From 7656765f307fbb7b572c2ff566b6641c945be560 Mon Sep 17 00:00:00 2001 From: Near <77224854+near-san@users.noreply.github.com> Date: Mon, 8 Feb 2021 09:11:00 +0000 Subject: [PATCH] Update to ares v117 release. [No official changelog available for this version. -Ed.] --- ares/Shaders/Curvature.shader/curvature.fs | 21 + ares/Shaders/Curvature.shader/manifest.bml | 4 + .../Edge Detection.shader/edge-detection.fs | 25 + .../Edge Detection.shader/manifest.bml | 4 + ares/Shaders/Scanline.shader/manifest.bml | 4 + ares/Shaders/Scanline.shader/scanline.fs | 20 + ares/ares/debug/debug.hpp | 4 +- ares/ares/information.hpp | 7 +- .../ares/node/debugger/tracer/instruction.hpp | 2 +- ares/ares/node/object.hpp | 8 +- ares/ares/scheduler/thread.hpp | 2 +- ares/ares/types.hpp | 152 +-- ares/component/audio/ay38910/ay38910.cpp | 12 +- ares/component/audio/ay38910/ay38910.hpp | 60 +- ares/component/audio/msm5205/msm5205.cpp | 42 +- ares/component/audio/msm5205/msm5205.hpp | 26 +- ares/component/audio/sn76489/sn76489.cpp | 8 +- ares/component/audio/sn76489/sn76489.hpp | 30 +- ares/component/audio/t6w28/t6w28.cpp | 10 +- ares/component/audio/t6w28/t6w28.hpp | 36 +- ares/component/audio/ym2149/ym2149.cpp | 18 +- ares/component/audio/ym2149/ym2149.hpp | 64 +- ares/component/audio/ym2413/constants.cpp | 16 +- ares/component/audio/ym2413/io.cpp | 14 +- ares/component/audio/ym2413/operator.cpp | 22 +- ares/component/audio/ym2413/voice.cpp | 2 +- ares/component/audio/ym2413/ym2413.cpp | 20 +- ares/component/audio/ym2413/ym2413.hpp | 122 +- ares/component/eeprom/m93lcx6/m93lcx6.cpp | 42 +- ares/component/eeprom/m93lcx6/m93lcx6.hpp | 40 +- .../component/eeprom/x24c01/serialization.cpp | 2 +- ares/component/eeprom/x24c01/x24c01.cpp | 8 +- ares/component/eeprom/x24c01/x24c01.hpp | 32 +- .../processor/arm7tdmi/algorithms.cpp | 26 +- .../component/processor/arm7tdmi/arm7tdmi.hpp | 262 ++-- .../processor/arm7tdmi/disassembler.cpp | 124 +- .../processor/arm7tdmi/instruction.cpp | 272 ++--- .../processor/arm7tdmi/instructions-arm.cpp | 122 +- .../processor/arm7tdmi/instructions-thumb.cpp | 62 +- ares/component/processor/arm7tdmi/memory.cpp | 12 +- .../processor/arm7tdmi/registers.cpp | 2 +- ares/component/processor/gsu/disassembler.cpp | 92 +- ares/component/processor/gsu/gsu.hpp | 54 +- ares/component/processor/gsu/instruction.cpp | 34 +- ares/component/processor/gsu/instructions.cpp | 62 +- ares/component/processor/gsu/registers.hpp | 116 +- .../component/processor/gsu/serialization.cpp | 4 +- .../processor/hg51b/disassembler.cpp | 100 +- ares/component/processor/hg51b/hg51b.cpp | 14 +- ares/component/processor/hg51b/hg51b.hpp | 324 ++--- .../component/processor/hg51b/instruction.cpp | 326 ++--- .../processor/hg51b/instructions.cpp | 142 +-- ares/component/processor/hg51b/registers.cpp | 4 +- .../processor/huc6280/algorithms.cpp | 72 +- .../processor/huc6280/disassembler.cpp | 48 +- ares/component/processor/huc6280/huc6280.hpp | 160 +-- .../processor/huc6280/instruction.cpp | 2 +- .../processor/huc6280/instructions.cpp | 106 +- ares/component/processor/huc6280/memory.cpp | 20 +- ares/component/processor/m68k/algorithms.cpp | 46 +- ares/component/processor/m68k/conditions.cpp | 2 +- .../component/processor/m68k/disassembler.cpp | 200 ++-- .../processor/m68k/effective-address.cpp | 36 +- ares/component/processor/m68k/instruction.cpp | 460 +++---- .../component/processor/m68k/instructions.cpp | 192 +-- ares/component/processor/m68k/m68k.cpp | 6 +- ares/component/processor/m68k/m68k.hpp | 644 +++++----- ares/component/processor/m68k/memory.cpp | 48 +- ares/component/processor/m68k/registers.cpp | 16 +- ares/component/processor/m68k/traits.cpp | 42 +- ares/component/processor/sm83/algorithms.cpp | 58 +- .../component/processor/sm83/disassembler.cpp | 20 +- ares/component/processor/sm83/instruction.cpp | 2 +- .../component/processor/sm83/instructions.cpp | 180 +-- ares/component/processor/sm83/memory.cpp | 18 +- ares/component/processor/sm83/sm83.hpp | 226 ++-- .../component/processor/spc700/algorithms.cpp | 50 +- .../processor/spc700/disassembler.cpp | 16 +- .../processor/spc700/instructions.cpp | 252 ++-- ares/component/processor/spc700/memory.cpp | 10 +- ares/component/processor/spc700/spc700.hpp | 122 +- .../processor/tlcs900h/algorithms.cpp | 10 +- .../processor/tlcs900h/conditions.cpp | 2 +- .../processor/tlcs900h/control-registers.cpp | 20 +- .../processor/tlcs900h/disassembler.cpp | 162 +-- ares/component/processor/tlcs900h/dma.cpp | 6 +- .../processor/tlcs900h/instruction.cpp | 384 +++--- .../processor/tlcs900h/instructions.cpp | 88 +- ares/component/processor/tlcs900h/memory.cpp | 56 +- .../processor/tlcs900h/registers.cpp | 38 +- .../processor/tlcs900h/serialization.cpp | 4 +- .../component/processor/tlcs900h/tlcs900h.cpp | 4 +- .../component/processor/tlcs900h/tlcs900h.hpp | 254 ++-- .../processor/upd96050/disassembler.cpp | 36 +- .../processor/upd96050/instructions.cpp | 50 +- ares/component/processor/upd96050/memory.cpp | 28 +- .../component/processor/upd96050/upd96050.cpp | 2 +- .../component/processor/upd96050/upd96050.hpp | 64 +- ares/component/processor/v30mz/algorithms.cpp | 110 +- .../processor/v30mz/disassembler.cpp | 56 +- .../component/processor/v30mz/instruction.cpp | 10 +- .../processor/v30mz/instructions-adjust.cpp | 2 +- .../processor/v30mz/instructions-alu.cpp | 10 +- .../processor/v30mz/instructions-exec.cpp | 20 +- .../processor/v30mz/instructions-flag.cpp | 4 +- .../processor/v30mz/instructions-group.cpp | 6 +- .../processor/v30mz/instructions-misc.cpp | 2 +- .../processor/v30mz/instructions-move.cpp | 10 +- ares/component/processor/v30mz/memory.cpp | 22 +- ares/component/processor/v30mz/modrm.cpp | 16 +- ares/component/processor/v30mz/registers.cpp | 8 +- .../processor/v30mz/serialization.cpp | 12 +- ares/component/processor/v30mz/v30mz.hpp | 186 +-- .../processor/wdc65816/algorithms.cpp | 120 +- .../processor/wdc65816/disassembler.cpp | 50 +- .../processor/wdc65816/instructions-other.cpp | 6 +- .../processor/wdc65816/instructions-pc.cpp | 22 +- ares/component/processor/wdc65816/memory.cpp | 42 +- .../component/processor/wdc65816/wdc65816.hpp | 148 +-- ares/component/processor/z80/algorithms.cpp | 78 +- ares/component/processor/z80/disassembler.cpp | 36 +- ares/component/processor/z80/instruction.cpp | 14 +- ares/component/processor/z80/instructions.cpp | 206 ++-- ares/component/processor/z80/memory.cpp | 28 +- .../component/processor/z80/serialization.cpp | 4 +- ares/component/processor/z80/z80.cpp | 8 +- ares/component/processor/z80/z80.hpp | 280 ++--- ares/component/video/tms9918/background.cpp | 36 +- ares/component/video/tms9918/io.cpp | 18 +- ares/component/video/tms9918/sprites.cpp | 36 +- ares/component/video/tms9918/tms9918.cpp | 4 +- ares/component/video/tms9918/tms9918.hpp | 90 +- ares/component/video/v9938/commands.cpp | 98 +- ares/component/video/v9938/graphic1.cpp | 12 +- ares/component/video/v9938/graphic2.cpp | 14 +- ares/component/video/v9938/graphic3.cpp | 2 +- ares/component/video/v9938/graphic4.cpp | 6 +- ares/component/video/v9938/io.cpp | 22 +- ares/component/video/v9938/sprite1.cpp | 36 +- ares/component/video/v9938/sprite2.cpp | 44 +- ares/component/video/v9938/v9938.cpp | 10 +- ares/component/video/v9938/v9938.hpp | 216 ++-- ares/cv/cartridge/cartridge.hpp | 2 +- ares/cv/controller/controller.hpp | 4 +- ares/cv/controller/gamepad/gamepad.cpp | 6 +- ares/cv/controller/gamepad/gamepad.hpp | 18 +- ares/cv/controller/port.hpp | 4 +- ares/cv/cpu/cpu.hpp | 16 +- ares/cv/cpu/memory.cpp | 12 +- ares/cv/cv.hpp | 1 + ares/cv/psg/psg.cpp | 4 +- ares/cv/psg/psg.hpp | 4 +- ares/cv/system/serialization.cpp | 4 +- ares/cv/system/system.cpp | 54 +- ares/cv/system/system.hpp | 14 +- ares/cv/vdp/color.cpp | 2 +- ares/cv/vdp/vdp.cpp | 2 +- ares/cv/vdp/vdp.hpp | 4 +- ares/fc/apu/apu.hpp | 76 +- ares/fc/cartridge/board/bandai-fcg.cpp | 12 +- ares/fc/cartridge/board/hvc-axrom.cpp | 4 +- ares/fc/cartridge/board/hvc-bnrom.cpp | 4 +- ares/fc/cartridge/board/hvc-cnrom.cpp | 4 +- ares/fc/cartridge/board/hvc-exrom.cpp | 70 +- ares/fc/cartridge/board/hvc-fmr.cpp | 4 +- ares/fc/cartridge/board/hvc-fxrom.cpp | 4 +- ares/fc/cartridge/board/hvc-gxrom.cpp | 4 +- ares/fc/cartridge/board/hvc-hkrom.cpp | 34 +- ares/fc/cartridge/board/hvc-nrom.cpp | 4 +- ares/fc/cartridge/board/hvc-pxrom.cpp | 4 +- ares/fc/cartridge/board/hvc-sxrom.cpp | 6 +- ares/fc/cartridge/board/hvc-txrom.cpp | 30 +- ares/fc/cartridge/board/hvc-uxrom.cpp | 4 +- ares/fc/cartridge/board/jaleco-jf.cpp | 17 +- ares/fc/cartridge/board/konami-vrc1.cpp | 4 +- ares/fc/cartridge/board/konami-vrc2.cpp | 4 +- ares/fc/cartridge/board/konami-vrc3.cpp | 18 +- ares/fc/cartridge/board/konami-vrc4.cpp | 28 +- ares/fc/cartridge/board/konami-vrc5.cpp | 52 +- ares/fc/cartridge/board/konami-vrc6.cpp | 56 +- ares/fc/cartridge/board/konami-vrc7.cpp | 30 +- ares/fc/cartridge/board/sunsoft-3.cpp | 12 +- ares/fc/cartridge/board/sunsoft-4.cpp | 14 +- ares/fc/cartridge/board/sunsoft-5b.cpp | 20 +- ares/fc/cpu/cpu.hpp | 18 +- ares/fc/fc.hpp | 1 + ares/fc/fds/audio.hpp | 28 +- ares/fc/fds/drive.hpp | 32 +- ares/fc/fds/timer.hpp | 8 +- ares/fc/ppu/ppu.hpp | 36 +- ares/fc/system/system.cpp | 57 +- ares/fc/system/system.hpp | 4 +- ares/gb/apu/apu.hpp | 114 +- ares/gb/apu/io.cpp | 4 +- ares/gb/apu/noise.cpp | 10 +- ares/gb/apu/sequencer.cpp | 2 +- ares/gb/apu/square1.cpp | 14 +- ares/gb/apu/square2.cpp | 6 +- ares/gb/apu/wave.cpp | 10 +- ares/gb/bus/bus.cpp | 8 +- ares/gb/bus/bus.hpp | 8 +- ares/gb/cartridge/board/board.cpp | 8 +- ares/gb/cartridge/board/board.hpp | 12 +- ares/gb/cartridge/board/huc1.cpp | 24 +- ares/gb/cartridge/board/huc3.cpp | 22 +- ares/gb/cartridge/board/linear.cpp | 12 +- ares/gb/cartridge/board/mbc1.cpp | 30 +- ares/gb/cartridge/board/mbc1m.cpp | 22 +- ares/gb/cartridge/board/mbc2.cpp | 16 +- ares/gb/cartridge/board/mbc3.cpp | 62 +- ares/gb/cartridge/board/mbc5.cpp | 22 +- ares/gb/cartridge/board/mbc6.cpp | 40 +- ares/gb/cartridge/board/mbc7.cpp | 30 +- ares/gb/cartridge/board/mmm01.cpp | 28 +- ares/gb/cartridge/board/tama.cpp | 80 +- ares/gb/cartridge/cartridge.cpp | 2 +- ares/gb/cartridge/cartridge.hpp | 6 +- ares/gb/cartridge/memory.cpp | 4 +- ares/gb/cpu/cpu.cpp | 10 +- ares/gb/cpu/cpu.hpp | 92 +- ares/gb/cpu/io.cpp | 20 +- ares/gb/cpu/memory.cpp | 12 +- ares/gb/cpu/timing.cpp | 16 +- ares/gb/gb.hpp | 5 +- ares/gb/ppu/cgb.cpp | 52 +- ares/gb/ppu/color.cpp | 40 +- ares/gb/ppu/dmg.cpp | 54 +- ares/gb/ppu/io.cpp | 10 +- ares/gb/ppu/ppu.cpp | 16 +- ares/gb/ppu/ppu.hpp | 124 +- ares/gb/system/serialization.cpp | 4 +- ares/gb/system/system.cpp | 35 +- ares/gb/system/system.hpp | 13 +- ares/gba/apu/apu.cpp | 12 +- ares/gba/apu/apu.hpp | 186 +-- ares/gba/apu/fifo.cpp | 2 +- ares/gba/apu/io.cpp | 4 +- ares/gba/apu/noise.cpp | 6 +- ares/gba/apu/sequencer.cpp | 4 +- ares/gba/apu/square.cpp | 2 +- ares/gba/apu/square1.cpp | 8 +- ares/gba/apu/square2.cpp | 4 +- ares/gba/apu/wave.cpp | 14 +- ares/gba/cartridge/cartridge.cpp | 20 +- ares/gba/cartridge/cartridge.hpp | 10 +- ares/gba/cartridge/eeprom.cpp | 4 +- ares/gba/cartridge/flash.cpp | 10 +- ares/gba/cartridge/memory.hpp | 52 +- ares/gba/cartridge/mrom.cpp | 8 +- ares/gba/cartridge/serialization.cpp | 8 +- ares/gba/cartridge/sram.cpp | 6 +- ares/gba/cpu/bus.cpp | 20 +- ares/gba/cpu/cpu.cpp | 26 +- ares/gba/cpu/cpu.hpp | 198 +-- ares/gba/cpu/dma.cpp | 8 +- ares/gba/cpu/io.cpp | 8 +- ares/gba/cpu/keypad.cpp | 2 +- ares/gba/cpu/memory.cpp | 8 +- ares/gba/cpu/prefetch.cpp | 8 +- ares/gba/cpu/timer.cpp | 4 +- ares/gba/gba.hpp | 3 +- ares/gba/memory/memory.cpp | 18 +- ares/gba/memory/memory.hpp | 10 +- ares/gba/player/player.cpp | 12 +- ares/gba/player/player.hpp | 24 +- ares/gba/ppu/background.cpp | 78 +- ares/gba/ppu/color.cpp | 22 +- ares/gba/ppu/dac.cpp | 30 +- ares/gba/ppu/io.cpp | 4 +- ares/gba/ppu/memory.cpp | 26 +- ares/gba/ppu/object.cpp | 44 +- ares/gba/ppu/ppu.cpp | 16 +- ares/gba/ppu/ppu.hpp | 240 ++-- ares/gba/ppu/window.cpp | 4 +- ares/gba/system/bios.cpp | 6 +- ares/gba/system/bios.hpp | 10 +- ares/gba/system/serialization.cpp | 4 +- ares/gba/system/system.cpp | 20 +- ares/gba/system/system.hpp | 7 +- ares/md/apu/apu.cpp | 2 +- ares/md/apu/apu.hpp | 22 +- ares/md/apu/bus.cpp | 12 +- ares/md/cartridge/board/banked.cpp | 16 +- ares/md/cartridge/board/board.cpp | 20 +- ares/md/cartridge/board/board.hpp | 18 +- ares/md/cartridge/board/game-genie.cpp | 20 +- ares/md/cartridge/board/linear.cpp | 18 +- ares/md/cartridge/board/lock-on.cpp | 14 +- ares/md/cartridge/cartridge.cpp | 8 +- ares/md/cartridge/cartridge.hpp | 8 +- .../md/controller/control-pad/control-pad.cpp | 6 +- .../md/controller/control-pad/control-pad.hpp | 20 +- ares/md/controller/controller.hpp | 4 +- .../controller/fighting-pad/fighting-pad.cpp | 6 +- .../controller/fighting-pad/fighting-pad.hpp | 24 +- ares/md/controller/port.hpp | 10 +- ares/md/cpu/bus.cpp | 4 +- ares/md/cpu/cpu.cpp | 32 +- ares/md/cpu/cpu.hpp | 36 +- ares/md/cpu/debugger.cpp | 4 +- ares/md/cpu/io.cpp | 4 +- ares/md/expansion/expansion.cpp | 8 +- ares/md/expansion/expansion.hpp | 8 +- ares/md/mcd/bus-external.cpp | 16 +- ares/md/mcd/bus.cpp | 12 +- ares/md/mcd/cdc-transfer.cpp | 14 +- ares/md/mcd/cdc.cpp | 16 +- ares/md/mcd/cdd-dac.cpp | 8 +- ares/md/mcd/cdd.cpp | 46 +- ares/md/mcd/gpu.cpp | 48 +- ares/md/mcd/io-external.cpp | 10 +- ares/md/mcd/io.cpp | 22 +- ares/md/mcd/mcd.cpp | 10 +- ares/md/mcd/mcd.hpp | 318 ++--- ares/md/mcd/pcm.cpp | 20 +- ares/md/md.hpp | 4 +- ares/md/psg/psg.cpp | 4 +- ares/md/psg/psg.hpp | 2 +- ares/md/system/serialization.cpp | 4 +- ares/md/system/system.cpp | 62 +- ares/md/system/system.hpp | 6 +- ares/md/vdp-performance/background.cpp | 74 +- ares/md/vdp-performance/color.cpp | 18 +- ares/md/vdp-performance/debugger.cpp | 8 +- ares/md/vdp-performance/io.cpp | 14 +- ares/md/vdp-performance/memory.cpp | 30 +- ares/md/vdp-performance/object.cpp | 4 +- ares/md/vdp-performance/sprite.cpp | 36 +- ares/md/vdp-performance/vdp.cpp | 42 +- ares/md/vdp-performance/vdp.hpp | 202 ++-- ares/md/vdp/background.cpp | 36 +- ares/md/vdp/color.cpp | 18 +- ares/md/vdp/debugger.cpp | 8 +- ares/md/vdp/io.cpp | 14 +- ares/md/vdp/memory.cpp | 26 +- ares/md/vdp/render.cpp | 6 +- ares/md/vdp/serialization.cpp | 4 +- ares/md/vdp/sprite.cpp | 36 +- ares/md/vdp/vdp.cpp | 2 +- ares/md/vdp/vdp.hpp | 218 ++-- ares/md/ym2612/channel.cpp | 32 +- ares/md/ym2612/constants.cpp | 8 +- ares/md/ym2612/io.cpp | 16 +- ares/md/ym2612/serialization.cpp | 4 +- ares/md/ym2612/ym2612.cpp | 44 +- ares/md/ym2612/ym2612.hpp | 148 +-- ares/ms/cpu/cpu.hpp | 2 +- ares/ms/ms.hpp | 1 + ares/ms/system/system.cpp | 85 +- ares/ms/system/system.hpp | 6 +- ares/msx/cartridge/board/asc16.cpp | 16 +- ares/msx/cartridge/board/asc8.cpp | 24 +- ares/msx/cartridge/board/board.cpp | 6 +- ares/msx/cartridge/board/board.hpp | 10 +- ares/msx/cartridge/board/cross-blaim.cpp | 24 +- ares/msx/cartridge/board/konami-scc.cpp | 46 +- ares/msx/cartridge/board/konami.cpp | 16 +- ares/msx/cartridge/board/linear.cpp | 6 +- .../msx/cartridge/board/super-lode-runner.cpp | 10 +- ares/msx/cartridge/board/super-pierrot.cpp | 12 +- ares/msx/cartridge/cartridge.cpp | 6 +- ares/msx/cartridge/cartridge.hpp | 10 +- ares/msx/controller/controller.hpp | 4 +- ares/msx/controller/gamepad/gamepad.cpp | 4 +- ares/msx/controller/gamepad/gamepad.hpp | 14 +- ares/msx/controller/port.hpp | 4 +- ares/msx/cpu/cpu.cpp | 2 +- ares/msx/cpu/cpu.hpp | 30 +- ares/msx/cpu/memory.cpp | 44 +- ares/msx/keyboard/keyboard.cpp | 18 +- ares/msx/keyboard/keyboard.hpp | 6 +- ares/msx/msx.hpp | 1 + ares/msx/psg/psg.cpp | 8 +- ares/msx/psg/psg.hpp | 8 +- ares/msx/system/serialization.cpp | 4 +- ares/msx/system/system.cpp | 54 +- ares/msx/system/system.hpp | 16 +- ares/msx/vdp/color.cpp | 16 +- ares/msx/vdp/vdp.cpp | 6 +- ares/msx/vdp/vdp.hpp | 10 +- ares/n64/ai/ai.cpp | 2 +- ares/n64/ai/ai.hpp | 16 +- ares/n64/ai/io.cpp | 6 +- ares/n64/controller/controller.hpp | 2 +- ares/n64/controller/gamepad/gamepad.cpp | 4 +- ares/n64/controller/gamepad/gamepad.hpp | 2 +- ares/n64/cpu/cpu.cpp | 4 +- ares/n64/cpu/cpu.hpp | 236 ++-- ares/n64/cpu/disassembler.cpp | 20 +- ares/n64/cpu/exceptions.cpp | 2 +- ares/n64/cpu/fpu.cpp | 24 +- ares/n64/cpu/ipu.cpp | 20 +- ares/n64/cpu/memory.cpp | 8 +- ares/n64/cpu/scc.cpp | 8 +- ares/n64/dd/io.cpp | 2 +- ares/n64/memory/bus.hpp | 8 +- ares/n64/memory/io.hpp | 4 +- ares/n64/memory/lsb-readable.hpp | 104 ++ ares/n64/memory/lsb-writable.hpp | 122 ++ ares/n64/memory/memory.hpp | 10 +- .../memory/{readable.hpp => msb-readable.hpp} | 46 +- ares/n64/memory/msb-writable.hpp | 80 ++ ares/n64/memory/writable.hpp | 80 -- ares/n64/mi/io.cpp | 4 +- ares/n64/mi/mi.hpp | 2 +- ares/n64/n64.hpp | 1 + ares/n64/pi/io.cpp | 12 +- ares/n64/pi/pi.hpp | 24 +- ares/n64/rdp/io.cpp | 8 +- ares/n64/rdp/rdp.cpp | 2 +- ares/n64/rdp/rdp.hpp | 266 ++--- ares/n64/rdp/render.cpp | 474 ++++---- ares/n64/ri/io.cpp | 4 +- ares/n64/rsp/decoder.hpp | 4 +- ares/n64/rsp/disassembler.cpp | 32 +- ares/n64/rsp/io.cpp | 8 +- ares/n64/rsp/recompiler.cpp | 2 +- ares/n64/rsp/rsp.cpp | 4 +- ares/n64/rsp/rsp.hpp | 86 +- ares/n64/rsp/vpu.cpp | 136 +-- ares/n64/si/io.cpp | 4 +- ares/n64/si/si.cpp | 22 +- ares/n64/si/si.hpp | 20 +- ares/n64/system/serialization.cpp | 4 +- ares/n64/system/system.cpp | 41 +- ares/n64/system/system.hpp | 10 +- ares/n64/vi/io.cpp | 4 +- ares/n64/vi/vi.cpp | 18 +- ares/n64/vi/vi.hpp | 62 +- ares/ngp/apu/apu.cpp | 2 +- ares/ngp/apu/apu.hpp | 22 +- ares/ngp/apu/memory.cpp | 14 +- ares/ngp/cartridge/cartridge.cpp | 4 +- ares/ngp/cartridge/cartridge.hpp | 4 +- ares/ngp/cartridge/flash.cpp | 24 +- ares/ngp/cartridge/flash.hpp | 24 +- ares/ngp/cpu/adc.cpp | 2 +- ares/ngp/cpu/cpu.cpp | 56 +- ares/ngp/cpu/cpu.hpp | 390 +++--- ares/ngp/cpu/interrupts.cpp | 10 +- ares/ngp/cpu/io.cpp | 10 +- ares/ngp/cpu/memory.cpp | 38 +- ares/ngp/cpu/rtc.cpp | 30 +- ares/ngp/cpu/timers.cpp | 14 +- ares/ngp/cpu/watchdog.cpp | 2 +- ares/ngp/ngp.hpp | 1 + ares/ngp/psg/psg.cpp | 12 +- ares/ngp/psg/psg.hpp | 14 +- ares/ngp/system/serialization.cpp | 4 +- ares/ngp/system/system.cpp | 20 +- ares/ngp/system/system.hpp | 9 +- ares/ngp/vpu/color.cpp | 20 +- ares/ngp/vpu/memory.cpp | 40 +- ares/ngp/vpu/plane.cpp | 10 +- ares/ngp/vpu/sprite.cpp | 24 +- ares/ngp/vpu/vpu.cpp | 8 +- ares/ngp/vpu/vpu.hpp | 166 +-- ares/ngp/vpu/window.cpp | 2 +- ares/pce/cartridge/board/arcade-card-duo.cpp | 28 +- ares/pce/cartridge/board/arcade-card-pro.cpp | 30 +- ares/pce/cartridge/board/banked.cpp | 10 +- ares/pce/cartridge/board/board.cpp | 6 +- ares/pce/cartridge/board/board.hpp | 10 +- ares/pce/cartridge/board/linear.cpp | 6 +- ares/pce/cartridge/board/ram.cpp | 8 +- ares/pce/cartridge/board/split.cpp | 10 +- .../pce/cartridge/board/super-system-card.cpp | 10 +- ares/pce/cartridge/board/system-card.cpp | 6 +- ares/pce/cartridge/cartridge.cpp | 4 +- ares/pce/cartridge/cartridge.hpp | 4 +- ares/pce/controller/avenuepad/avenuepad.cpp | 6 +- ares/pce/controller/avenuepad/avenuepad.hpp | 4 +- ares/pce/controller/controller.hpp | 4 +- ares/pce/controller/gamepad/gamepad.cpp | 6 +- ares/pce/controller/gamepad/gamepad.hpp | 20 +- ares/pce/controller/port.hpp | 4 +- ares/pce/cpu/cpu.cpp | 6 +- ares/pce/cpu/cpu.hpp | 44 +- ares/pce/cpu/debugger.cpp | 2 +- ares/pce/cpu/io.cpp | 8 +- ares/pce/pcd/adpcm.cpp | 4 +- ares/pce/pcd/drive.cpp | 2 +- ares/pce/pcd/io.cpp | 12 +- ares/pce/pcd/pcd.cpp | 8 +- ares/pce/pcd/pcd.hpp | 164 +-- ares/pce/pcd/scsi.cpp | 16 +- ares/pce/pcd/serialization.cpp | 8 +- ares/pce/pce.hpp | 1 + ares/pce/psg/channel.cpp | 4 +- ares/pce/psg/io.cpp | 4 +- ares/pce/psg/psg.cpp | 34 +- ares/pce/psg/psg.hpp | 58 +- ares/pce/system/serialization.cpp | 4 +- ares/pce/system/system.cpp | 64 +- ares/pce/system/system.hpp | 12 +- ares/pce/vdp-performance/background.cpp | 22 +- ares/pce/vdp-performance/color.cpp | 18 +- ares/pce/vdp-performance/debugger.cpp | 12 +- ares/pce/vdp-performance/dma.cpp | 6 +- ares/pce/vdp-performance/irq.cpp | 2 +- ares/pce/vdp-performance/sprite.cpp | 34 +- ares/pce/vdp-performance/vce.cpp | 10 +- ares/pce/vdp-performance/vce.hpp | 22 +- ares/pce/vdp-performance/vdc.cpp | 20 +- ares/pce/vdp-performance/vdc.hpp | 190 +-- ares/pce/vdp-performance/vdp.cpp | 14 +- ares/pce/vdp-performance/vdp.hpp | 16 +- ares/pce/vdp-performance/vpc.cpp | 12 +- ares/pce/vdp-performance/vpc.hpp | 18 +- ares/pce/vdp/background.cpp | 20 +- ares/pce/vdp/color.cpp | 18 +- ares/pce/vdp/debugger.cpp | 12 +- ares/pce/vdp/dma.cpp | 6 +- ares/pce/vdp/irq.cpp | 2 +- ares/pce/vdp/sprite.cpp | 32 +- ares/pce/vdp/vce.cpp | 10 +- ares/pce/vdp/vce.hpp | 20 +- ares/pce/vdp/vdc.cpp | 18 +- ares/pce/vdp/vdc.hpp | 192 +-- ares/pce/vdp/vdp.cpp | 4 +- ares/pce/vdp/vdp.hpp | 8 +- ares/pce/vdp/vpc.cpp | 12 +- ares/pce/vdp/vpc.hpp | 18 +- ares/ps1/cpu/breakpoints.cpp | 2 +- ares/ps1/cpu/cpu.cpp | 6 +- ares/ps1/cpu/cpu.hpp | 122 +- ares/ps1/cpu/debugger.cpp | 4 +- ares/ps1/cpu/delay-slots.cpp | 2 +- ares/ps1/cpu/disassembler.cpp | 10 +- ares/ps1/cpu/exceptions.cpp | 4 +- ares/ps1/cpu/gte.cpp | 34 +- ares/ps1/cpu/memory.cpp | 4 +- ares/ps1/cpu/scc.cpp | 4 +- ares/ps1/disc/cdxa.cpp | 42 +- ares/ps1/disc/command.cpp | 14 +- ares/ps1/disc/debugger.cpp | 6 +- ares/ps1/disc/disc.cpp | 16 +- ares/ps1/disc/disc.hpp | 72 +- ares/ps1/disc/drive.cpp | 10 +- ares/ps1/disc/io.cpp | 10 +- ares/ps1/disc/serialization.cpp | 2 +- ares/ps1/dma/channel.cpp | 12 +- ares/ps1/dma/debugger.cpp | 2 +- ares/ps1/dma/dma.cpp | 6 +- ares/ps1/dma/dma.hpp | 62 +- ares/ps1/dma/io.cpp | 12 +- ares/ps1/gpu/blitter.cpp | 20 +- ares/ps1/gpu/debugger.cpp | 8 +- ares/ps1/gpu/gp0.cpp | 26 +- ares/ps1/gpu/gp1.cpp | 6 +- ares/ps1/gpu/gpu.cpp | 6 +- ares/ps1/gpu/gpu.hpp | 200 ++-- ares/ps1/gpu/io.cpp | 2 +- ares/ps1/gpu/renderer.cpp | 38 +- ares/ps1/gpu/serialization.cpp | 2 +- ares/ps1/interrupt/interrupt.cpp | 10 +- ares/ps1/interrupt/interrupt.hpp | 20 +- ares/ps1/interrupt/io.cpp | 4 +- ares/ps1/mdec/decoder.cpp | 40 +- ares/ps1/mdec/io.cpp | 4 +- ares/ps1/mdec/mdec.hpp | 34 +- ares/ps1/mdec/serialization.cpp | 2 +- ares/ps1/memory/bus.hpp | 4 +- ares/ps1/memory/interface.hpp | 14 +- ares/ps1/memory/io.cpp | 8 +- ares/ps1/memory/memory.hpp | 42 +- .../digital-gamepad/digital-gamepad.cpp | 4 +- .../digital-gamepad/digital-gamepad.hpp | 2 +- ares/ps1/peripheral/io.cpp | 10 +- .../peripheral/memory-card/memory-card.cpp | 16 +- .../peripheral/memory-card/memory-card.hpp | 10 +- ares/ps1/peripheral/peripheral.cpp | 2 +- ares/ps1/peripheral/peripheral.hpp | 62 +- ares/ps1/ps1.hpp | 3 +- ares/ps1/spu/adpcm.cpp | 10 +- ares/ps1/spu/capture.cpp | 2 +- ares/ps1/spu/fifo.cpp | 28 +- ares/ps1/spu/gaussian.cpp | 28 +- ares/ps1/spu/io.cpp | 34 +- ares/ps1/spu/reverb.cpp | 4 +- ares/ps1/spu/serialization.cpp | 2 +- ares/ps1/spu/spu.cpp | 2 +- ares/ps1/spu/spu.hpp | 240 ++-- ares/ps1/system/serialization.cpp | 4 +- ares/ps1/system/system.cpp | 52 +- ares/ps1/system/system.hpp | 6 +- ares/ps1/timer/io.cpp | 8 +- ares/ps1/timer/timer.cpp | 4 +- ares/ps1/timer/timer.hpp | 42 +- ares/sfc/cartridge/slot.cpp | 2 +- ares/sfc/controller/controller.cpp | 2 +- ares/sfc/controller/controller.hpp | 6 +- ares/sfc/controller/gamepad/gamepad.cpp | 4 +- ares/sfc/controller/gamepad/gamepad.hpp | 20 +- ares/sfc/controller/justifier/justifier.cpp | 16 +- ares/sfc/controller/justifier/justifier.hpp | 16 +- ares/sfc/controller/justifiers/justifiers.cpp | 20 +- ares/sfc/controller/justifiers/justifiers.hpp | 20 +- ares/sfc/controller/mouse/mouse.cpp | 10 +- ares/sfc/controller/mouse/mouse.hpp | 18 +- .../ntt-data-keypad/ntt-data-keypad.cpp | 4 +- .../ntt-data-keypad/ntt-data-keypad.hpp | 20 +- ares/sfc/controller/port.hpp | 6 +- .../super-multitap/super-multitap.cpp | 4 +- .../super-multitap/super-multitap.hpp | 6 +- .../controller/super-scope/super-scope.cpp | 12 +- .../controller/super-scope/super-scope.hpp | 28 +- ares/sfc/controller/twin-tap/twin-tap.cpp | 4 +- ares/sfc/controller/twin-tap/twin-tap.hpp | 8 +- ares/sfc/coprocessor/armdsp/armdsp.cpp | 2 +- ares/sfc/coprocessor/armdsp/armdsp.hpp | 38 +- ares/sfc/coprocessor/armdsp/io.cpp | 6 +- ares/sfc/coprocessor/armdsp/memory.cpp | 8 +- ares/sfc/coprocessor/armdsp/serialization.cpp | 12 +- .../coprocessor/competition/competition.cpp | 12 +- .../coprocessor/competition/competition.hpp | 24 +- ares/sfc/coprocessor/dip/dip.cpp | 4 +- ares/sfc/coprocessor/dip/dip.hpp | 6 +- ares/sfc/coprocessor/epsonrtc/epsonrtc.cpp | 18 +- ares/sfc/coprocessor/epsonrtc/epsonrtc.hpp | 92 +- ares/sfc/coprocessor/epsonrtc/memory.cpp | 16 +- .../coprocessor/epsonrtc/serialization.cpp | 2 +- ares/sfc/coprocessor/epsonrtc/time.cpp | 6 +- .../sfc/coprocessor/hitachidsp/hitachidsp.cpp | 2 +- .../sfc/coprocessor/hitachidsp/hitachidsp.hpp | 42 +- ares/sfc/coprocessor/hitachidsp/memory.cpp | 32 +- .../coprocessor/hitachidsp/serialization.cpp | 8 +- ares/sfc/coprocessor/icd/icd.cpp | 6 +- ares/sfc/coprocessor/icd/icd.hpp | 76 +- ares/sfc/coprocessor/icd/interface.cpp | 16 +- ares/sfc/coprocessor/icd/io.cpp | 4 +- ares/sfc/coprocessor/icd/serialization.cpp | 2 +- ares/sfc/coprocessor/mcc/mcc.cpp | 18 +- ares/sfc/coprocessor/mcc/mcc.hpp | 44 +- ares/sfc/coprocessor/msu1/msu1.cpp | 14 +- ares/sfc/coprocessor/msu1/msu1.hpp | 32 +- ares/sfc/coprocessor/necdsp/memory.cpp | 8 +- ares/sfc/coprocessor/necdsp/necdsp.hpp | 12 +- ares/sfc/coprocessor/necdsp/serialization.cpp | 10 +- ares/sfc/coprocessor/obc1/obc1.cpp | 14 +- ares/sfc/coprocessor/obc1/obc1.hpp | 14 +- ares/sfc/coprocessor/sa1/bwram.cpp | 30 +- ares/sfc/coprocessor/sa1/dma.cpp | 54 +- ares/sfc/coprocessor/sa1/io.cpp | 28 +- ares/sfc/coprocessor/sa1/iram.cpp | 12 +- ares/sfc/coprocessor/sa1/memory.cpp | 12 +- ares/sfc/coprocessor/sa1/rom.cpp | 14 +- ares/sfc/coprocessor/sa1/sa1.cpp | 2 +- ares/sfc/coprocessor/sa1/sa1.hpp | 146 +-- ares/sfc/coprocessor/sdd1/decompressor.cpp | 44 +- ares/sfc/coprocessor/sdd1/decompressor.hpp | 58 +- ares/sfc/coprocessor/sdd1/sdd1.cpp | 28 +- ares/sfc/coprocessor/sdd1/sdd1.hpp | 33 +- ares/sfc/coprocessor/sharprtc/memory.cpp | 14 +- .../coprocessor/sharprtc/serialization.cpp | 2 +- ares/sfc/coprocessor/sharprtc/sharprtc.cpp | 6 +- ares/sfc/coprocessor/sharprtc/sharprtc.hpp | 36 +- ares/sfc/coprocessor/sharprtc/time.cpp | 14 +- ares/sfc/coprocessor/spc7110/alu.cpp | 36 +- ares/sfc/coprocessor/spc7110/data.cpp | 54 +- ares/sfc/coprocessor/spc7110/dcu.cpp | 14 +- ares/sfc/coprocessor/spc7110/decompressor.cpp | 66 +- ares/sfc/coprocessor/spc7110/spc7110.cpp | 18 +- ares/sfc/coprocessor/spc7110/spc7110.hpp | 136 +-- ares/sfc/coprocessor/superfx/bus.cpp | 26 +- ares/sfc/coprocessor/superfx/core.cpp | 40 +- ares/sfc/coprocessor/superfx/io.cpp | 8 +- ares/sfc/coprocessor/superfx/memory.cpp | 28 +- ares/sfc/coprocessor/superfx/superfx.cpp | 6 +- ares/sfc/coprocessor/superfx/superfx.hpp | 64 +- ares/sfc/coprocessor/superfx/timing.cpp | 8 +- ares/sfc/cpu/cpu.cpp | 6 +- ares/sfc/cpu/cpu.hpp | 146 +-- ares/sfc/cpu/debugger.cpp | 8 +- ares/sfc/cpu/dma.cpp | 30 +- ares/sfc/cpu/io.cpp | 24 +- ares/sfc/cpu/irq.cpp | 2 +- ares/sfc/cpu/memory.cpp | 8 +- ares/sfc/cpu/timing.cpp | 12 +- ares/sfc/dsp/brr.cpp | 18 +- ares/sfc/dsp/counter.cpp | 6 +- ares/sfc/dsp/debugger.cpp | 4 +- ares/sfc/dsp/dsp.cpp | 4 +- ares/sfc/dsp/dsp.hpp | 172 +-- ares/sfc/dsp/echo.cpp | 56 +- ares/sfc/dsp/envelope.cpp | 14 +- ares/sfc/dsp/gaussian.cpp | 40 +- ares/sfc/dsp/memory.cpp | 22 +- ares/sfc/dsp/misc.cpp | 2 +- ares/sfc/dsp/voice.cpp | 18 +- ares/sfc/expansion/21fx/21fx.cpp | 20 +- ares/sfc/expansion/21fx/21fx.hpp | 34 +- .../sfc/expansion/satellaview/satellaview.cpp | 6 +- .../sfc/expansion/satellaview/satellaview.hpp | 24 +- ares/sfc/memory/memory-inline.hpp | 14 +- ares/sfc/memory/memory.cpp | 52 +- ares/sfc/memory/memory.hpp | 38 +- ares/sfc/memory/protectable.hpp | 24 +- ares/sfc/memory/readable.hpp | 28 +- ares/sfc/memory/writable.hpp | 26 +- ares/sfc/ppu-performance/background.cpp | 94 +- ares/sfc/ppu-performance/background.hpp | 32 +- ares/sfc/ppu-performance/color.cpp | 20 +- ares/sfc/ppu-performance/dac.cpp | 34 +- ares/sfc/ppu-performance/dac.hpp | 36 +- ares/sfc/ppu-performance/debugger.cpp | 70 +- ares/sfc/ppu-performance/io.cpp | 36 +- ares/sfc/ppu-performance/mode7.cpp | 58 +- ares/sfc/ppu-performance/mosaic.cpp | 2 +- ares/sfc/ppu-performance/mosaic.hpp | 6 +- ares/sfc/ppu-performance/oam.cpp | 26 +- ares/sfc/ppu-performance/oam.hpp | 26 +- ares/sfc/ppu-performance/object.cpp | 50 +- ares/sfc/ppu-performance/object.hpp | 40 +- ares/sfc/ppu-performance/ppu.cpp | 14 +- ares/sfc/ppu-performance/ppu.hpp | 136 +-- ares/sfc/ppu-performance/serialization.cpp | 2 +- ares/sfc/ppu-performance/window.cpp | 14 +- ares/sfc/ppu-performance/window.hpp | 38 +- ares/sfc/ppu/background.cpp | 94 +- ares/sfc/ppu/background.hpp | 76 +- ares/sfc/ppu/color.cpp | 20 +- ares/sfc/ppu/counter/counter-inline.hpp | 16 +- ares/sfc/ppu/counter/counter.hpp | 28 +- ares/sfc/ppu/dac.cpp | 34 +- ares/sfc/ppu/dac.hpp | 40 +- ares/sfc/ppu/debugger.cpp | 70 +- ares/sfc/ppu/io.cpp | 36 +- ares/sfc/ppu/main.cpp | 4 +- ares/sfc/ppu/mode7.cpp | 44 +- ares/sfc/ppu/mosaic.cpp | 4 +- ares/sfc/ppu/mosaic.hpp | 6 +- ares/sfc/ppu/oam.cpp | 26 +- ares/sfc/ppu/oam.hpp | 22 +- ares/sfc/ppu/object.cpp | 50 +- ares/sfc/ppu/object.hpp | 52 +- ares/sfc/ppu/ppu.cpp | 10 +- ares/sfc/ppu/ppu.hpp | 128 +- ares/sfc/ppu/serialization.cpp | 8 +- ares/sfc/ppu/window.cpp | 2 +- ares/sfc/ppu/window.hpp | 42 +- ares/sfc/sfc.hpp | 1 + ares/sfc/slot/bsmemory/bsmemory.cpp | 78 +- ares/sfc/slot/bsmemory/bsmemory.hpp | 114 +- ares/sfc/slot/sufamiturbo/memory.cpp | 8 +- ares/sfc/slot/sufamiturbo/sufamiturbo.hpp | 8 +- ares/sfc/smp/io.cpp | 10 +- ares/sfc/smp/memory.cpp | 14 +- ares/sfc/smp/serialization.cpp | 2 +- ares/sfc/smp/smp.hpp | 84 +- ares/sfc/smp/timing.cpp | 16 +- ares/sfc/system/serialization.cpp | 4 +- ares/sfc/system/system.cpp | 49 +- ares/sfc/system/system.hpp | 10 +- ares/sg/cartridge/cartridge.cpp | 4 +- ares/sg/cartridge/cartridge.hpp | 8 +- ares/sg/controller/controller.hpp | 4 +- ares/sg/controller/gamepad/gamepad.cpp | 4 +- ares/sg/controller/gamepad/gamepad.hpp | 14 +- ares/sg/controller/port.hpp | 4 +- ares/sg/cpu/cpu.hpp | 14 +- ares/sg/cpu/memory.cpp | 10 +- ares/sg/psg/psg.cpp | 4 +- ares/sg/psg/psg.hpp | 4 +- ares/sg/sg.hpp | 2 + ares/sg/system/serialization.cpp | 4 +- ares/sg/system/system.cpp | 54 +- ares/sg/system/system.hpp | 10 +- ares/sg/vdp/color.cpp | 2 +- ares/sg/vdp/vdp.cpp | 2 +- ares/sg/vdp/vdp.hpp | 4 +- ares/ws/apu/apu.cpp | 10 +- ares/ws/apu/apu.hpp | 158 +-- ares/ws/apu/channel2.cpp | 6 +- ares/ws/apu/channel4.cpp | 4 +- ares/ws/apu/channel5.cpp | 14 +- ares/ws/apu/dma.cpp | 2 +- ares/ws/apu/io.cpp | 6 +- ares/ws/cartridge/cartridge.cpp | 14 +- ares/ws/cartridge/cartridge.hpp | 68 +- ares/ws/cartridge/io.cpp | 6 +- ares/ws/cartridge/memory.cpp | 20 +- ares/ws/cartridge/rtc.cpp | 20 +- ares/ws/cartridge/serialization.cpp | 4 +- ares/ws/cpu/cpu.cpp | 12 +- ares/ws/cpu/cpu.hpp | 46 +- ares/ws/cpu/debugger.cpp | 2 +- ares/ws/cpu/dma.cpp | 2 +- ares/ws/cpu/interrupt.cpp | 8 +- ares/ws/cpu/io.cpp | 10 +- ares/ws/eeprom/eeprom.cpp | 12 +- ares/ws/eeprom/eeprom.hpp | 26 +- ares/ws/memory/memory.cpp | 22 +- ares/ws/memory/memory.hpp | 26 +- ares/ws/ppu/color.cpp | 14 +- ares/ws/ppu/io.cpp | 6 +- ares/ws/ppu/latch.cpp | 16 +- ares/ws/ppu/ppu.cpp | 10 +- ares/ws/ppu/ppu.hpp | 184 +-- ares/ws/ppu/render.cpp | 70 +- ares/ws/ppu/serialization.cpp | 6 +- ares/ws/system/controls.cpp | 2 +- ares/ws/system/io.cpp | 6 +- ares/ws/system/serialization.cpp | 4 +- ares/ws/system/system.cpp | 39 +- ares/ws/system/system.hpp | 25 +- ares/ws/ws.hpp | 3 +- hiro/GNUmakefile | 2 +- hiro/cocoa/action/menu-item.cpp | 2 +- hiro/cocoa/action/menu.cpp | 2 +- hiro/cocoa/application.cpp | 2 +- hiro/cocoa/desktop.cpp | 12 +- hiro/cocoa/font.cpp | 2 +- hiro/cocoa/keyboard.cpp | 2 +- hiro/cocoa/keyboard.hpp | 2 +- hiro/cocoa/message-window.cpp | 2 +- hiro/cocoa/monitor.cpp | 26 +- hiro/cocoa/monitor.hpp | 10 +- hiro/cocoa/timer.cpp | 2 +- hiro/cocoa/timer.hpp | 2 +- hiro/cocoa/utility.cpp | 6 +- hiro/cocoa/widget/canvas.cpp | 12 +- hiro/cocoa/widget/canvas.hpp | 4 +- hiro/cocoa/widget/combo-button.cpp | 2 +- hiro/cocoa/widget/console.cpp | 14 +- hiro/cocoa/widget/console.hpp | 14 +- hiro/cocoa/widget/hex-edit.cpp | 8 +- hiro/cocoa/widget/hex-edit.hpp | 8 +- hiro/cocoa/widget/horizontal-scroll-bar.cpp | 10 +- hiro/cocoa/widget/horizontal-scroll-bar.hpp | 4 +- hiro/cocoa/widget/horizontal-slider.cpp | 4 +- hiro/cocoa/widget/horizontal-slider.hpp | 4 +- hiro/cocoa/widget/label.cpp | 2 +- hiro/cocoa/widget/progress-bar.cpp | 2 +- hiro/cocoa/widget/progress-bar.hpp | 2 +- hiro/cocoa/widget/tab-frame.cpp | 10 +- hiro/cocoa/widget/table-view.cpp | 42 +- hiro/cocoa/widget/table-view.hpp | 6 +- hiro/cocoa/widget/vertical-scroll-bar.cpp | 10 +- hiro/cocoa/widget/vertical-scroll-bar.hpp | 4 +- hiro/cocoa/widget/vertical-slider.cpp | 4 +- hiro/cocoa/widget/vertical-slider.hpp | 4 +- hiro/cocoa/widget/widget.cpp | 8 +- hiro/cocoa/window.cpp | 10 +- hiro/cocoa/window.hpp | 4 +- hiro/core/action/action.hpp | 11 + hiro/core/action/menu-check-item.hpp | 19 + hiro/core/action/menu-item.hpp | 19 + hiro/core/action/menu-radio-item.hpp | 22 + hiro/core/action/menu-separator.hpp | 9 + hiro/core/action/menu.cpp | 6 +- hiro/core/action/menu.hpp | 27 + hiro/core/alignment.cpp | 12 +- hiro/core/alignment.hpp | 26 + hiro/core/application.cpp | 8 +- hiro/core/application.hpp | 12 +- hiro/core/browser-window.hpp | 21 + hiro/core/color.cpp | 24 +- hiro/core/color.hpp | 34 + hiro/core/core.hpp | 1059 +---------------- hiro/core/font.cpp | 6 +- hiro/core/font.hpp | 16 +- hiro/core/geometry.cpp | 24 +- hiro/core/geometry.hpp | 42 + hiro/core/gradient.hpp | 20 + hiro/core/group.cpp | 4 +- hiro/core/group.hpp | 4 +- hiro/core/hotkey.hpp | 30 + hiro/core/keyboard.cpp | 4 +- hiro/core/keyboard.hpp | 22 + hiro/core/lock.hpp | 2 +- hiro/core/menu-bar.cpp | 8 +- hiro/core/menu-bar.hpp | 21 + hiro/core/message-window.hpp | 26 + hiro/core/monitor.cpp | 10 +- hiro/core/monitor.hpp | 18 +- hiro/core/mouse.hpp | 12 + hiro/core/object.cpp | 6 +- hiro/core/object.hpp | 8 +- hiro/core/popup-menu.cpp | 8 +- hiro/core/popup-menu.hpp | 22 + hiro/core/position.cpp | 12 +- hiro/core/position.hpp | 28 + hiro/core/shared.hpp | 76 +- hiro/core/size.cpp | 12 +- hiro/core/size.hpp | 31 + hiro/core/status-bar.hpp | 14 + hiro/core/text-cursor.cpp | 12 +- hiro/core/text-cursor.hpp | 16 +- hiro/core/timer.cpp | 4 +- hiro/core/timer.hpp | 6 +- hiro/core/widget/button.hpp | 25 + hiro/core/widget/canvas.cpp | 6 +- hiro/core/widget/canvas.hpp | 2 +- hiro/core/widget/check-button.hpp | 28 + hiro/core/widget/check-label.hpp | 19 + hiro/core/widget/combo-button-item.hpp | 20 + hiro/core/widget/combo-button.cpp | 8 +- hiro/core/widget/combo-button.hpp | 25 + hiro/core/widget/combo-edit-item.hpp | 17 + hiro/core/widget/combo-edit.cpp | 6 +- hiro/core/widget/combo-edit.hpp | 39 + hiro/core/widget/console.hpp | 24 + hiro/core/widget/frame.cpp | 2 +- hiro/core/widget/frame.hpp | 22 + hiro/core/widget/hex-edit.cpp | 24 +- hiro/core/widget/hex-edit.hpp | 35 + hiro/core/widget/horizontal-scroll-bar.cpp | 8 +- hiro/core/widget/horizontal-scroll-bar.hpp | 19 + hiro/core/widget/horizontal-slider.cpp | 8 +- hiro/core/widget/horizontal-slider.hpp | 19 + hiro/core/widget/icon-view-item.hpp | 20 + hiro/core/widget/icon-view.cpp | 8 +- hiro/core/widget/icon-view.hpp | 48 + hiro/core/widget/line-edit.hpp | 28 + hiro/core/widget/progress-bar.cpp | 4 +- hiro/core/widget/progress-bar.hpp | 13 + hiro/core/widget/radio-button.hpp | 31 + hiro/core/widget/radio-label.hpp | 22 + hiro/core/widget/tab-frame-item.cpp | 2 +- hiro/core/widget/tab-frame-item.hpp | 4 +- hiro/core/widget/tab-frame.cpp | 2 +- hiro/core/widget/tab-frame.hpp | 4 +- hiro/core/widget/table-view-column.cpp | 12 +- hiro/core/widget/table-view-column.hpp | 20 +- hiro/core/widget/table-view-item.cpp | 6 +- hiro/core/widget/table-view-item.hpp | 8 +- hiro/core/widget/table-view.cpp | 16 +- hiro/core/widget/table-view.hpp | 14 +- hiro/core/widget/tree-view-item.cpp | 6 +- hiro/core/widget/tree-view-item.hpp | 4 +- hiro/core/widget/tree-view.cpp | 6 +- hiro/core/widget/tree-view.hpp | 6 +- hiro/core/widget/vertical-scroll-bar.cpp | 8 +- hiro/core/widget/vertical-scroll-bar.hpp | 19 + hiro/core/widget/vertical-slider.cpp | 8 +- hiro/core/widget/vertical-slider.hpp | 19 + hiro/core/window.cpp | 16 +- hiro/core/window.hpp | 18 +- hiro/extension/about-dialog.cpp | 13 +- hiro/extension/about-dialog.hpp | 3 +- hiro/extension/fixed-layout.cpp | 12 +- hiro/extension/fixed-layout.hpp | 8 +- hiro/extension/horizontal-layout.cpp | 72 +- hiro/extension/horizontal-layout.hpp | 34 +- hiro/extension/horizontal-resize-grip.cpp | 6 +- hiro/extension/horizontal-resize-grip.hpp | 8 +- hiro/extension/list-view.cpp | 2 +- hiro/extension/list-view.hpp | 4 +- hiro/extension/message-dialog.cpp | 6 +- hiro/extension/table-layout.cpp | 96 +- hiro/extension/table-layout.hpp | 30 +- hiro/extension/vertical-layout.cpp | 72 +- hiro/extension/vertical-layout.hpp | 34 +- hiro/extension/vertical-resize-grip.cpp | 6 +- hiro/extension/vertical-resize-grip.hpp | 8 +- hiro/gtk/desktop.cpp | 8 +- hiro/gtk/font.cpp | 2 +- hiro/gtk/keyboard.cpp | 16 +- hiro/gtk/keyboard.hpp | 6 +- hiro/gtk/monitor.cpp | 10 +- hiro/gtk/monitor.hpp | 10 +- hiro/gtk/mouse.cpp | 10 +- hiro/gtk/popup-menu.hpp | 2 +- hiro/gtk/settings.hpp | 14 +- hiro/gtk/timer.cpp | 2 +- hiro/gtk/timer.hpp | 2 +- hiro/gtk/utility.cpp | 2 +- hiro/gtk/widget/canvas.cpp | 26 +- hiro/gtk/widget/canvas.hpp | 6 +- hiro/gtk/widget/check-label.hpp | 2 +- hiro/gtk/widget/combo-button.cpp | 4 +- hiro/gtk/widget/combo-button.hpp | 2 +- hiro/gtk/widget/combo-edit.cpp | 6 +- hiro/gtk/widget/combo-edit.hpp | 2 +- hiro/gtk/widget/console.cpp | 4 +- hiro/gtk/widget/console.hpp | 6 +- hiro/gtk/widget/hex-edit.cpp | 60 +- hiro/gtk/widget/hex-edit.hpp | 20 +- hiro/gtk/widget/horizontal-scroll-bar.cpp | 6 +- hiro/gtk/widget/horizontal-scroll-bar.hpp | 6 +- hiro/gtk/widget/horizontal-slider.cpp | 6 +- hiro/gtk/widget/horizontal-slider.hpp | 4 +- hiro/gtk/widget/icon-view.cpp | 16 +- hiro/gtk/widget/icon-view.hpp | 14 +- hiro/gtk/widget/label.cpp | 20 +- hiro/gtk/widget/line-edit.hpp | 2 +- hiro/gtk/widget/progress-bar.cpp | 4 +- hiro/gtk/widget/progress-bar.hpp | 4 +- hiro/gtk/widget/radio-button.hpp | 2 +- hiro/gtk/widget/radio-label.hpp | 2 +- hiro/gtk/widget/source-edit.cpp | 8 +- hiro/gtk/widget/tab-frame.cpp | 40 +- hiro/gtk/widget/tab-frame.hpp | 18 +- hiro/gtk/widget/table-view-column.cpp | 4 +- hiro/gtk/widget/table-view-column.hpp | 2 +- hiro/gtk/widget/table-view-item.hpp | 2 +- hiro/gtk/widget/table-view.cpp | 46 +- hiro/gtk/widget/table-view.hpp | 12 +- hiro/gtk/widget/text-edit.cpp | 8 +- hiro/gtk/widget/tree-view-item.cpp | 4 +- hiro/gtk/widget/tree-view-item.hpp | 6 +- hiro/gtk/widget/tree-view.cpp | 12 +- hiro/gtk/widget/tree-view.hpp | 8 +- hiro/gtk/widget/vertical-scroll-bar.cpp | 6 +- hiro/gtk/widget/vertical-scroll-bar.hpp | 6 +- hiro/gtk/widget/vertical-slider.cpp | 6 +- hiro/gtk/widget/vertical-slider.hpp | 4 +- hiro/gtk/widget/viewport.cpp | 8 +- hiro/gtk/widget/widget.cpp | 16 +- hiro/gtk/window.cpp | 52 +- hiro/gtk/window.hpp | 16 +- hiro/qt/desktop.cpp | 10 +- hiro/qt/font.cpp | 2 +- hiro/qt/keyboard.cpp | 12 +- hiro/qt/keyboard.hpp | 4 +- hiro/qt/monitor.cpp | 10 +- hiro/qt/monitor.hpp | 8 +- hiro/qt/qt.hpp | 10 +- hiro/qt/qt.moc | 18 +- hiro/qt/settings.hpp | 12 +- hiro/qt/timer.cpp | 2 +- hiro/qt/timer.hpp | 2 +- hiro/qt/utility.cpp | 222 +--- hiro/qt/widget/canvas.cpp | 16 +- hiro/qt/widget/canvas.hpp | 4 +- hiro/qt/widget/check-label.cpp | 2 +- hiro/qt/widget/combo-button.cpp | 4 +- hiro/qt/widget/hex-edit.cpp | 46 +- hiro/qt/widget/hex-edit.hpp | 14 +- hiro/qt/widget/horizontal-scroll-bar.cpp | 8 +- hiro/qt/widget/horizontal-scroll-bar.hpp | 4 +- hiro/qt/widget/horizontal-slider.cpp | 8 +- hiro/qt/widget/horizontal-slider.hpp | 4 +- hiro/qt/widget/progress-bar.cpp | 2 +- hiro/qt/widget/progress-bar.hpp | 2 +- hiro/qt/widget/tab-frame.cpp | 4 +- hiro/qt/widget/table-view-column.cpp | 2 +- hiro/qt/widget/table-view-column.hpp | 2 +- hiro/qt/widget/table-view.cpp | 38 +- hiro/qt/widget/table-view.hpp | 6 +- hiro/qt/widget/text-edit.cpp | 2 +- hiro/qt/widget/vertical-scroll-bar.cpp | 8 +- hiro/qt/widget/vertical-scroll-bar.hpp | 4 +- hiro/qt/widget/vertical-slider.cpp | 8 +- hiro/qt/widget/vertical-slider.hpp | 4 +- hiro/qt/window.cpp | 20 +- hiro/qt/window.hpp | 10 +- hiro/windows/action/action.hpp | 2 +- hiro/windows/action/menu.cpp | 4 +- hiro/windows/application.cpp | 6 + hiro/windows/application.hpp | 7 +- hiro/windows/browser-window.cpp | 2 +- hiro/windows/font.cpp | 2 +- hiro/windows/keyboard.cpp | 10 +- hiro/windows/keyboard.hpp | 6 +- hiro/windows/menu-bar.cpp | 18 +- hiro/windows/menu-bar.hpp | 1 + hiro/windows/monitor.cpp | 18 +- hiro/windows/monitor.hpp | 10 +- hiro/windows/popup-menu.cpp | 4 +- hiro/windows/settings.hpp | 8 +- hiro/windows/timer.cpp | 2 +- hiro/windows/timer.hpp | 2 +- hiro/windows/tool-tip.cpp | 8 +- hiro/windows/tool-tip.hpp | 2 +- hiro/windows/utility.cpp | 30 +- hiro/windows/widget/button.cpp | 12 +- hiro/windows/widget/canvas.cpp | 24 +- hiro/windows/widget/canvas.hpp | 8 +- hiro/windows/widget/check-button.cpp | 2 +- hiro/windows/widget/combo-button.cpp | 4 +- hiro/windows/widget/hex-edit.cpp | 42 +- hiro/windows/widget/hex-edit.hpp | 18 +- hiro/windows/widget/horizontal-scroll-bar.cpp | 6 +- hiro/windows/widget/horizontal-scroll-bar.hpp | 4 +- hiro/windows/widget/horizontal-slider.cpp | 6 +- hiro/windows/widget/horizontal-slider.hpp | 4 +- hiro/windows/widget/label.cpp | 6 +- hiro/windows/widget/line-edit.cpp | 2 +- hiro/windows/widget/progress-bar.cpp | 2 +- hiro/windows/widget/progress-bar.hpp | 2 +- hiro/windows/widget/radio-button.cpp | 2 +- hiro/windows/widget/tab-frame.cpp | 6 +- hiro/windows/widget/table-view-column.cpp | 6 +- hiro/windows/widget/table-view-column.hpp | 6 +- hiro/windows/widget/table-view.cpp | 44 +- hiro/windows/widget/table-view.hpp | 12 +- hiro/windows/widget/text-edit.cpp | 8 +- hiro/windows/widget/vertical-scroll-bar.cpp | 6 +- hiro/windows/widget/vertical-scroll-bar.hpp | 4 +- hiro/windows/widget/vertical-slider.cpp | 6 +- hiro/windows/widget/vertical-slider.hpp | 4 +- hiro/windows/widget/viewport.cpp | 2 +- hiro/windows/widget/viewport.hpp | 2 +- hiro/windows/widget/widget.cpp | 2 +- hiro/windows/widget/widget.hpp | 2 +- hiro/windows/window.cpp | 22 +- hiro/windows/window.hpp | 8 +- lucia/GNUmakefile | 2 +- lucia/emulator/colecovision.cpp | 3 +- lucia/emulator/emulator.cpp | 25 + lucia/emulator/emulator.hpp | 2 + lucia/emulator/famicom.cpp | 6 +- lucia/emulator/game-boy-advance.cpp | 2 +- lucia/emulator/game-boy.cpp | 4 +- lucia/emulator/master-system.cpp | 11 +- lucia/emulator/mega-drive.cpp | 34 +- lucia/emulator/msx.cpp | 6 +- lucia/emulator/neo-geo-pocket.cpp | 4 +- lucia/emulator/nintendo-64.cpp | 6 +- lucia/emulator/pc-engine.cpp | 35 +- lucia/emulator/playstation.cpp | 21 +- lucia/emulator/sg-1000.cpp | 3 +- lucia/emulator/super-famicom.cpp | 18 +- lucia/emulator/wonderswan.cpp | 6 +- lucia/input/input.hpp | 8 +- lucia/presentation/presentation.cpp | 9 +- lucia/program/load.cpp | 5 +- lucia/program/platform.cpp | 4 +- lucia/program/program.cpp | 7 + lucia/resource/lucia.Manifest | 2 +- luna/GNUmakefile | 101 -- luna/emulator/audio.cpp | 56 - luna/emulator/emulator.cpp | 152 --- luna/emulator/emulator.hpp | 76 -- luna/emulator/input.cpp | 14 - luna/emulator/platform.cpp | 210 ---- luna/emulator/states.cpp | 33 - luna/emulator/status.cpp | 14 - luna/emulator/utility.cpp | 7 - luna/emulator/video.cpp | 82 -- luna/input/hotkeys.cpp | 144 --- luna/input/hotkeys.hpp | 47 - luna/input/input.cpp | 115 -- luna/input/input.hpp | 38 - luna/luna.cpp | 174 --- luna/luna.hpp | 28 - luna/menus/action.cpp | 17 - luna/menus/help.cpp | 16 - luna/menus/menus.cpp | 6 - luna/menus/menus.hpp | 62 - luna/menus/settings.cpp | 100 -- luna/menus/system.cpp | 10 - luna/menus/tools.cpp | 22 - luna/obj/.gitignore | 2 - luna/out/.gitignore | 2 - luna/panel-items/audio.cpp | 120 -- luna/panel-items/audio.hpp | 42 - luna/panel-items/home.cpp | 23 - luna/panel-items/home.hpp | 8 - luna/panel-items/hotkeys.cpp | 126 -- luna/panel-items/hotkeys.hpp | 24 - luna/panel-items/input-mapper.cpp | 210 ---- luna/panel-items/input-mapper.hpp | 31 - luna/panel-items/input.cpp | 47 - luna/panel-items/input.hpp | 23 - luna/panel-items/peripheral-overview.cpp | 19 - luna/panel-items/peripheral-overview.hpp | 11 - luna/panel-items/port-connector.cpp | 298 ----- luna/panel-items/port-connector.hpp | 28 - luna/panel-items/setting-editor.cpp | 51 - luna/panel-items/setting-editor.hpp | 17 - luna/panel-items/system-creation.cpp | 78 -- luna/panel-items/system-creation.hpp | 16 - luna/panel-items/system-overview.cpp | 43 - luna/panel-items/system-overview.hpp | 15 - luna/panel-items/video.cpp | 105 -- luna/panel-items/video.hpp | 42 - luna/panel-lists/event-manager.cpp | 43 - luna/panel-lists/event-manager.hpp | 12 - luna/panel-lists/node-manager.cpp | 104 -- luna/panel-lists/node-manager.hpp | 13 - luna/panel-lists/port-manager.cpp | 77 -- luna/panel-lists/port-manager.hpp | 12 - luna/panel-lists/settings-manager.cpp | 32 - luna/panel-lists/settings-manager.hpp | 10 - luna/panel-lists/system-manager.cpp | 157 --- luna/panel-lists/system-manager.hpp | 21 - luna/program/program.cpp | 217 ---- luna/program/program.hpp | 115 -- luna/resource/GNUmakefile | 6 - luna/resource/luna.Manifest | 15 - luna/resource/luna.desktop | 8 - luna/resource/luna.ico | Bin 26041 -> 0 bytes luna/resource/luna.plist | 18 - luna/resource/luna.png | Bin 11155 -> 0 bytes luna/resource/luna.rc | 2 - luna/resource/resource.bml | 1 - luna/resource/resource.cpp | 4 - luna/resource/resource.hpp | 2 - luna/settings/settings.cpp | 67 -- luna/settings/settings.hpp | 48 - mia/cartridge/colecovision.cpp | 1 + mia/cartridge/famicom.cpp | 8 +- mia/cartridge/master-system.cpp | 5 +- mia/cartridge/msx.cpp | 5 +- mia/cartridge/sg-1000.cpp | 1 + mia/program/program.cpp | 1 + nall/GNUmakefile | 4 +- nall/adaptive-array.hpp | 14 +- nall/arguments.hpp | 20 +- nall/arithmetic.hpp | 14 +- nall/arithmetic/barrett.hpp | 4 +- nall/arithmetic/natural.hpp | 24 +- nall/arithmetic/unsigned.hpp | 4 +- nall/array-span.hpp | 42 +- nall/array-view.hpp | 68 +- nall/array.hpp | 20 +- nall/atoi.hpp | 20 +- nall/beat/archive/container.hpp | 200 ---- nall/beat/archive/create.hpp | 86 -- nall/beat/archive/extract.hpp | 27 - nall/beat/archive/node.hpp | 332 ------ nall/beat/single/apply.hpp | 40 +- nall/beat/single/create.hpp | 34 +- nall/bit.hpp | 36 +- nall/bump-allocator.hpp | 32 +- nall/cd/crc16.hpp | 6 +- nall/cd/edc.hpp | 32 +- nall/cd/efm.hpp | 18 +- nall/cd/rspc.hpp | 58 +- nall/cd/scrambler.hpp | 14 +- nall/cd/session.hpp | 172 +-- nall/cd/sync.hpp | 8 +- nall/chrono.hpp | 129 +- nall/cipher/chacha20.hpp | 36 +- nall/counting-sort.hpp | 14 +- nall/database/odbc.hpp | 102 +- nall/database/sqlite3.hpp | 72 +- nall/decode/base.hpp | 6 +- nall/decode/base64.hpp | 18 +- nall/decode/bmp.hpp | 44 +- nall/decode/bwt.hpp | 32 +- nall/decode/cue.hpp | 64 +- nall/decode/gzip.hpp | 28 +- nall/decode/html.hpp | 2 +- nall/decode/huffman.hpp | 20 +- nall/decode/inflate.hpp | 109 +- nall/decode/lzsa.hpp | 36 +- nall/decode/mtf.hpp | 14 +- nall/decode/png.hpp | 174 +-- nall/decode/rle.hpp | 24 +- nall/decode/url.hpp | 2 +- nall/decode/wav.hpp | 32 +- nall/decode/zip.hpp | 48 +- nall/directory.hpp | 16 +- nall/dsp/dsp.hpp | 5 - nall/dsp/iir/biquad.hpp | 44 +- nall/dsp/iir/dc-removal.hpp | 10 +- nall/dsp/iir/one-pole.hpp | 22 +- nall/dsp/resampler/cubic.hpp | 39 +- nall/elliptic-curve/curve25519.hpp | 6 +- nall/elliptic-curve/ed25519.hpp | 48 +- nall/elliptic-curve/modulo25519-optimized.hpp | 102 +- nall/elliptic-curve/modulo25519-reference.hpp | 24 +- nall/emulation/21fx.hpp | 52 +- nall/encode/base.hpp | 4 +- nall/encode/base64.hpp | 20 +- nall/encode/bmp.hpp | 16 +- nall/encode/bwt.hpp | 28 +- nall/encode/huffman.hpp | 50 +- nall/encode/lzsa.hpp | 34 +- nall/encode/mtf.hpp | 16 +- nall/encode/png.hpp | 44 +- nall/encode/rle.hpp | 28 +- nall/encode/url.hpp | 4 +- nall/encode/wav.hpp | 10 +- nall/encode/zip.hpp | 20 +- nall/file-buffer.hpp | 62 +- nall/file-map.hpp | 32 +- nall/file.hpp | 20 +- nall/galois-field.hpp | 18 +- nall/hash/crc16.hpp | 18 +- nall/hash/crc32.hpp | 18 +- nall/hash/crc64.hpp | 18 +- nall/hash/hash.hpp | 16 +- nall/hash/sha224.hpp | 50 +- nall/hash/sha256.hpp | 50 +- nall/hash/sha384.hpp | 54 +- nall/hash/sha512.hpp | 54 +- nall/hashset.hpp | 28 +- nall/hid.hpp | 46 +- nall/http/client.hpp | 8 +- nall/http/message.hpp | 4 +- nall/http/request.hpp | 14 +- nall/http/response.hpp | 46 +- nall/http/role.hpp | 40 +- nall/http/server.hpp | 58 +- nall/image.hpp | 108 +- nall/image/blend.hpp | 32 +- nall/image/core.hpp | 42 +- nall/image/fill.hpp | 62 +- nall/image/interpolation.hpp | 36 +- nall/image/load.hpp | 36 +- nall/image/scale.hpp | 104 +- nall/image/static.hpp | 10 +- nall/image/utility.hpp | 112 +- nall/induced-sort.hpp | 70 +- nall/inode.hpp | 22 +- nall/interpolation.hpp | 26 +- nall/intrinsics.hpp | 25 +- nall/iterator.hpp | 28 +- nall/locale.hpp | 2 +- nall/location.hpp | 12 +- nall/mac/poly1305.hpp | 62 +- nall/matrix-multiply.hpp | 14 +- nall/matrix.hpp | 84 +- nall/memory.hpp | 136 ++- nall/merge-sort.hpp | 18 +- nall/platform.hpp | 20 +- nall/posix/shared-memory.hpp | 20 +- nall/primitives.hpp | 6 +- nall/primitives/bit-field.hpp | 28 +- nall/primitives/bit-range.hpp | 40 +- nall/primitives/boolean.hpp | 2 +- nall/primitives/integer.hpp | 52 +- nall/primitives/natural.hpp | 52 +- nall/primitives/real.hpp | 14 +- nall/queue/spsc.hpp | 8 +- nall/queue/st.hpp | 40 +- nall/random.hpp | 56 +- nall/range.hpp | 28 +- nall/recompiler/amd64/constants.hpp | 8 +- nall/recompiler/amd64/emitter.hpp | 2 +- .../recompiler/amd64/encoder-instructions.hpp | 20 +- nall/reed-solomon.hpp | 80 +- nall/serial.hpp | 6 +- nall/serializer.hpp | 40 +- nall/set.hpp | 16 +- nall/shared-pointer.hpp | 6 +- nall/smtp.hpp | 48 +- nall/string.hpp | 110 +- nall/string/allocator/adaptive.hpp | 16 +- nall/string/allocator/copy-on-write.hpp | 12 +- .../allocator/small-string-optimization.hpp | 4 +- nall/string/allocator/vector.hpp | 4 +- nall/string/atoi.hpp | 8 +- nall/string/cast.hpp | 110 +- nall/string/compare.hpp | 10 +- nall/string/convert.hpp | 12 +- nall/string/core.hpp | 6 +- nall/string/eval/evaluator.hpp | 8 +- nall/string/eval/literal.hpp | 6 +- nall/string/eval/node.hpp | 2 +- nall/string/eval/parser.hpp | 14 +- nall/string/find.hpp | 36 +- nall/string/format.hpp | 38 +- nall/string/markup/bml.hpp | 26 +- nall/string/markup/find.hpp | 6 +- nall/string/markup/node.hpp | 32 +- nall/string/markup/xml.hpp | 4 +- nall/string/pascal.hpp | 34 +- nall/string/replace.hpp | 22 +- nall/string/split.hpp | 8 +- nall/string/transform/cml.hpp | 4 +- nall/string/transform/dml.hpp | 26 +- nall/string/trim.hpp | 28 +- nall/string/utf8.hpp | 8 +- nall/string/utility.hpp | 65 +- nall/string/vector.hpp | 14 +- nall/string/view.hpp | 4 +- nall/suffix-array.hpp | 118 +- nall/thread.hpp | 8 +- nall/traits.hpp | 8 +- nall/unique-pointer.hpp | 4 +- nall/utility.hpp | 4 +- nall/variant.hpp | 30 +- nall/varint.hpp | 80 +- nall/vector.hpp | 68 +- nall/vector/access.hpp | 8 +- nall/vector/assign.hpp | 2 +- nall/vector/compare.hpp | 2 +- nall/vector/core.hpp | 4 +- nall/vector/iterator.hpp | 16 +- nall/vector/memory.hpp | 32 +- nall/vector/modify.hpp | 24 +- nall/vector/specialization/u8.hpp | 38 + nall/vector/specialization/uint8_t.hpp | 38 - nall/vector/utility.hpp | 24 +- nall/vfs/cdrom.hpp | 44 +- nall/vfs/disk.hpp | 14 +- nall/vfs/memory.hpp | 30 +- nall/vfs/vfs.hpp | 40 +- nall/windows/detour.hpp | 52 +- nall/windows/launcher.hpp | 14 +- nall/windows/registry.hpp | 6 +- nall/windows/shared-memory.hpp | 8 +- nall/windows/utf8.hpp | 12 +- ruby/video/cgl.cpp | 49 +- ruby/video/glx.cpp | 41 +- ruby/video/glx2.cpp | 34 +- ruby/video/video.cpp | 10 - ruby/video/video.hpp | 4 - ruby/video/wgl.cpp | 40 +- 1395 files changed, 19084 insertions(+), 23498 deletions(-) create mode 100644 ares/Shaders/Curvature.shader/curvature.fs create mode 100644 ares/Shaders/Curvature.shader/manifest.bml create mode 100644 ares/Shaders/Edge Detection.shader/edge-detection.fs create mode 100644 ares/Shaders/Edge Detection.shader/manifest.bml create mode 100644 ares/Shaders/Scanline.shader/manifest.bml create mode 100644 ares/Shaders/Scanline.shader/scanline.fs create mode 100644 ares/n64/memory/lsb-readable.hpp create mode 100644 ares/n64/memory/lsb-writable.hpp rename ares/n64/memory/{readable.hpp => msb-readable.hpp} (52%) create mode 100644 ares/n64/memory/msb-writable.hpp delete mode 100644 ares/n64/memory/writable.hpp create mode 100644 hiro/core/action/action.hpp create mode 100644 hiro/core/action/menu-check-item.hpp create mode 100644 hiro/core/action/menu-item.hpp create mode 100644 hiro/core/action/menu-radio-item.hpp create mode 100644 hiro/core/action/menu-separator.hpp create mode 100644 hiro/core/action/menu.hpp create mode 100644 hiro/core/alignment.hpp create mode 100644 hiro/core/browser-window.hpp create mode 100644 hiro/core/color.hpp create mode 100644 hiro/core/geometry.hpp create mode 100644 hiro/core/gradient.hpp create mode 100644 hiro/core/hotkey.hpp create mode 100644 hiro/core/keyboard.hpp create mode 100644 hiro/core/menu-bar.hpp create mode 100644 hiro/core/message-window.hpp create mode 100644 hiro/core/mouse.hpp create mode 100644 hiro/core/popup-menu.hpp create mode 100644 hiro/core/position.hpp create mode 100644 hiro/core/size.hpp create mode 100644 hiro/core/status-bar.hpp create mode 100644 hiro/core/widget/button.hpp create mode 100644 hiro/core/widget/check-button.hpp create mode 100644 hiro/core/widget/check-label.hpp create mode 100644 hiro/core/widget/combo-button-item.hpp create mode 100644 hiro/core/widget/combo-button.hpp create mode 100644 hiro/core/widget/combo-edit-item.hpp create mode 100644 hiro/core/widget/combo-edit.hpp create mode 100644 hiro/core/widget/console.hpp create mode 100644 hiro/core/widget/frame.hpp create mode 100644 hiro/core/widget/hex-edit.hpp create mode 100644 hiro/core/widget/horizontal-scroll-bar.hpp create mode 100644 hiro/core/widget/horizontal-slider.hpp create mode 100644 hiro/core/widget/icon-view-item.hpp create mode 100644 hiro/core/widget/icon-view.hpp create mode 100644 hiro/core/widget/line-edit.hpp create mode 100644 hiro/core/widget/progress-bar.hpp create mode 100644 hiro/core/widget/radio-button.hpp create mode 100644 hiro/core/widget/radio-label.hpp create mode 100644 hiro/core/widget/vertical-scroll-bar.hpp create mode 100644 hiro/core/widget/vertical-slider.hpp delete mode 100644 luna/GNUmakefile delete mode 100644 luna/emulator/audio.cpp delete mode 100644 luna/emulator/emulator.cpp delete mode 100644 luna/emulator/emulator.hpp delete mode 100644 luna/emulator/input.cpp delete mode 100644 luna/emulator/platform.cpp delete mode 100644 luna/emulator/states.cpp delete mode 100644 luna/emulator/status.cpp delete mode 100644 luna/emulator/utility.cpp delete mode 100644 luna/emulator/video.cpp delete mode 100644 luna/input/hotkeys.cpp delete mode 100644 luna/input/hotkeys.hpp delete mode 100644 luna/input/input.cpp delete mode 100644 luna/input/input.hpp delete mode 100644 luna/luna.cpp delete mode 100644 luna/luna.hpp delete mode 100644 luna/menus/action.cpp delete mode 100644 luna/menus/help.cpp delete mode 100644 luna/menus/menus.cpp delete mode 100644 luna/menus/menus.hpp delete mode 100644 luna/menus/settings.cpp delete mode 100644 luna/menus/system.cpp delete mode 100644 luna/menus/tools.cpp delete mode 100644 luna/obj/.gitignore delete mode 100644 luna/out/.gitignore delete mode 100644 luna/panel-items/audio.cpp delete mode 100644 luna/panel-items/audio.hpp delete mode 100644 luna/panel-items/home.cpp delete mode 100644 luna/panel-items/home.hpp delete mode 100644 luna/panel-items/hotkeys.cpp delete mode 100644 luna/panel-items/hotkeys.hpp delete mode 100644 luna/panel-items/input-mapper.cpp delete mode 100644 luna/panel-items/input-mapper.hpp delete mode 100644 luna/panel-items/input.cpp delete mode 100644 luna/panel-items/input.hpp delete mode 100644 luna/panel-items/peripheral-overview.cpp delete mode 100644 luna/panel-items/peripheral-overview.hpp delete mode 100644 luna/panel-items/port-connector.cpp delete mode 100644 luna/panel-items/port-connector.hpp delete mode 100644 luna/panel-items/setting-editor.cpp delete mode 100644 luna/panel-items/setting-editor.hpp delete mode 100644 luna/panel-items/system-creation.cpp delete mode 100644 luna/panel-items/system-creation.hpp delete mode 100644 luna/panel-items/system-overview.cpp delete mode 100644 luna/panel-items/system-overview.hpp delete mode 100644 luna/panel-items/video.cpp delete mode 100644 luna/panel-items/video.hpp delete mode 100644 luna/panel-lists/event-manager.cpp delete mode 100644 luna/panel-lists/event-manager.hpp delete mode 100644 luna/panel-lists/node-manager.cpp delete mode 100644 luna/panel-lists/node-manager.hpp delete mode 100644 luna/panel-lists/port-manager.cpp delete mode 100644 luna/panel-lists/port-manager.hpp delete mode 100644 luna/panel-lists/settings-manager.cpp delete mode 100644 luna/panel-lists/settings-manager.hpp delete mode 100644 luna/panel-lists/system-manager.cpp delete mode 100644 luna/panel-lists/system-manager.hpp delete mode 100644 luna/program/program.cpp delete mode 100644 luna/program/program.hpp delete mode 100644 luna/resource/GNUmakefile delete mode 100644 luna/resource/luna.Manifest delete mode 100644 luna/resource/luna.desktop delete mode 100644 luna/resource/luna.ico delete mode 100644 luna/resource/luna.plist delete mode 100644 luna/resource/luna.png delete mode 100644 luna/resource/luna.rc delete mode 100644 luna/resource/resource.bml delete mode 100644 luna/resource/resource.cpp delete mode 100644 luna/resource/resource.hpp delete mode 100644 luna/settings/settings.cpp delete mode 100644 luna/settings/settings.hpp delete mode 100644 nall/beat/archive/container.hpp delete mode 100644 nall/beat/archive/create.hpp delete mode 100644 nall/beat/archive/extract.hpp delete mode 100644 nall/beat/archive/node.hpp delete mode 100644 nall/dsp/dsp.hpp create mode 100644 nall/vector/specialization/u8.hpp delete mode 100644 nall/vector/specialization/uint8_t.hpp diff --git a/ares/Shaders/Curvature.shader/curvature.fs b/ares/Shaders/Curvature.shader/curvature.fs new file mode 100644 index 0000000000..d6db5b838a --- /dev/null +++ b/ares/Shaders/Curvature.shader/curvature.fs @@ -0,0 +1,21 @@ +#version 150 +#define distortion 0.2 + +uniform sampler2D source[]; +uniform vec4 sourceSize[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +vec2 radialDistortion(vec2 coord) { + vec2 cc = coord - vec2(0.5); + float dist = dot(cc, cc) * distortion; + return coord + cc * (1.0 - dist) * dist; +} + +void main() { + fragColor = texture(source[0], radialDistortion(texCoord)); +} diff --git a/ares/Shaders/Curvature.shader/manifest.bml b/ares/Shaders/Curvature.shader/manifest.bml new file mode 100644 index 0000000000..7bec47091f --- /dev/null +++ b/ares/Shaders/Curvature.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: border + fragment: curvature.fs diff --git a/ares/Shaders/Edge Detection.shader/edge-detection.fs b/ares/Shaders/Edge Detection.shader/edge-detection.fs new file mode 100644 index 0000000000..bf00fc2549 --- /dev/null +++ b/ares/Shaders/Edge Detection.shader/edge-detection.fs @@ -0,0 +1,25 @@ +#version 150 + +uniform sampler2D source[]; +uniform vec4 sourceSize[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +vec3 grayscale(vec3 color) { + return vec3(dot(color, vec3(0.3, 0.59, 0.11))); +} + +void main() { + vec2 offset = fract(texCoord * sourceSize[0].xy) - 0.5; + offset /= sourceSize[0].xy; + + vec3 cx = texture(source[0], texCoord - offset).xyz; + vec3 cy = texture(source[0], texCoord).xyz; + vec3 cz = vec3(5.0 * grayscale(abs(cx - cy))); + + fragColor = vec4(clamp(cz, 0.0, 1.0), 1.0); +} diff --git a/ares/Shaders/Edge Detection.shader/manifest.bml b/ares/Shaders/Edge Detection.shader/manifest.bml new file mode 100644 index 0000000000..166db6dea7 --- /dev/null +++ b/ares/Shaders/Edge Detection.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: edge + fragment: edge-detection.fs diff --git a/ares/Shaders/Scanline.shader/manifest.bml b/ares/Shaders/Scanline.shader/manifest.bml new file mode 100644 index 0000000000..a5db6351ba --- /dev/null +++ b/ares/Shaders/Scanline.shader/manifest.bml @@ -0,0 +1,4 @@ +program + filter: linear + wrap: border + fragment: scanline.fs diff --git a/ares/Shaders/Scanline.shader/scanline.fs b/ares/Shaders/Scanline.shader/scanline.fs new file mode 100644 index 0000000000..42a9603a58 --- /dev/null +++ b/ares/Shaders/Scanline.shader/scanline.fs @@ -0,0 +1,20 @@ +#version 150 + +uniform sampler2D source[]; + +in Vertex { + vec2 texCoord; +}; + +out vec4 fragColor; + +void main() { + vec4 rgba = texture(source[0], texCoord); + vec4 intensity; + if(fract(gl_FragCoord.y * (0.5 * 4.0 / 3.0)) > 0.5) { + intensity = vec4(0); + } else { + intensity = smoothstep(0.2, 0.8, rgba) + normalize(rgba); + } + fragColor = intensity * -0.25 + rgba * 1.1; +} diff --git a/ares/ares/debug/debug.hpp b/ares/ares/debug/debug.hpp index 6a636af038..5abebf287a 100644 --- a/ares/ares/debug/debug.hpp +++ b/ares/ares/debug/debug.hpp @@ -1,8 +1,6 @@ namespace ares { struct Debug { - static constexpr auto enabled() -> bool { return true; } - auto reset() -> void; template auto unhandled(P&&... p) -> void { @@ -37,4 +35,4 @@ extern Debug _debug; } -#define debug(function, ...) if constexpr(ares::_debug.enabled()) ares::_debug.function(__VA_ARGS__) +#define debug(function, ...) if constexpr(1) ares::_debug.function(__VA_ARGS__) diff --git a/ares/ares/information.hpp b/ares/ares/information.hpp index 07a2b67b3c..9a966bca15 100644 --- a/ares/ares/information.hpp +++ b/ares/ares/information.hpp @@ -2,13 +2,14 @@ namespace ares { static const string Name = "ares"; - static const string Version = "116.8"; + static const string Version = "117"; + static const string Copyright = "Near"; static const string License = "CC BY-NC-ND 4.0"; static const string LicenseURI = "https://creativecommons.org/licenses/by-nc-nd/4.0/"; static const string Website = "ares.dev"; static const string WebsiteURI = "https://ares.dev"; //incremented only when serialization format changes - static const u32 SerializerSignature = 0x31545341; //"AST1" (little-endian) - static const string SerializerVersion = "116"; + static const u32 SerializerSignature = 0x31545342; //"BST1" (little-endian) + static const string SerializerVersion = "117"; } diff --git a/ares/ares/node/debugger/tracer/instruction.hpp b/ares/ares/node/debugger/tracer/instruction.hpp index bd05d48d91..85d41cfdde 100644 --- a/ares/ares/node/debugger/tracer/instruction.hpp +++ b/ares/ares/node/debugger/tracer/instruction.hpp @@ -24,7 +24,7 @@ struct Instruction : Tracer { _depth = depth; _history.reset(); _history.resize(depth); - for(auto& history : _history) history = ~0ull; + for(auto& history : _history) history = ~0; } auto address(u32 address) -> bool { diff --git a/ares/ares/node/object.hpp b/ares/ares/node/object.hpp index 7dbd4ec4da..7a19ac3bdf 100644 --- a/ares/ares/node/object.hpp +++ b/ares/ares/node/object.hpp @@ -3,12 +3,16 @@ #define DeclareClass(Type, Name) \ static inline const string identifier = Name; \ - virtual auto identity() const -> string { return Name; } \ static auto create() -> Node::Object { return new Type; } \ + auto identity() const -> string override { return Name; } \ private: static inline Class::Register register; public: \ struct Object : shared_pointer_this { - DeclareClass(Object, "object") + static inline const string identifier = "Object"; + static auto create() -> Node::Object { return new Object; } + virtual auto identity() const -> string { return "Object"; } + private: static inline Class::Register register; public: +//DeclareClass(Object, "object") Object(string name = {}) : _name(name) {} virtual ~Object() = default; diff --git a/ares/ares/scheduler/thread.hpp b/ares/ares/scheduler/thread.hpp index 3726420522..0ac5013433 100644 --- a/ares/ares/scheduler/thread.hpp +++ b/ares/ares/scheduler/thread.hpp @@ -2,7 +2,7 @@ struct Scheduler; struct Thread { enum : uintmax { Second = (uintmax)-1 >> 1 }; - enum : uintmax { Size = 8_KiB * sizeof(void*) }; + enum : uintmax { Size = 16_KiB * sizeof(void*) }; struct EntryPoint { cothread_t handle = nullptr; diff --git a/ares/ares/types.hpp b/ares/ares/types.hpp index d4feb4b948..37dabd0aac 100644 --- a/ares/ares/types.hpp +++ b/ares/ares/types.hpp @@ -1,3 +1,5 @@ +using b1 = nall::Boolean; + using i1 = nall::Integer< 1>; using i2 = nall::Integer< 2>; using i3 = nall::Integer< 3>; @@ -7,15 +9,6 @@ using i6 = nall::Integer< 6>; using i7 = nall::Integer< 7>; using i8 = nall::Integer< 8>; using i9 = nall::Integer< 9>; -using i01 = nall::Integer< 1>; -using i02 = nall::Integer< 2>; -using i03 = nall::Integer< 3>; -using i04 = nall::Integer< 4>; -using i05 = nall::Integer< 5>; -using i06 = nall::Integer< 6>; -using i07 = nall::Integer< 7>; -using i08 = nall::Integer< 8>; -using i09 = nall::Integer< 9>; using i10 = nall::Integer<10>; using i11 = nall::Integer<11>; using i12 = nall::Integer<12>; @@ -81,15 +74,6 @@ using n6 = nall::Natural< 6>; using n7 = nall::Natural< 7>; using n8 = nall::Natural< 8>; using n9 = nall::Natural< 9>; -using n01 = nall::Natural< 1>; -using n02 = nall::Natural< 2>; -using n03 = nall::Natural< 3>; -using n04 = nall::Natural< 4>; -using n05 = nall::Natural< 5>; -using n06 = nall::Natural< 6>; -using n07 = nall::Natural< 7>; -using n08 = nall::Natural< 8>; -using n09 = nall::Natural< 9>; using n10 = nall::Natural<10>; using n11 = nall::Natural<11>; using n12 = nall::Natural<12>; @@ -148,135 +132,3 @@ using n64 = nall::Natural<64>; using r32 = nall::Real<32>; using r64 = nall::Real<64>; - -//deprecated long-form variants: - -using int1 = nall::Integer< 1>; -using int2 = nall::Integer< 2>; -using int3 = nall::Integer< 3>; -using int4 = nall::Integer< 4>; -using int5 = nall::Integer< 5>; -using int6 = nall::Integer< 6>; -using int7 = nall::Integer< 7>; -using int8 = nall::Integer< 8>; -using int9 = nall::Integer< 9>; -using int10 = nall::Integer<10>; -using int11 = nall::Integer<11>; -using int12 = nall::Integer<12>; -using int13 = nall::Integer<13>; -using int14 = nall::Integer<14>; -using int15 = nall::Integer<15>; -using int16 = nall::Integer<16>; -using int17 = nall::Integer<17>; -using int18 = nall::Integer<18>; -using int19 = nall::Integer<19>; -using int20 = nall::Integer<20>; -using int21 = nall::Integer<21>; -using int22 = nall::Integer<22>; -using int23 = nall::Integer<23>; -using int24 = nall::Integer<24>; -using int25 = nall::Integer<25>; -using int26 = nall::Integer<26>; -using int27 = nall::Integer<27>; -using int28 = nall::Integer<28>; -using int29 = nall::Integer<29>; -using int30 = nall::Integer<30>; -using int31 = nall::Integer<31>; -using int32 = nall::Integer<32>; -using int33 = nall::Integer<33>; -using int34 = nall::Integer<34>; -using int35 = nall::Integer<35>; -using int36 = nall::Integer<36>; -using int37 = nall::Integer<37>; -using int38 = nall::Integer<38>; -using int39 = nall::Integer<39>; -using int40 = nall::Integer<40>; -using int41 = nall::Integer<41>; -using int42 = nall::Integer<42>; -using int43 = nall::Integer<43>; -using int44 = nall::Integer<44>; -using int45 = nall::Integer<45>; -using int46 = nall::Integer<46>; -using int47 = nall::Integer<47>; -using int48 = nall::Integer<48>; -using int49 = nall::Integer<49>; -using int50 = nall::Integer<50>; -using int51 = nall::Integer<51>; -using int52 = nall::Integer<52>; -using int53 = nall::Integer<53>; -using int54 = nall::Integer<54>; -using int55 = nall::Integer<55>; -using int56 = nall::Integer<56>; -using int57 = nall::Integer<57>; -using int58 = nall::Integer<58>; -using int59 = nall::Integer<59>; -using int60 = nall::Integer<60>; -using int61 = nall::Integer<61>; -using int62 = nall::Integer<62>; -using int63 = nall::Integer<63>; -using int64 = nall::Integer<64>; - -using uint1 = nall::Natural< 1>; -using uint2 = nall::Natural< 2>; -using uint3 = nall::Natural< 3>; -using uint4 = nall::Natural< 4>; -using uint5 = nall::Natural< 5>; -using uint6 = nall::Natural< 6>; -using uint7 = nall::Natural< 7>; -using uint8 = nall::Natural< 8>; -using uint9 = nall::Natural< 9>; -using uint10 = nall::Natural<10>; -using uint11 = nall::Natural<11>; -using uint12 = nall::Natural<12>; -using uint13 = nall::Natural<13>; -using uint14 = nall::Natural<14>; -using uint15 = nall::Natural<15>; -using uint16 = nall::Natural<16>; -using uint17 = nall::Natural<17>; -using uint18 = nall::Natural<18>; -using uint19 = nall::Natural<19>; -using uint20 = nall::Natural<20>; -using uint21 = nall::Natural<21>; -using uint22 = nall::Natural<22>; -using uint23 = nall::Natural<23>; -using uint24 = nall::Natural<24>; -using uint25 = nall::Natural<25>; -using uint26 = nall::Natural<26>; -using uint27 = nall::Natural<27>; -using uint28 = nall::Natural<28>; -using uint29 = nall::Natural<29>; -using uint30 = nall::Natural<30>; -using uint31 = nall::Natural<31>; -using uint32 = nall::Natural<32>; -using uint33 = nall::Natural<33>; -using uint34 = nall::Natural<34>; -using uint35 = nall::Natural<35>; -using uint36 = nall::Natural<36>; -using uint37 = nall::Natural<37>; -using uint38 = nall::Natural<38>; -using uint39 = nall::Natural<39>; -using uint40 = nall::Natural<40>; -using uint41 = nall::Natural<41>; -using uint42 = nall::Natural<42>; -using uint43 = nall::Natural<43>; -using uint44 = nall::Natural<44>; -using uint45 = nall::Natural<45>; -using uint46 = nall::Natural<46>; -using uint47 = nall::Natural<47>; -using uint48 = nall::Natural<48>; -using uint49 = nall::Natural<49>; -using uint50 = nall::Natural<50>; -using uint51 = nall::Natural<51>; -using uint52 = nall::Natural<52>; -using uint53 = nall::Natural<53>; -using uint54 = nall::Natural<54>; -using uint55 = nall::Natural<55>; -using uint56 = nall::Natural<56>; -using uint57 = nall::Natural<57>; -using uint58 = nall::Natural<58>; -using uint59 = nall::Natural<59>; -using uint60 = nall::Natural<60>; -using uint61 = nall::Natural<61>; -using uint62 = nall::Natural<62>; -using uint63 = nall::Natural<63>; -using uint64 = nall::Natural<64>; diff --git a/ares/component/audio/ay38910/ay38910.cpp b/ares/component/audio/ay38910/ay38910.cpp index a805be4163..2eaa201ce9 100644 --- a/ares/component/audio/ay38910/ay38910.cpp +++ b/ares/component/audio/ay38910/ay38910.cpp @@ -5,14 +5,14 @@ namespace ares { #include "serialization.cpp" -auto AY38910::clock() -> array { +auto AY38910::clock() -> array { toneA.clock(); toneB.clock(); toneC.clock(); noise.clock(); envelope.clock(); - array output; + array output; if((toneA.output | channelA.tone) & (noise.output | channelA.noise)) { output[0] = channelA.envelope ? envelope.output : channelA.volume; } @@ -65,8 +65,8 @@ auto AY38910::Envelope::clock() -> void { } } -auto AY38910::read() -> uint8 { - uint8 data; +auto AY38910::read() -> n8 { + n8 data; switch(io.register) { case 0: @@ -135,7 +135,7 @@ auto AY38910::read() -> uint8 { return data; } -auto AY38910::write(uint8 data) -> void { +auto AY38910::write(n8 data) -> void { switch(io.register) { case 0: toneA.period.bit(0, 7) = data.bit(0,7); @@ -204,7 +204,7 @@ auto AY38910::write(uint8 data) -> void { } } -auto AY38910::select(uint4 data) -> void { +auto AY38910::select(n4 data) -> void { io.register = data; } diff --git a/ares/component/audio/ay38910/ay38910.hpp b/ares/component/audio/ay38910/ay38910.hpp index 38fc2112a0..eadac2a635 100644 --- a/ares/component/audio/ay38910/ay38910.hpp +++ b/ares/component/audio/ay38910/ay38910.hpp @@ -5,14 +5,14 @@ namespace ares { //General Instrument AY-3-8910 struct AY38910 { - virtual auto readIO(uint1 port) -> uint8 { return 0xff; } - virtual auto writeIO(uint1 port, uint8 data) -> void {} + virtual auto readIO(n1 port) -> n8 { return 0xff; } + virtual auto writeIO(n1 port, n8 data) -> void {} //ay38910.cpp - auto clock() -> array; - auto read() -> uint8; - auto write(uint8 data) -> void; - auto select(uint4 data) -> void; + auto clock() -> array; + auto read() -> n8; + auto write(n8 data) -> void; + auto select(n4 data) -> void; auto power() -> void; //serialization.cpp @@ -23,51 +23,51 @@ struct AY38910 { //ay38910.cpp auto clock() -> void; - uint12 counter; - uint12 period; - uint1 output; + n12 counter; + n12 period; + n1 output; }; struct Noise { //ay38910.cpp auto clock() -> void; - uint5 counter; - uint5 period; - uint1 flip; - uint17 lfsr = 1; - uint1 output; + n5 counter; + n5 period; + n1 flip; + n17 lfsr = 1; + n1 output; }; struct Envelope { //ay38910.cpp auto clock() -> void; - uint16 counter; - uint16 period; - uint1 holding; - uint1 attacking; - uint1 hold; - uint1 alternate; - uint1 attack; - uint1 repeat; //continue - uint4 output; + n16 counter; + n16 period; + n1 holding; + n1 attacking; + n1 hold; + n1 alternate; + n1 attack; + n1 repeat; //continue + n4 output; }; struct Channel { - uint1 tone; //0 = enable, 1 = disable - uint1 noise; //0 = enable, 1 = disable - uint1 envelope; //0 = use fixed volume, 1 = use envelope phase - uint4 volume; + n1 tone; //0 = enable, 1 = disable + n1 noise; //0 = enable, 1 = disable + n1 envelope; //0 = use fixed volume, 1 = use envelope phase + n4 volume; }; struct Port { - uint1 direction; //0 = input, 1 = output - uint8 data; + n1 direction; //0 = input, 1 = output + n8 data; }; struct IO { - uint4 register; + n4 register; }; Tone toneA; diff --git a/ares/component/audio/msm5205/msm5205.cpp b/ares/component/audio/msm5205/msm5205.cpp index fb0654e123..9da428f005 100644 --- a/ares/component/audio/msm5205/msm5205.cpp +++ b/ares/component/audio/msm5205/msm5205.cpp @@ -5,36 +5,36 @@ namespace ares { #include "serialization.cpp" -auto MSM5205::sample() const -> int12 { +auto MSM5205::sample() const -> i12 { //note: technically this should return io.sample & ~3; //the DAC output is only 10-bits return io.sample; } -auto MSM5205::scaler() const -> uint { +auto MSM5205::scaler() const -> u32 { //0 = 4khz (384khz / 96); 8khz (768khz / 96) //1 = 6khz (384khz / 64); 12khz (768khz / 64) //2 = 8khz (384khz / 48); 16khz (768khz / 48) //3 = prohibited (unknown behavior: treat as 8khz) - static const uint scaler[4] = {96, 64, 48, 48}; + static const u32 scaler[4] = {96, 64, 48, 48}; return scaler[io.scaler]; } -auto MSM5205::setReset(uint1 reset) -> void { +auto MSM5205::setReset(n1 reset) -> void { io.reset = reset; } -auto MSM5205::setWidth(uint1 width) -> void { +auto MSM5205::setWidth(n1 width) -> void { io.width = width; } -auto MSM5205::setScaler(uint2 scaler) -> void { +auto MSM5205::setScaler(n2 scaler) -> void { io.scaler = scaler; } -auto MSM5205::setData(uint4 data) -> void { - if(io.width == 0) io.data = (uint3)data << 1; - if(io.width == 1) io.data = (uint4)data << 0; +auto MSM5205::setData(n4 data) -> void { + if(io.width == 0) io.data = (n3)data << 1; + if(io.width == 1) io.data = (n4)data << 0; } auto MSM5205::clock() -> void { @@ -44,13 +44,13 @@ auto MSM5205::clock() -> void { return; } - int sample = io.sample + lookup[io.step * 16 + io.data]; + s32 sample = io.sample + lookup[io.step * 16 + io.data]; if(sample > 2047) sample = 2047; if(sample < -2048) sample = -2048; io.sample = sample; - static const int shift[8] = {-1, -1, -1, -1, 2, 4, 6, 8}; - io.step += shift[(uint3)io.data]; + static const s32 shift[8] = {-1, -1, -1, -1, 2, 4, 6, 8}; + io.step += shift[(n3)io.data]; if(io.step > 48) io.step = 48; if(io.step < 0) io.step = 0; } @@ -58,21 +58,21 @@ auto MSM5205::clock() -> void { auto MSM5205::power() -> void { io = {}; - static const int map[16][4] = { + static const s32 map[16][4] = { { 1,0,0,0}, { 1,0,0,1}, { 1,0,1,0}, { 1,0,1,1}, { 1,1,0,0}, { 1,1,0,1}, { 1,1,1,0}, { 1,1,1,1}, {-1,0,0,0}, {-1,0,0,1}, {-1,0,1,0}, {-1,0,1,1}, {-1,1,0,0}, {-1,1,0,1}, {-1,1,1,0}, {-1,1,1,1}, }; - for(int step : range(49)) { - int scale = floor(16.0 * pow(11.0 / 10.0, (double)step)); - for(int nibble : range(16)) { - int a = map[nibble][0]; - int b = map[nibble][1] * scale / 1; - int c = map[nibble][2] * scale / 2; - int d = map[nibble][3] * scale / 4; - int e = scale / 8; + for(s32 step : range(49)) { + s32 scale = floor(16.0 * pow(11.0 / 10.0, (f64)step)); + for(s32 nibble : range(16)) { + s32 a = map[nibble][0]; + s32 b = map[nibble][1] * scale / 1; + s32 c = map[nibble][2] * scale / 2; + s32 d = map[nibble][3] * scale / 4; + s32 e = scale / 8; lookup[step * 16 + nibble] = a * (b + c + d + e); } } diff --git a/ares/component/audio/msm5205/msm5205.hpp b/ares/component/audio/msm5205/msm5205.hpp index f501ce5635..536d5656c3 100644 --- a/ares/component/audio/msm5205/msm5205.hpp +++ b/ares/component/audio/msm5205/msm5205.hpp @@ -6,13 +6,13 @@ namespace ares { struct MSM5205 { //msm5205.cpp - auto sample() const -> int12; - auto scaler() const -> uint; + auto sample() const -> i12; + auto scaler() const -> u32; - auto setReset(uint1 reset) -> void; - auto setWidth(uint1 width) -> void; - auto setScaler(uint2 frequency) -> void; - auto setData(uint4 data) -> void; + auto setReset(n1 reset) -> void; + auto setWidth(n1 width) -> void; + auto setScaler(n2 frequency) -> void; + auto setData(n4 data) -> void; auto clock() -> void; auto power() -> void; @@ -21,16 +21,16 @@ struct MSM5205 { auto serialize(serializer&) -> void; struct IO { - uint1 reset; //RESET - uint1 width; //4B - uint2 scaler; //S0-S1 - uint4 data; //D0-D7 - int12 sample; //DAOUT - int8 step; + n1 reset; //RESET + n1 width; //4B + n2 scaler; //S0-S1 + n4 data; //D0-D7 + i12 sample; //DAOUT + i8 step; } io; //unserialized: - int lookup[49 * 16]; + s32 lookup[49 * 16]; }; } diff --git a/ares/component/audio/sn76489/sn76489.cpp b/ares/component/audio/sn76489/sn76489.cpp index 5ec4590341..d761283252 100644 --- a/ares/component/audio/sn76489/sn76489.cpp +++ b/ares/component/audio/sn76489/sn76489.cpp @@ -5,13 +5,13 @@ namespace ares { #include "serialization.cpp" -auto SN76489::clock() -> array { +auto SN76489::clock() -> array { tone0.clock(); tone1.clock(); tone2.clock(); noise.clock(); - array output{15, 15, 15, 15}; + array output{15, 15, 15, 15}; if(tone0.output) output[0] = tone0.volume; if(tone1.output) output[1] = tone1.volume; if(tone2.output) output[2] = tone2.volume; @@ -28,7 +28,7 @@ auto SN76489::Tone::clock() -> void { auto SN76489::Noise::clock() -> void { if(!counter--) { - counter = array{0x10, 0x20, 0x40, pitch}[rate]; + counter = array{0x10, 0x20, 0x40, pitch}[rate]; if(flip ^= 1) { //0->1 transition output = !lfsr.bit(0); lfsr = (lfsr.bit(0) ^ lfsr.bit(3) & enable) << 15 | lfsr >> 1; @@ -36,7 +36,7 @@ auto SN76489::Noise::clock() -> void { } } -auto SN76489::write(uint8 data) -> void { +auto SN76489::write(n8 data) -> void { if(data.bit(7)) io.register = data.bit(4,6); if(io.register.bit(0)) switch(io.register.bit(1,2)) { diff --git a/ares/component/audio/sn76489/sn76489.hpp b/ares/component/audio/sn76489/sn76489.hpp index 496eaa7fa6..9ef28f3860 100644 --- a/ares/component/audio/sn76489/sn76489.hpp +++ b/ares/component/audio/sn76489/sn76489.hpp @@ -6,8 +6,8 @@ namespace ares { struct SN76489 { //sn76489.cpp - auto clock() -> array; - auto write(uint8 data) -> void; + auto clock() -> array; + auto write(n8 data) -> void; auto power() -> void; //serialization.cpp @@ -21,10 +21,10 @@ struct SN76489 { //serialization.cpp auto serialize(serializer&) -> void; - uint4 volume = 15; - uint10 counter; - uint10 pitch; - uint1 output; + n4 volume = 15; + n10 counter; + n10 pitch; + n1 output; }; struct Noise { @@ -34,18 +34,18 @@ struct SN76489 { //serialization.cpp auto serialize(serializer&) -> void; - uint4 volume = 15; - uint10 counter; - uint10 pitch; - uint1 enable; - uint2 rate; - uint16 lfsr = 0x8000; - uint1 flip; - uint1 output; + n4 volume = 15; + n10 counter; + n10 pitch; + n1 enable; + n2 rate; + n16 lfsr = 0x8000; + n1 flip; + n1 output; }; struct IO { - uint3 register; + n3 register; }; Tone tone0; diff --git a/ares/component/audio/t6w28/t6w28.cpp b/ares/component/audio/t6w28/t6w28.cpp index 5be093a861..63550b2b61 100644 --- a/ares/component/audio/t6w28/t6w28.cpp +++ b/ares/component/audio/t6w28/t6w28.cpp @@ -5,13 +5,13 @@ namespace ares { #include "serialization.cpp" -auto T6W28::clock() -> array { +auto T6W28::clock() -> array { tone0.clock(); tone1.clock(); tone2.clock(); noise.clock(); - array output{15, 15, 15, 15, 15, 15, 15, 15}; + array output{15, 15, 15, 15, 15, 15, 15, 15}; if(tone0.output) output[0] = tone0.volume.left, output[4] = tone0.volume.right; if(tone1.output) output[1] = tone1.volume.left, output[5] = tone1.volume.right; if(tone2.output) output[2] = tone2.volume.left, output[6] = tone2.volume.right; @@ -28,7 +28,7 @@ auto T6W28::Tone::clock() -> void { auto T6W28::Noise::clock() -> void { if(!counter--) { - counter = array{0x10, 0x20, 0x40, pitch}[rate]; + counter = array{0x10, 0x20, 0x40, pitch}[rate]; if(flip ^= 1) { output = !lfsr.bit(0); lfsr = (lfsr.bit(0) ^ lfsr.bit(2) & enable) << 14 | lfsr >> 1; @@ -36,7 +36,7 @@ auto T6W28::Noise::clock() -> void { } } -auto T6W28::writeLeft(uint8 data) -> void { +auto T6W28::writeLeft(n8 data) -> void { if(data.bit(7)) io.register = data.bit(4,6); if(io.register.bit(0)) switch(io.register.bit(1,2)) { @@ -59,7 +59,7 @@ auto T6W28::writeLeft(uint8 data) -> void { } } -auto T6W28::writeRight(uint8 data) -> void { +auto T6W28::writeRight(n8 data) -> void { if(data.bit(7)) io.register = data.bit(4,6); if(io.register.bit(0)) switch(io.register.bit(1,2)) { diff --git a/ares/component/audio/t6w28/t6w28.hpp b/ares/component/audio/t6w28/t6w28.hpp index 371ccd1003..764e892296 100644 --- a/ares/component/audio/t6w28/t6w28.hpp +++ b/ares/component/audio/t6w28/t6w28.hpp @@ -6,9 +6,9 @@ namespace ares { struct T6W28 { //t6w28.cpp - auto clock() -> array; - auto writeLeft(uint8 data) -> void; - auto writeRight(uint8 data) -> void; + auto clock() -> array; + auto writeLeft(n8 data) -> void; + auto writeRight(n8 data) -> void; auto power() -> void; //serialization.cpp @@ -22,12 +22,12 @@ struct T6W28 { //serialization.cpp auto serialize(serializer&) -> void; - uint10 counter; - uint10 pitch; - uint1 output; + n10 counter; + n10 pitch; + n1 output; struct Volume { - uint4 left = 15; - uint4 right = 15; + n4 left = 15; + n4 right = 15; } volume; }; @@ -38,21 +38,21 @@ struct T6W28 { //serialization.cpp auto serialize(serializer&) -> void; - uint10 counter; - uint10 pitch; - uint1 enable; - uint2 rate; - uint15 lfsr = 0x4000; - uint1 flip; - uint1 output; + n10 counter; + n10 pitch; + n1 enable; + n2 rate; + n15 lfsr = 0x4000; + n1 flip; + n1 output; struct Volume { - uint4 left = 15; - uint4 right = 15; + n4 left = 15; + n4 right = 15; } volume; }; struct IO { - uint3 register; + n3 register; }; Tone tone0; diff --git a/ares/component/audio/ym2149/ym2149.cpp b/ares/component/audio/ym2149/ym2149.cpp index a47bc2aec8..bfbd4254b2 100644 --- a/ares/component/audio/ym2149/ym2149.cpp +++ b/ares/component/audio/ym2149/ym2149.cpp @@ -5,22 +5,22 @@ namespace ares { #include "serialization.cpp" -auto YM2149::clock() -> array { +auto YM2149::clock() -> array { toneA.clock(); toneB.clock(); toneC.clock(); noise.clock(); envelope.clock(); - array output; + array output; if((toneA.output | channelA.tone) & (noise.output | channelA.noise)) { - output[0] = channelA.envelope ? envelope.output : uint5(channelA.volume << 1 | 1); + output[0] = channelA.envelope ? envelope.output : n5(channelA.volume << 1 | 1); } if((toneB.output | channelB.tone) & (noise.output | channelB.noise)) { - output[1] = channelB.envelope ? envelope.output : uint5(channelB.volume << 1 | 1); + output[1] = channelB.envelope ? envelope.output : n5(channelB.volume << 1 | 1); } if((toneC.output | channelC.tone) & (noise.output | channelC.noise)) { - output[2] = channelC.envelope ? envelope.output : uint5(channelC.volume << 1 | 1); + output[2] = channelC.envelope ? envelope.output : n5(channelC.volume << 1 | 1); } return output; } @@ -67,8 +67,8 @@ auto YM2149::Envelope::clock() -> void { } } -auto YM2149::read() -> uint8 { - uint8 data; +auto YM2149::read() -> n8 { + n8 data; switch(io.register) { case 0: @@ -145,7 +145,7 @@ auto YM2149::read() -> uint8 { return data; } -auto YM2149::write(uint8 data) -> void { +auto YM2149::write(n8 data) -> void { switch(io.register) { case 0: toneA.period.bit(0, 7) = data.bit(0,7); @@ -222,7 +222,7 @@ auto YM2149::write(uint8 data) -> void { } } -auto YM2149::select(uint4 data) -> void { +auto YM2149::select(n4 data) -> void { io.register = data; } diff --git a/ares/component/audio/ym2149/ym2149.hpp b/ares/component/audio/ym2149/ym2149.hpp index adf61fb8dc..e59c2d2dfd 100644 --- a/ares/component/audio/ym2149/ym2149.hpp +++ b/ares/component/audio/ym2149/ym2149.hpp @@ -6,10 +6,10 @@ namespace ares { struct YM2149 { //ym2149.cpp - auto clock() -> array; - auto read() -> uint8; - auto write(uint8 data) -> void; - auto select(uint4 data) -> void; + auto clock() -> array; + auto read() -> n8; + auto write(n8 data) -> void; + auto select(n4 data) -> void; auto power() -> void; //serialization.cpp @@ -20,55 +20,55 @@ struct YM2149 { //ym2149.cpp auto clock() -> void; - uint12 counter; - uint12 period; - uint4 unused; - uint1 output; + n12 counter; + n12 period; + n4 unused; + n1 output; }; struct Noise { //ym2149.cpp auto clock() -> void; - uint5 counter; - uint5 period; - uint3 unused; - uint1 flip; - uint17 lfsr = 1; - uint1 output; + n5 counter; + n5 period; + n3 unused; + n1 flip; + n17 lfsr = 1; + n1 output; }; struct Envelope { //ym2149.cpp auto clock() -> void; - uint16 counter; - uint16 period; - uint1 holding; - uint1 attacking; - uint1 hold; - uint1 alternate; - uint1 attack; - uint1 repeat; //continue - uint4 unused; - uint5 output; + n16 counter; + n16 period; + n1 holding; + n1 attacking; + n1 hold; + n1 alternate; + n1 attack; + n1 repeat; //continue + n4 unused; + n5 output; }; struct Channel { - uint1 tone; //0 = enable, 1 = disable - uint1 noise; //0 = enable, 1 = disable - uint1 envelope; //0 = use fixed volume, 1 = use envelope volume - uint4 volume; - uint3 unused; + n1 tone; //0 = enable, 1 = disable + n1 noise; //0 = enable, 1 = disable + n1 envelope; //0 = use fixed volume, 1 = use envelope volume + n4 volume; + n3 unused; }; struct Port { - uint1 direction; //0 = input, 1 = output - uint8 data; + n1 direction; //0 = input, 1 = output + n8 data; }; struct IO { - uint4 register; + n4 register; }; Tone toneA; diff --git a/ares/component/audio/ym2413/constants.cpp b/ares/component/audio/ym2413/constants.cpp index 74c07e4952..8e0c2fa6ac 100644 --- a/ares/component/audio/ym2413/constants.cpp +++ b/ares/component/audio/ym2413/constants.cpp @@ -1,10 +1,10 @@ -const int8 YM2413::levelScaling[16] = { +const i8 YM2413::levelScaling[16] = { //-6 dB/octave, -6 dB/8 units //input: fnumber.bits(5,8) 0, 24, 32, 37, 40, 43, 45, 47, 48, 50, 51, 52, 53, 54, 55, 56, }; -const uint64 YM2413::envelopeSteps[17][2] = { +const n64 YM2413::envelopeSteps[17][2] = { //{attack sequence, decay sequence }, {0x0101010101010101, 0x0101010101010101}, // 4..44 {0x0101110101011101, 0x0101110101011101}, // 5..45 @@ -27,7 +27,7 @@ const uint64 YM2413::envelopeSteps[17][2] = { /* these are approximations and are not hardware accurate */ -const uint8 YM2413::melodicTonesOPLL[15][8] = { +const n8 YM2413::melodicTonesOPLL[15][8] = { {0x61, 0x61, 0x1e, 0x17, 0xf0, 0x78, 0x00, 0x17}, {0x13, 0x41, 0x1e, 0x0d, 0xd7, 0xf7, 0x13, 0x13}, {0x13, 0x01, 0x99, 0x04, 0xf2, 0xf4, 0x11, 0x23}, @@ -45,7 +45,7 @@ const uint8 YM2413::melodicTonesOPLL[15][8] = { {0x61, 0x41, 0x89, 0x03, 0xf1, 0xf4, 0xf0, 0x13}, }; -const uint8 YM2413::rhythmTonesOPLL[3][8] = { +const n8 YM2413::rhythmTonesOPLL[3][8] = { {0x01, 0x01, 0x16, 0x00, 0xfd, 0xf8, 0x2f, 0x6d}, {0x01, 0x01, 0x00, 0x00, 0xd8, 0xd8, 0xf9, 0xf8}, {0x05, 0x01, 0x00, 0x00, 0xf8, 0xba, 0x49, 0x55}, @@ -53,7 +53,7 @@ const uint8 YM2413::rhythmTonesOPLL[3][8] = { /* these tables were extracted from the VRC7 debug mode: likely inaccurate for the YM2413 */ -const uint8 YM2413::melodicTonesVRC7[15][8] = { +const n8 YM2413::melodicTonesVRC7[15][8] = { {0x03, 0x21, 0x05, 0x06, 0xe8, 0x81, 0x42, 0x27}, //1: violin {0x13, 0x41, 0x14, 0x0d, 0xd8, 0xf6, 0x23, 0x12}, //2: guitar {0x11, 0x11, 0x08, 0x08, 0xfa, 0xb2, 0x20, 0x12}, //3: piano @@ -71,11 +71,11 @@ const uint8 YM2413::melodicTonesVRC7[15][8] = { {0x21, 0x72, 0x0d, 0x00, 0xc1, 0xd5, 0x56, 0x06}, //f: electric guitar }; -const uint8 YM2413::rhythmTonesVRC7[3][8] = { +const n8 YM2413::rhythmTonesVRC7[3][8] = { {0x01, 0x01, 0x18, 0x0f, 0xdf, 0xf8, 0x6a, 0x6d}, //7, 13/16: bass drum {0x01, 0x01, 0x00, 0x00, 0xc8, 0xd8, 0xa7, 0x68}, //8, 14/17: hihat, snare drum {0x05, 0x01, 0x00, 0x00, 0xf8, 0xaa, 0x59, 0x55}, //9, 15/18: tomtom, top cymbal }; -uint13 YM2413::sinTable[1 << 10]; - int12 YM2413::expTable[1 << 9]; +n13 YM2413::sinTable[1 << 10]; +i12 YM2413::expTable[1 << 9]; diff --git a/ares/component/audio/ym2413/io.cpp b/ares/component/audio/ym2413/io.cpp index ec2baa09ca..e81da6a38b 100644 --- a/ares/component/audio/ym2413/io.cpp +++ b/ares/component/audio/ym2413/io.cpp @@ -1,14 +1,14 @@ -auto YM2413::address(uint8 data) -> void { +auto YM2413::address(n8 data) -> void { io.address = data; } -auto YM2413::write(uint8 data) -> void { - uint4 index = io.address.bit(0,3) % 9; +auto YM2413::write(n8 data) -> void { + n4 index = io.address.bit(0,3) % 9; auto& voice = voices[index]; if(io.address >= 0x00 && io.address <= 0x07) { customTone[io.address] = data; - for(uint n : range(9)) { + for(u32 n : range(9)) { if(voices[n].tone == 0) reload(n); } return; @@ -18,7 +18,7 @@ auto YM2413::write(uint8 data) -> void { if(io.isVRC7) return; if(io.rhythmMode != data.bit(5)) { io.rhythmMode = data.bit(5); - for(uint n : range(9)) reload(n); + for(u32 n : range(9)) reload(n); } if(io.rhythmMode) { hihat.trigger(data.bit(0)); @@ -46,8 +46,8 @@ auto YM2413::write(uint8 data) -> void { if(io.isVRC7 && index >= 6) return; voice.fnumber.bit(8) = data.bit(0); voice.block = data.bit(1,3); - uint1 keyOn = data.bit(4); - uint1 sustainOn = data.bit(5); + n1 keyOn = data.bit(4); + n1 sustainOn = data.bit(5); voice.update(); voice.carrier.trigger(keyOn, sustainOn); return; diff --git a/ares/component/audio/ym2413/operator.cpp b/ares/component/audio/ym2413/operator.cpp index 4a129b997b..d7ad114c06 100644 --- a/ares/component/audio/ym2413/operator.cpp +++ b/ares/component/audio/ym2413/operator.cpp @@ -1,15 +1,15 @@ -auto YM2413::Operator::releaseRate() const -> uint4 { +auto YM2413::Operator::releaseRate() const -> n4 { if(state == Trigger) return 13; if(state == Attack) return attack; if(state == Decay) return decay; - if(state == Sustain) return sustainable ? (uint4)0 : release; + if(state == Sustain) return sustainable ? (n4)0 : release; // state == Release if(!audible) return 0; //should never happen if(sustainOn) return 5; //carrier only - return sustainable ? release : (uint4)7; + return sustainable ? release : (n4)7; } -auto YM2413::Operator::update(maybe updateState) -> void { +auto YM2413::Operator::update(maybe updateState) -> void { if(updateState) state = updateState(); auto baseRate = releaseRate(); @@ -29,12 +29,12 @@ auto YM2413::Operator::update(maybe updateState) -> void { m += (m == 14) - (m == 13 || m == 11); //unimplemented; maps to 15, 12, or 10 m = max(1, 2 * m); //0 => 1/2, which truncates fnumber bit 0 - for(uint n : range(8)) { + for(u32 n : range(8)) { pitch[n] = (fnumber + lfo[n]) * m / 2 << block; } } -auto YM2413::Operator::synchronize(uint1 hard, maybe modulator) -> void { +auto YM2413::Operator::synchronize(n1 hard, maybe modulator) -> void { if(state == Trigger && envelope.bit(2,6) == 31) { update(Attack); if(rate >= 60) update(Decay), envelope = 0; @@ -51,15 +51,15 @@ auto YM2413::Operator::synchronize(uint1 hard, maybe modulator) -> vo } //only carriers (never modulators) call trigger() -auto YM2413::Operator::trigger(uint1 key, uint1 sustain) -> void { +auto YM2413::Operator::trigger(n1 key, n1 sustain) -> void { sustainOn = sustain; if(keyOn == key) return; keyOn = key; update(keyOn ? Trigger : Release); } -auto YM2413::Operator::clock(natural clock, integer offset, integer modulation) -> int12 { - uint14 y = YM2413::sinTable[uint10(offset + modulation)]; +auto YM2413::Operator::clock(natural clock, integer offset, integer modulation) -> i12 { + n14 y = YM2413::sinTable[n10(offset + modulation)]; if(waveform & ~y.bit(0)) y = sinTable[0]; auto w = clock / 64 % 210 * tremolo; auto lfo = (w < 105 ? w : 210 - w) >> 3; @@ -71,8 +71,8 @@ auto YM2413::Operator::clock(natural clock, integer offset, integer modulation) phase += pitch[clock / 1024 % 8 * vibrato]; auto lsbs = divider ? clock.bit(0, divider - 1) : 0; if(rate && (state == Attack ? lsbs & -4 : lsbs) == 0) { - natural msbs = uint4(clock >> divider); - integer step = uint4(sequence << 4 * msbs >> 60); + natural msbs = n4(clock >> divider); + integer step = n4(sequence << 4 * msbs >> 60); if(state == Attack) step = ~envelope * step >> 4; envelope = max(0x00, min(0x7f, envelope + step)); } diff --git a/ares/component/audio/ym2413/voice.cpp b/ares/component/audio/ym2413/voice.cpp index 1b0a283e9e..df7a325211 100644 --- a/ares/component/audio/ym2413/voice.cpp +++ b/ares/component/audio/ym2413/voice.cpp @@ -1,4 +1,4 @@ -auto YM2413::Voice::update(const uint8* data) -> void { +auto YM2413::Voice::update(const n8* data) -> void { if(data) { modulator.multiple = data[0].bit(0,3); modulator.scaleRate = data[0].bit(4); diff --git a/ares/component/audio/ym2413/ym2413.cpp b/ares/component/audio/ym2413/ym2413.cpp index 081d4097d4..b269294204 100644 --- a/ares/component/audio/ym2413/ym2413.cpp +++ b/ares/component/audio/ym2413/ym2413.cpp @@ -9,12 +9,12 @@ namespace ares { #include "io.cpp" #include "serialization.cpp" -auto YM2413::clock() -> double { +auto YM2413::clock() -> f64 { auto melody = 0; auto rhythm = 0; auto mask = -(1 << 12 - 9); - for(uint index : range(io.rhythmMode ? 6 : 9)) { + for(u32 index : range(io.rhythmMode ? 6 : 9)) { auto& voice = voices[index]; auto input = voice.modulator.output + voice.modulator.prior >> 8 - voice.feedback; voice.modulator.clock(io.clock, voice.modulator.phase >> 9, voice.feedback ? input : 0); @@ -50,7 +50,7 @@ auto YM2413::clock() -> double { return mix / 32768.0 * 4.0; } -auto YM2413::reload(uint4 index) -> void { +auto YM2413::reload(n4 index) -> void { auto& voice = voices[index]; voice.modulator.audible = io.rhythmMode && index > 6; voice.carrier.audible = true; @@ -74,23 +74,23 @@ auto YM2413::power(bool isVRC7) -> void { //10.9 fixed point phases auto y = sin((2 * x + 1) * Math::Pi / 1024.0); //0x400 units to 2pi radians auto z = -(1 << 8) * log(y) / log(2); //convert to -6 dB/256 units - auto s = (1 << 10) * pow(2, uint8(~x) / 256.0); //0x7fa .. 0x400 + auto s = (1 << 10) * pow(2, n8(~x) / 256.0); //0x7fa .. 0x400 - sinTable[0x000 + x] = sinTable[0x1ff - x] = uint(z + 0.5) * 2 + 1; - sinTable[0x200 + x] = sinTable[0x3ff - x] = uint(z + 0.5) * 2 + 0; + sinTable[0x000 + x] = sinTable[0x1ff - x] = u32(z + 0.5) * 2 + 1; + sinTable[0x200 + x] = sinTable[0x3ff - x] = u32(z + 0.5) * 2 + 0; - expTable[x * 2 + 1] = +uint(s + 0.5); - expTable[x * 2 + 0] = ~uint(s + 0.5); + expTable[x * 2 + 1] = +u32(s + 0.5); + expTable[x * 2 + 0] = ~u32(s + 0.5); } io = {}; io.isVRC7 = isVRC7; - for(uint n : range(9)) { + for(u32 n : range(9)) { voices[n] = {}; reload(n); } - for(uint n : range(3)) { + for(u32 n : range(3)) { voices[3 * n + 0].modulator.slot = 1 + 6 * n; voices[3 * n + 1].modulator.slot = 2 + 6 * n; voices[3 * n + 2].modulator.slot = 3 + 6 * n; diff --git a/ares/component/audio/ym2413/ym2413.hpp b/ares/component/audio/ym2413/ym2413.hpp index e2cab6ed4c..54e130f74d 100644 --- a/ares/component/audio/ym2413/ym2413.hpp +++ b/ares/component/audio/ym2413/ym2413.hpp @@ -7,102 +7,102 @@ namespace ares { struct YM2413 { //ym2413.cpp - auto clock() -> double; - auto reload(uint4 voice) -> void; + auto clock() -> f64; + auto reload(n4 voice) -> void; auto power(bool isVRC7 = false) -> void; //io.cpp - auto address(uint8 data) -> void; - auto write(uint8 data) -> void; + auto address(n8 data) -> void; + auto write(n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; protected: - static const int8 levelScaling[16]; - static const uint64 envelopeSteps[17][2]; - static const uint8 melodicTonesOPLL[15][8]; - static const uint8 rhythmTonesOPLL[3][8]; - static const uint8 melodicTonesVRC7[15][8]; - static const uint8 rhythmTonesVRC7[3][8]; - static uint13 sinTable[1 << 10]; - static int12 expTable[1 << 9]; - uint8 melodicTones[15][8]; - uint8 rhythmTones[3][8]; - uint8 customTone[8]; - - enum : uint { Trigger, Attack, Decay, Sustain, Release }; + static const i8 levelScaling[16]; + static const n64 envelopeSteps[17][2]; + static const n8 melodicTonesOPLL[15][8]; + static const n8 rhythmTonesOPLL[3][8]; + static const n8 melodicTonesVRC7[15][8]; + static const n8 rhythmTonesVRC7[3][8]; + static n13 sinTable[1 << 10]; + static i12 expTable[1 << 9]; + n8 melodicTones[15][8]; + n8 rhythmTones[3][8]; + n8 customTone[8]; + + enum : u32 { Trigger, Attack, Decay, Sustain, Release }; struct Operator { //operator.cpp - auto releaseRate() const -> uint4; - auto update(maybe state = {}) -> void; - auto synchronize(uint1 hard, maybe modulator = {}) -> void; - auto trigger(uint1 key, uint1 sustain = 0) -> void; - auto clock(natural clock, integer offset, integer modulation = 0) -> int12; + auto releaseRate() const -> n4; + auto update(maybe state = {}) -> void; + auto synchronize(n1 hard, maybe modulator = {}) -> void; + auto trigger(n1 key, n1 sustain = 0) -> void; + auto clock(natural clock, integer offset, integer modulation = 0) -> i12; //serialization.cpp auto serialize(serializer&) -> void; - uint5 slot; //1-18 - uint1 keyOn; - uint1 sustainOn; - uint4 multiple; - uint1 scaleRate; - uint1 sustainable; - uint1 vibrato; - uint1 tremolo; - uint2 scaleLevel; - uint1 waveform; - uint4 attack; - uint4 decay; - uint4 sustain; - uint4 release; - uint6 totalLevel; - uint1 audible; + n5 slot; //1-18 + n1 keyOn; + n1 sustainOn; + n4 multiple; + n1 scaleRate; + n1 sustainable; + n1 vibrato; + n1 tremolo; + n2 scaleLevel; + n1 waveform; + n4 attack; + n4 decay; + n4 sustain; + n4 release; + n6 totalLevel; + n1 audible; //envelope generator - uint3 state = Release; - uint7 rate; - uint4 divider; - uint64 sequence; - uint7 envelope = 0x7f; - uint7 level; + n3 state = Release; + n7 rate; + n4 divider; + n64 sequence; + n7 envelope = 0x7f; + n7 level; //phase generator - uint9 fnumber; - uint3 block; - uint19 pitch[8]; - uint19 phase; + n9 fnumber; + n3 block; + n19 pitch[8]; + n19 phase; //output - int12 output; - int12 prior; + i12 output; + i12 prior; }; struct Voice { //voice.cpp - auto update(const uint8* data = nullptr) -> void; + auto update(const n8* data = nullptr) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint4 tone; - uint9 fnumber; - uint3 block; - uint4 level; - uint3 feedback; + n4 tone; + n9 fnumber; + n3 block; + n4 level; + n3 feedback; Operator modulator; Operator carrier; } voices[9]; struct IO { - uint32 clock; - uint8 address; - uint1 rhythmMode; - uint23 noise = 1; - uint1 isVRC7 = 0; + n32 clock; + n8 address; + n1 rhythmMode; + n23 noise = 1; + n1 isVRC7 = 0; } io; Voice& bass = voices[6]; diff --git a/ares/component/eeprom/m93lcx6/m93lcx6.cpp b/ares/component/eeprom/m93lcx6/m93lcx6.cpp index b3dcd3323f..581e9782c1 100644 --- a/ares/component/eeprom/m93lcx6/m93lcx6.cpp +++ b/ares/component/eeprom/m93lcx6/m93lcx6.cpp @@ -13,7 +13,7 @@ auto M93LCx6::reset() -> void { size = 0; } -auto M93LCx6::allocate(uint size, uint width, bool endian, uint8 fill) -> bool { +auto M93LCx6::allocate(u32 size, u32 width, bool endian, n8 fill) -> bool { if(size != 128 && size != 256 && size != 512 && size != 1024 && size != 2048) return false; if(width != 8 && width != 16) return false; @@ -37,7 +37,7 @@ auto M93LCx6::allocate(uint size, uint width, bool endian, uint8 fill) -> bool { } //used externally to program initial state values for uninitialized EEPROMs -auto M93LCx6::program(uint11 address, uint8 value) -> void { +auto M93LCx6::program(n11 address, n8 value) -> void { data[address] = value; } @@ -58,14 +58,14 @@ auto M93LCx6::power() -> void { auto M93LCx6::edge() -> void { //wait for start if(!input.start()) return; - uint start = *input.start(); + u32 start = *input.start(); //start bit must be set if(start != 1) return input.flush(); //wait for opcode if(!input.opcode()) return; - uint opcode = *input.opcode(); + u32 opcode = *input.opcode(); //wait for address if(!input.address()) return; @@ -85,9 +85,9 @@ auto M93LCx6::edge() -> void { // auto M93LCx6::read() -> void { - uint address = *input.address() << (width == 16) & size - 1; + u32 address = *input.address() << (width == 16) & size - 1; output.flush(); - for(uint4 index : range(width)) { + for(n4 index : range(width)) { output.write(data[address + (index.bit(3) ^ !endian)].bit(index.bit(0,2))); } output.write(0); //reads have an extra dummy data bit @@ -96,8 +96,8 @@ auto M93LCx6::read() -> void { auto M93LCx6::write() -> void { if(!input.data()) return; //wait for data if(!writable) return input.flush(); - uint address = *input.address() << (width == 16) & size - 1; - for(uint4 index : range(width)) { + u32 address = *input.address() << (width == 16) & size - 1; + for(n4 index : range(width)) { data[address + (index.bit(3) ^ !endian)].bit(index.bit(0,2)) = input.read(); } busy = 4; //milliseconds @@ -106,8 +106,8 @@ auto M93LCx6::write() -> void { auto M93LCx6::erase() -> void { if(!writable) return input.flush(); - uint address = *input.address() << (width == 16) & size - 1; - for(uint4 index : range(width)) { + u32 address = *input.address() << (width == 16) & size - 1; + for(n4 index : range(width)) { data[address + (index.bit(3) ^ !endian)].bit(index.bit(0,2)) = 1; } busy = 4; //milliseconds @@ -119,8 +119,8 @@ auto M93LCx6::writeAll() -> void { if(!writable) return input.flush(); auto word = *input.data(); if(width == 8) word |= word << 8; - for(uint address = 0; address < size; address += 2) { - for(uint4 index : range(16)) { + for(u32 address = 0; address < size; address += 2) { + for(n4 index : range(16)) { data[address + (index.bit(3) ^ !endian)].bit(index.bit(0,2)) = word.bit(index); } } @@ -153,18 +153,18 @@ auto M93LCx6::ShiftRegister::flush() -> void { } //peek at the next bit without clocking the shift register -auto M93LCx6::ShiftRegister::edge() -> uint1 { +auto M93LCx6::ShiftRegister::edge() -> n1 { return value.bit(0); } -auto M93LCx6::ShiftRegister::read() -> uint1 { - uint1 bit = value.bit(0); +auto M93LCx6::ShiftRegister::read() -> n1 { + n1 bit = value.bit(0); value >>= 1; count--; return bit; } -auto M93LCx6::ShiftRegister::write(uint1 bit) -> void { +auto M93LCx6::ShiftRegister::write(n1 bit) -> void { value <<= 1; value.bit(0) = bit; count++; @@ -172,27 +172,27 @@ auto M93LCx6::ShiftRegister::write(uint1 bit) -> void { // -auto M93LCx6::InputShiftRegister::start() -> maybe { +auto M93LCx6::InputShiftRegister::start() -> maybe { if(count < 1) return nothing; return {value >> count - 1 & 1}; } -auto M93LCx6::InputShiftRegister::opcode() -> maybe { +auto M93LCx6::InputShiftRegister::opcode() -> maybe { if(count < 1 + 2) return nothing; return {value >> count - 3 & 3}; } -auto M93LCx6::InputShiftRegister::mode() -> maybe { +auto M93LCx6::InputShiftRegister::mode() -> maybe { if(count < 1 + 2 + addressLength) return nothing; return {value >> count - 5 & 3}; } -auto M93LCx6::InputShiftRegister::address() -> maybe { +auto M93LCx6::InputShiftRegister::address() -> maybe { if(count < 1 + 2 + addressLength) return nothing; return {value >> count - (3 + addressLength) & (1 << addressLength) - 1}; } -auto M93LCx6::InputShiftRegister::data() -> maybe { +auto M93LCx6::InputShiftRegister::data() -> maybe { if(count < 1 + 2 + addressLength + dataLength) return nothing; return {value >> count - (3 + addressLength + dataLength) & (1 << dataLength) - 1}; } diff --git a/ares/component/eeprom/m93lcx6/m93lcx6.hpp b/ares/component/eeprom/m93lcx6/m93lcx6.hpp index 9464cac5d8..c6cd9d4bb7 100644 --- a/ares/component/eeprom/m93lcx6/m93lcx6.hpp +++ b/ares/component/eeprom/m93lcx6/m93lcx6.hpp @@ -13,8 +13,8 @@ struct M93LCx6 { //m93lcx6.cpp explicit operator bool() const; auto reset() -> void; - auto allocate(uint size, uint width, bool endian, uint8 fill) -> bool; - auto program(uint11 address, uint8 data) -> void; + auto allocate(u32 size, u32 width, bool endian, n8 fill) -> bool; + auto program(n11 address, n8 data) -> void; auto clock() -> void; auto power() -> void; auto edge() -> void; @@ -32,37 +32,37 @@ struct M93LCx6 { auto serialize(serializer&) -> void; //it is awkward no matter if data is uint1[bits], uint8[bytes], or uint16[words] - uint8 data[2048]; //uint8 was chosen solely for easier serialization and saving - uint size; //in bytes - uint width; //8-bit (ORG=0) or 16-bit (ORG=1) configuration - bool endian; //16-bit mode: 0 = little-endian; 1 = big-endian + n8 data[2048]; //uint8 was chosen solely for easier serialization and saving + u32 size; //in bytes + u32 width; //8-bit (ORG=0) or 16-bit (ORG=1) configuration + bool endian; //16-bit mode: 0 = little-endian; 1 = big-endian - boolean writable; //EWEN, EWDS - uint busy; //busy cycles in milliseconds remaining for programming (write) operations to complete + b1 writable; //EWEN, EWDS + u32 busy; //busy cycles in milliseconds remaining for programming (write) operations to complete struct ShiftRegister { auto flush() -> void; - auto edge() -> uint1; - auto read() -> uint1; - auto write(uint1 data) -> void; + auto edge() -> n1; + auto read() -> n1; + auto write(n1 data) -> void; - uint32 value; - uint32 count; + n32 value; + n32 count; }; struct InputShiftRegister : ShiftRegister { - auto start() -> maybe; - auto opcode() -> maybe; - auto mode() -> maybe; - auto address() -> maybe; - auto data() -> maybe; + auto start() -> maybe; + auto opcode() -> maybe; + auto mode() -> maybe; + auto address() -> maybe; + auto data() -> maybe; auto increment() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint32 addressLength; - uint32 dataLength; + n32 addressLength; + n32 dataLength; } input; struct OutputShiftRegister : ShiftRegister { diff --git a/ares/component/eeprom/x24c01/serialization.cpp b/ares/component/eeprom/x24c01/serialization.cpp index b4f4306589..538f27223b 100644 --- a/ares/component/eeprom/x24c01/serialization.cpp +++ b/ares/component/eeprom/x24c01/serialization.cpp @@ -10,7 +10,7 @@ auto X24C01::serialize(serializer& s) -> void { s(data.fall); s(data.rise); s(data.line); - s((uint&)mode); + s((u32&)mode); s(counter); s(address); s(input); diff --git a/ares/component/eeprom/x24c01/x24c01.cpp b/ares/component/eeprom/x24c01/x24c01.cpp index 72c5b89b66..f4f406df59 100644 --- a/ares/component/eeprom/x24c01/x24c01.cpp +++ b/ares/component/eeprom/x24c01/x24c01.cpp @@ -16,11 +16,11 @@ auto X24C01::reset() -> void { line = 1; } -auto X24C01::read() -> uint1 { +auto X24C01::read() -> n1 { return line; } -auto X24C01::write(uint1 scl, uint1 sda) -> void { +auto X24C01::write(n1 scl, n1 sda) -> void { clock.write(scl); data.write(sda); @@ -113,11 +113,11 @@ auto X24C01::write(uint1 scl, uint1 sda) -> void { } } -auto X24C01::erase(uint8 fill) -> void { +auto X24C01::erase(n8 fill) -> void { for(auto& byte : memory) byte = fill; } -auto X24C01::Line::write(uint1 data) -> void { +auto X24C01::Line::write(n1 data) -> void { lo = !line && !data; hi = line && data; fall = line && !data; diff --git a/ares/component/eeprom/x24c01/x24c01.hpp b/ares/component/eeprom/x24c01/x24c01.hpp index fd342ec090..4d8c11fca4 100644 --- a/ares/component/eeprom/x24c01/x24c01.hpp +++ b/ares/component/eeprom/x24c01/x24c01.hpp @@ -7,17 +7,17 @@ namespace ares { struct X24C01 { //x24c01.cpp auto reset() -> void; - auto read() -> uint1; - auto write(uint1 clock, uint1 data) -> void; - auto erase(uint8 fill = 0xff) -> void; + auto read() -> n1; + auto write(n1 clock, n1 data) -> void; + auto erase(n8 fill = 0xff) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8 memory[128]; + n8 memory[128]; private: - enum class Mode : uint { + enum class Mode : u32 { Idle, Address, AddressAcknowledge, Read, ReadAcknowledge, @@ -26,23 +26,23 @@ struct X24C01 { struct Line { //x24c01.cpp - auto write(uint1 data) -> void; + auto write(n1 data) -> void; - uint1 lo; - uint1 hi; - uint1 fall; - uint1 rise; - uint1 line; + n1 lo; + n1 hi; + n1 fall; + n1 rise; + n1 line; }; Line clock; Line data; Mode mode; - uint8 counter; - uint8 address; - uint8 input; - uint8 output; - uint1 line; + n8 counter; + n8 address; + n8 input; + n8 output; + n1 line; }; } diff --git a/ares/component/processor/arm7tdmi/algorithms.cpp b/ares/component/processor/arm7tdmi/algorithms.cpp index 15c0db4107..81cba1fbdc 100644 --- a/ares/component/processor/arm7tdmi/algorithms.cpp +++ b/ares/component/processor/arm7tdmi/algorithms.cpp @@ -1,7 +1,7 @@ -auto ARM7TDMI::ADD(uint32 source, uint32 modify, bool carry) -> uint32 { - uint32 result = source + modify + carry; +auto ARM7TDMI::ADD(n32 source, n32 modify, bool carry) -> n32 { + n32 result = source + modify + carry; if(cpsr().t || opcode.bit(20)) { - uint32 overflow = ~(source ^ modify) & (source ^ result); + n32 overflow = ~(source ^ modify) & (source ^ result); cpsr().v = 1 << 31 & (overflow); cpsr().c = 1 << 31 & (overflow ^ source ^ modify ^ result); cpsr().z = result == 0; @@ -10,15 +10,15 @@ auto ARM7TDMI::ADD(uint32 source, uint32 modify, bool carry) -> uint32 { return result; } -auto ARM7TDMI::ASR(uint32 source, uint8 shift) -> uint32 { +auto ARM7TDMI::ASR(n32 source, n8 shift) -> n32 { carry = cpsr().c; if(shift == 0) return source; carry = shift > 32 ? source & 1 << 31 : source & 1 << shift - 1; - source = shift > 31 ? (int32)source >> 31 : (int32)source >> shift; + source = shift > 31 ? (i32)source >> 31 : (i32)source >> shift; return source; } -auto ARM7TDMI::BIT(uint32 result) -> uint32 { +auto ARM7TDMI::BIT(n32 result) -> n32 { if(cpsr().t || opcode.bit(20)) { cpsr().c = carry; cpsr().z = result == 0; @@ -27,7 +27,7 @@ auto ARM7TDMI::BIT(uint32 result) -> uint32 { return result; } -auto ARM7TDMI::LSL(uint32 source, uint8 shift) -> uint32 { +auto ARM7TDMI::LSL(n32 source, n8 shift) -> n32 { carry = cpsr().c; if(shift == 0) return source; carry = shift > 32 ? 0 : source & 1 << 32 - shift; @@ -35,7 +35,7 @@ auto ARM7TDMI::LSL(uint32 source, uint8 shift) -> uint32 { return source; } -auto ARM7TDMI::LSR(uint32 source, uint8 shift) -> uint32 { +auto ARM7TDMI::LSR(n32 source, n8 shift) -> n32 { carry = cpsr().c; if(shift == 0) return source; carry = shift > 32 ? 0 : source & 1 << shift - 1; @@ -43,7 +43,7 @@ auto ARM7TDMI::LSR(uint32 source, uint8 shift) -> uint32 { return source; } -auto ARM7TDMI::MUL(uint32 product, uint32 multiplicand, uint32 multiplier) -> uint32 { +auto ARM7TDMI::MUL(n32 product, n32 multiplicand, n32 multiplier) -> n32 { idle(); if(multiplier >> 8 && multiplier >> 8 != 0xffffff) idle(); if(multiplier >> 16 && multiplier >> 16 != 0xffff) idle(); @@ -56,7 +56,7 @@ auto ARM7TDMI::MUL(uint32 product, uint32 multiplicand, uint32 multiplier) -> ui return product; } -auto ARM7TDMI::ROR(uint32 source, uint8 shift) -> uint32 { +auto ARM7TDMI::ROR(n32 source, n8 shift) -> n32 { carry = cpsr().c; if(shift == 0) return source; if(shift &= 31) source = source << 32 - shift | source >> shift; @@ -64,16 +64,16 @@ auto ARM7TDMI::ROR(uint32 source, uint8 shift) -> uint32 { return source; } -auto ARM7TDMI::RRX(uint32 source) -> uint32 { +auto ARM7TDMI::RRX(n32 source) -> n32 { carry = source.bit(0); return cpsr().c << 31 | source >> 1; } -auto ARM7TDMI::SUB(uint32 source, uint32 modify, bool carry) -> uint32 { +auto ARM7TDMI::SUB(n32 source, n32 modify, bool carry) -> n32 { return ADD(source, ~modify, carry); } -auto ARM7TDMI::TST(uint4 mode) -> bool { +auto ARM7TDMI::TST(n4 mode) -> bool { switch(mode) { case 0: return cpsr().z == 1; //EQ (equal) case 1: return cpsr().z == 0; //NE (not equal) diff --git a/ares/component/processor/arm7tdmi/arm7tdmi.hpp b/ares/component/processor/arm7tdmi/arm7tdmi.hpp index 4edcd5e3d1..c2485d2e64 100644 --- a/ares/component/processor/arm7tdmi/arm7tdmi.hpp +++ b/ares/component/processor/arm7tdmi/arm7tdmi.hpp @@ -5,7 +5,7 @@ namespace ares { struct ARM7TDMI { - enum : uint { + enum : u32 { Nonsequential = 1 << 0, //N cycle Sequential = 1 << 1, //S cycle Prefetch = 1 << 2, //instruction fetch @@ -17,10 +17,10 @@ struct ARM7TDMI { Signed = 1 << 8, //sign-extend }; - virtual auto step(uint clocks) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; virtual auto sleep() -> void = 0; - virtual auto get(uint mode, uint32 address) -> uint32 = 0; - virtual auto set(uint mode, uint32 address, uint32 word) -> void = 0; + virtual auto get(u32 mode, n32 address) -> n32 = 0; + virtual auto set(u32 mode, n32 address, n32 word) -> void = 0; //arm7tdmi.cpp ARM7TDMI(); @@ -29,7 +29,7 @@ struct ARM7TDMI { //registers.cpp struct GPR; struct PSR; - auto r(uint4) -> GPR&; + auto r(n4) -> GPR&; auto cpsr() -> PSR&; auto spsr() -> PSR&; auto privileged() const -> bool; @@ -37,103 +37,103 @@ struct ARM7TDMI { //memory.cpp auto idle() -> void; - auto read(uint mode, uint32 address) -> uint32; - auto load(uint mode, uint32 address) -> uint32; - auto write(uint mode, uint32 address, uint32 word) -> void; - auto store(uint mode, uint32 address, uint32 word) -> void; + auto read(u32 mode, n32 address) -> n32; + auto load(u32 mode, n32 address) -> n32; + auto write(u32 mode, n32 address, n32 word) -> void; + auto store(u32 mode, n32 address, n32 word) -> void; //algorithms.cpp - auto ADD(uint32, uint32, bool) -> uint32; - auto ASR(uint32, uint8) -> uint32; - auto BIT(uint32) -> uint32; - auto LSL(uint32, uint8) -> uint32; - auto LSR(uint32, uint8) -> uint32; - auto MUL(uint32, uint32, uint32) -> uint32; - auto ROR(uint32, uint8) -> uint32; - auto RRX(uint32) -> uint32; - auto SUB(uint32, uint32, bool) -> uint32; - auto TST(uint4) -> bool; + auto ADD(n32, n32, bool) -> n32; + auto ASR(n32, n8) -> n32; + auto BIT(n32) -> n32; + auto LSL(n32, n8) -> n32; + auto LSR(n32, n8) -> n32; + auto MUL(n32, n32, n32) -> n32; + auto ROR(n32, n8) -> n32; + auto RRX(n32) -> n32; + auto SUB(n32, n32, bool) -> n32; + auto TST(n4) -> bool; //instruction.cpp auto fetch() -> void; auto instruction() -> void; - auto exception(uint mode, uint32 address) -> void; + auto exception(u32 mode, n32 address) -> void; auto armInitialize() -> void; auto thumbInitialize() -> void; //instructions-arm.cpp - auto armALU(uint4 mode, uint4 target, uint4 source, uint32 data) -> void; - auto armMoveToStatus(uint4 field, uint1 source, uint32 data) -> void; - - auto armInstructionBranch(int24, uint1) -> void; - auto armInstructionBranchExchangeRegister(uint4) -> void; - auto armInstructionDataImmediate(uint8, uint4, uint4, uint4, uint1, uint4) -> void; - auto armInstructionDataImmediateShift(uint4, uint2, uint5, uint4, uint4, uint1, uint4) -> void; - auto armInstructionDataRegisterShift(uint4, uint2, uint4, uint4, uint4, uint1, uint4) -> void; - auto armInstructionLoadImmediate(uint8, uint1, uint4, uint4, uint1, uint1, uint1) -> void; - auto armInstructionLoadRegister(uint4, uint1, uint4, uint4, uint1, uint1, uint1) -> void; - auto armInstructionMemorySwap(uint4, uint4, uint4, uint1) -> void; - auto armInstructionMoveHalfImmediate(uint8, uint4, uint4, uint1, uint1, uint1, uint1) -> void; - auto armInstructionMoveHalfRegister(uint4, uint4, uint4, uint1, uint1, uint1, uint1) -> void; - auto armInstructionMoveImmediateOffset(uint12, uint4, uint4, uint1, uint1, uint1, uint1, uint1) -> void; - auto armInstructionMoveMultiple(uint16, uint4, uint1, uint1, uint1, uint1, uint1) -> void; - auto armInstructionMoveRegisterOffset(uint4, uint2, uint5, uint4, uint4, uint1, uint1, uint1, uint1, uint1) -> void; - auto armInstructionMoveToRegisterFromStatus(uint4, uint1) -> void; - auto armInstructionMoveToStatusFromImmediate(uint8, uint4, uint4, uint1) -> void; - auto armInstructionMoveToStatusFromRegister(uint4, uint4, uint1) -> void; - auto armInstructionMultiply(uint4, uint4, uint4, uint4, uint1, uint1) -> void; - auto armInstructionMultiplyLong(uint4, uint4, uint4, uint4, uint1, uint1, uint1) -> void; - auto armInstructionSoftwareInterrupt(uint24 immediate) -> void; + auto armALU(n4 mode, n4 target, n4 source, n32 data) -> void; + auto armMoveToStatus(n4 field, n1 source, n32 data) -> void; + + auto armInstructionBranch(i24, n1) -> void; + auto armInstructionBranchExchangeRegister(n4) -> void; + auto armInstructionDataImmediate(n8, n4, n4, n4, n1, n4) -> void; + auto armInstructionDataImmediateShift(n4, n2, n5, n4, n4, n1, n4) -> void; + auto armInstructionDataRegisterShift(n4, n2, n4, n4, n4, n1, n4) -> void; + auto armInstructionLoadImmediate(n8, n1, n4, n4, n1, n1, n1) -> void; + auto armInstructionLoadRegister(n4, n1, n4, n4, n1, n1, n1) -> void; + auto armInstructionMemorySwap(n4, n4, n4, n1) -> void; + auto armInstructionMoveHalfImmediate(n8, n4, n4, n1, n1, n1, n1) -> void; + auto armInstructionMoveHalfRegister(n4, n4, n4, n1, n1, n1, n1) -> void; + auto armInstructionMoveImmediateOffset(n12, n4, n4, n1, n1, n1, n1, n1) -> void; + auto armInstructionMoveMultiple(n16, n4, n1, n1, n1, n1, n1) -> void; + auto armInstructionMoveRegisterOffset(n4, n2, n5, n4, n4, n1, n1, n1, n1, n1) -> void; + auto armInstructionMoveToRegisterFromStatus(n4, n1) -> void; + auto armInstructionMoveToStatusFromImmediate(n8, n4, n4, n1) -> void; + auto armInstructionMoveToStatusFromRegister(n4, n4, n1) -> void; + auto armInstructionMultiply(n4, n4, n4, n4, n1, n1) -> void; + auto armInstructionMultiplyLong(n4, n4, n4, n4, n1, n1, n1) -> void; + auto armInstructionSoftwareInterrupt(n24 immediate) -> void; auto armInstructionUndefined() -> void; //instructions-thumb.cpp - auto thumbInstructionALU(uint3, uint3, uint4) -> void; - auto thumbInstructionALUExtended(uint4, uint4, uint2) -> void; - auto thumbInstructionAddRegister(uint8, uint3, uint1) -> void; - auto thumbInstructionAdjustImmediate(uint3, uint3, uint3, uint1) -> void; - auto thumbInstructionAdjustRegister(uint3, uint3, uint3, uint1) -> void; - auto thumbInstructionAdjustStack(uint7, uint1) -> void; - auto thumbInstructionBranchExchange(uint4) -> void; - auto thumbInstructionBranchFarPrefix(int11) -> void; - auto thumbInstructionBranchFarSuffix(uint11) -> void; - auto thumbInstructionBranchNear(int11) -> void; - auto thumbInstructionBranchTest(int8, uint4) -> void; - auto thumbInstructionImmediate(uint8, uint3, uint2) -> void; - auto thumbInstructionLoadLiteral(uint8, uint3) -> void; - auto thumbInstructionMoveByteImmediate(uint3, uint3, uint5, uint1) -> void; - auto thumbInstructionMoveHalfImmediate(uint3, uint3, uint5, uint1) -> void; - auto thumbInstructionMoveMultiple(uint8, uint3, uint1) -> void; - auto thumbInstructionMoveRegisterOffset(uint3, uint3, uint3, uint3) -> void; - auto thumbInstructionMoveStack(uint8, uint3, uint1) -> void; - auto thumbInstructionMoveWordImmediate(uint3, uint3, uint5, uint1) -> void; - auto thumbInstructionShiftImmediate(uint3, uint3, uint5, uint2) -> void; - auto thumbInstructionSoftwareInterrupt(uint8) -> void; - auto thumbInstructionStackMultiple(uint8, uint1, uint1) -> void; + auto thumbInstructionALU(n3, n3, n4) -> void; + auto thumbInstructionALUExtended(n4, n4, n2) -> void; + auto thumbInstructionAddRegister(n8, n3, n1) -> void; + auto thumbInstructionAdjustImmediate(n3, n3, n3, n1) -> void; + auto thumbInstructionAdjustRegister(n3, n3, n3, n1) -> void; + auto thumbInstructionAdjustStack(n7, n1) -> void; + auto thumbInstructionBranchExchange(n4) -> void; + auto thumbInstructionBranchFarPrefix(i11) -> void; + auto thumbInstructionBranchFarSuffix(n11) -> void; + auto thumbInstructionBranchNear(i11) -> void; + auto thumbInstructionBranchTest(i8, n4) -> void; + auto thumbInstructionImmediate(n8, n3, n2) -> void; + auto thumbInstructionLoadLiteral(n8, n3) -> void; + auto thumbInstructionMoveByteImmediate(n3, n3, n5, n1) -> void; + auto thumbInstructionMoveHalfImmediate(n3, n3, n5, n1) -> void; + auto thumbInstructionMoveMultiple(n8, n3, n1) -> void; + auto thumbInstructionMoveRegisterOffset(n3, n3, n3, n3) -> void; + auto thumbInstructionMoveStack(n8, n3, n1) -> void; + auto thumbInstructionMoveWordImmediate(n3, n3, n5, n1) -> void; + auto thumbInstructionShiftImmediate(n3, n3, n5, n2) -> void; + auto thumbInstructionSoftwareInterrupt(n8) -> void; + auto thumbInstructionStackMultiple(n8, n1, n1) -> void; auto thumbInstructionUndefined() -> void; //serialization.cpp auto serialize(serializer&) -> void; //disassembler.cpp - auto disassembleInstruction(maybe pc = {}, maybe thumb = {}) -> string; + auto disassembleInstruction(maybe pc = {}, maybe thumb = {}) -> string; auto disassembleContext() -> string; struct GPR { - operator uint32_t() const { return data; } + operator u32() const { return data; } auto operator=(const GPR& value) -> GPR& { return operator=(value.data); } - auto operator=(uint32 value) -> GPR& { + auto operator=(n32 value) -> GPR& { data = value; if(modify) modify(); return *this; } - uint32 data; + n32 data; function void> modify; }; struct PSR { - enum : uint { + enum : u32 { USR = 0x10, //user FIQ = 0x11, //fast interrupt IRQ = 0x12, //interrupt @@ -143,11 +143,11 @@ struct ARM7TDMI { SYS = 0x1f, //system }; - operator uint32_t() const { + operator u32() const { return m << 0 | t << 5 | f << 6 | i << 7 | v << 28 | c << 29 | z << 30 | n << 31; } - auto operator=(uint32 data) -> PSR& { + auto operator=(n32 data) -> PSR& { m = data.bit(0,4); t = data.bit(5); f = data.bit(6); @@ -162,14 +162,14 @@ struct ARM7TDMI { //serialization.cpp auto serialize(serializer&) -> void; - uint5 m; //mode - boolean t; //thumb - boolean f; //fiq - boolean i; //irq - boolean v; //overflow - boolean c; //carry - boolean z; //zero - boolean n; //negative + n5 m; //mode + b1 t; //thumb + b1 f; //fiq + b1 i; //irq + b1 v; //overflow + b1 c; //carry + b1 z; //zero + b1 n; //negative }; struct Processor { @@ -210,75 +210,75 @@ struct ARM7TDMI { auto serialize(serializer&) -> void; struct Instruction { - uint32 address; - uint32 instruction; - boolean thumb; //not used by fetch stage + n32 address; + n32 instruction; + b1 thumb; //not used by fetch stage }; - uint1 reload = 1; - uint1 nonsequential = 1; + n1 reload = 1; + n1 nonsequential = 1; Instruction fetch; Instruction decode; Instruction execute; } pipeline; - uint32 opcode; - boolean carry; - boolean irq; + n32 opcode; + b1 carry; + b1 irq; - function armInstruction[4096]; + function armInstruction[4096]; function thumbInstruction[65536]; //disassembler.cpp - auto armDisassembleBranch(int24, uint1) -> string; - auto armDisassembleBranchExchangeRegister(uint4) -> string; - auto armDisassembleDataImmediate(uint8, uint4, uint4, uint4, uint1, uint4) -> string; - auto armDisassembleDataImmediateShift(uint4, uint2, uint5, uint4, uint4, uint1, uint4) -> string; - auto armDisassembleDataRegisterShift(uint4, uint2, uint4, uint4, uint4, uint1, uint4) -> string; - auto armDisassembleLoadImmediate(uint8, uint1, uint4, uint4, uint1, uint1, uint1) -> string; - auto armDisassembleLoadRegister(uint4, uint1, uint4, uint4, uint1, uint1, uint1) -> string; - auto armDisassembleMemorySwap(uint4, uint4, uint4, uint1) -> string; - auto armDisassembleMoveHalfImmediate(uint8, uint4, uint4, uint1, uint1, uint1, uint1) -> string; - auto armDisassembleMoveHalfRegister(uint4, uint4, uint4, uint1, uint1, uint1, uint1) -> string; - auto armDisassembleMoveImmediateOffset(uint12, uint4, uint4, uint1, uint1, uint1, uint1, uint1) -> string; - auto armDisassembleMoveMultiple(uint16, uint4, uint1, uint1, uint1, uint1, uint1) -> string; - auto armDisassembleMoveRegisterOffset(uint4, uint2, uint5, uint4, uint4, uint1, uint1, uint1, uint1, uint1) -> string; - auto armDisassembleMoveToRegisterFromStatus(uint4, uint1) -> string; - auto armDisassembleMoveToStatusFromImmediate(uint8, uint4, uint4, uint1) -> string; - auto armDisassembleMoveToStatusFromRegister(uint4, uint4, uint1) -> string; - auto armDisassembleMultiply(uint4, uint4, uint4, uint4, uint1, uint1) -> string; - auto armDisassembleMultiplyLong(uint4, uint4, uint4, uint4, uint1, uint1, uint1) -> string; - auto armDisassembleSoftwareInterrupt(uint24) -> string; + auto armDisassembleBranch(i24, n1) -> string; + auto armDisassembleBranchExchangeRegister(n4) -> string; + auto armDisassembleDataImmediate(n8, n4, n4, n4, n1, n4) -> string; + auto armDisassembleDataImmediateShift(n4, n2, n5, n4, n4, n1, n4) -> string; + auto armDisassembleDataRegisterShift(n4, n2, n4, n4, n4, n1, n4) -> string; + auto armDisassembleLoadImmediate(n8, n1, n4, n4, n1, n1, n1) -> string; + auto armDisassembleLoadRegister(n4, n1, n4, n4, n1, n1, n1) -> string; + auto armDisassembleMemorySwap(n4, n4, n4, n1) -> string; + auto armDisassembleMoveHalfImmediate(n8, n4, n4, n1, n1, n1, n1) -> string; + auto armDisassembleMoveHalfRegister(n4, n4, n4, n1, n1, n1, n1) -> string; + auto armDisassembleMoveImmediateOffset(n12, n4, n4, n1, n1, n1, n1, n1) -> string; + auto armDisassembleMoveMultiple(n16, n4, n1, n1, n1, n1, n1) -> string; + auto armDisassembleMoveRegisterOffset(n4, n2, n5, n4, n4, n1, n1, n1, n1, n1) -> string; + auto armDisassembleMoveToRegisterFromStatus(n4, n1) -> string; + auto armDisassembleMoveToStatusFromImmediate(n8, n4, n4, n1) -> string; + auto armDisassembleMoveToStatusFromRegister(n4, n4, n1) -> string; + auto armDisassembleMultiply(n4, n4, n4, n4, n1, n1) -> string; + auto armDisassembleMultiplyLong(n4, n4, n4, n4, n1, n1, n1) -> string; + auto armDisassembleSoftwareInterrupt(n24) -> string; auto armDisassembleUndefined() -> string; - auto thumbDisassembleALU(uint3, uint3, uint4) -> string; - auto thumbDisassembleALUExtended(uint4, uint4, uint2) -> string; - auto thumbDisassembleAddRegister(uint8, uint3, uint1) -> string; - auto thumbDisassembleAdjustImmediate(uint3, uint3, uint3, uint1) -> string; - auto thumbDisassembleAdjustRegister(uint3, uint3, uint3, uint1) -> string; - auto thumbDisassembleAdjustStack(uint7, uint1) -> string; - auto thumbDisassembleBranchExchange(uint4) -> string; - auto thumbDisassembleBranchFarPrefix(int11) -> string; - auto thumbDisassembleBranchFarSuffix(uint11) -> string; - auto thumbDisassembleBranchNear(int11) -> string; - auto thumbDisassembleBranchTest(int8, uint4) -> string; - auto thumbDisassembleImmediate(uint8, uint3, uint2) -> string; - auto thumbDisassembleLoadLiteral(uint8, uint3) -> string; - auto thumbDisassembleMoveByteImmediate(uint3, uint3, uint5, uint1) -> string; - auto thumbDisassembleMoveHalfImmediate(uint3, uint3, uint5, uint1) -> string; - auto thumbDisassembleMoveMultiple(uint8, uint3, uint1) -> string; - auto thumbDisassembleMoveRegisterOffset(uint3, uint3, uint3, uint3) -> string; - auto thumbDisassembleMoveStack(uint8, uint3, uint1) -> string; - auto thumbDisassembleMoveWordImmediate(uint3, uint3, uint5, uint1) -> string; - auto thumbDisassembleShiftImmediate(uint3, uint3, uint5, uint2) -> string; - auto thumbDisassembleSoftwareInterrupt(uint8) -> string; - auto thumbDisassembleStackMultiple(uint8, uint1, uint1) -> string; + auto thumbDisassembleALU(n3, n3, n4) -> string; + auto thumbDisassembleALUExtended(n4, n4, n2) -> string; + auto thumbDisassembleAddRegister(n8, n3, n1) -> string; + auto thumbDisassembleAdjustImmediate(n3, n3, n3, n1) -> string; + auto thumbDisassembleAdjustRegister(n3, n3, n3, n1) -> string; + auto thumbDisassembleAdjustStack(n7, n1) -> string; + auto thumbDisassembleBranchExchange(n4) -> string; + auto thumbDisassembleBranchFarPrefix(i11) -> string; + auto thumbDisassembleBranchFarSuffix(n11) -> string; + auto thumbDisassembleBranchNear(i11) -> string; + auto thumbDisassembleBranchTest(i8, n4) -> string; + auto thumbDisassembleImmediate(n8, n3, n2) -> string; + auto thumbDisassembleLoadLiteral(n8, n3) -> string; + auto thumbDisassembleMoveByteImmediate(n3, n3, n5, n1) -> string; + auto thumbDisassembleMoveHalfImmediate(n3, n3, n5, n1) -> string; + auto thumbDisassembleMoveMultiple(n8, n3, n1) -> string; + auto thumbDisassembleMoveRegisterOffset(n3, n3, n3, n3) -> string; + auto thumbDisassembleMoveStack(n8, n3, n1) -> string; + auto thumbDisassembleMoveWordImmediate(n3, n3, n5, n1) -> string; + auto thumbDisassembleShiftImmediate(n3, n3, n5, n2) -> string; + auto thumbDisassembleSoftwareInterrupt(n8) -> string; + auto thumbDisassembleStackMultiple(n8, n1, n1) -> string; auto thumbDisassembleUndefined() -> string; - function armDisassemble[4096]; + function armDisassemble[4096]; function thumbDisassemble[65536]; - uint32 _pc; + n32 _pc; string _c; }; diff --git a/ares/component/processor/arm7tdmi/disassembler.cpp b/ares/component/processor/arm7tdmi/disassembler.cpp index 269ba1bda6..ee8665fb32 100644 --- a/ares/component/processor/arm7tdmi/disassembler.cpp +++ b/ares/component/processor/arm7tdmi/disassembler.cpp @@ -11,25 +11,25 @@ static const string _conditions[] = { #define _comp(mode) (mode >= 8 && mode <= 11) #define _math(mode) (mode <= 7 || mode == 12 || mode == 14) -auto ARM7TDMI::disassembleInstruction(maybe pc, maybe thumb) -> string { +auto ARM7TDMI::disassembleInstruction(maybe pc, maybe thumb) -> string { if(!pc) pc = pipeline.execute.address; if(!thumb) thumb = cpsr().t; _pc = pc(); if(!thumb()) { - uint32 opcode = read(Word | Nonsequential, _pc & ~3); - uint12 index = (opcode & 0x0ff00000) >> 16 | (opcode & 0x000000f0) >> 4; + n32 opcode = read(Word | Nonsequential, _pc & ~3); + n12 index = (opcode & 0x0ff00000) >> 16 | (opcode & 0x000000f0) >> 4; _c = _conditions[opcode >> 28]; return pad(armDisassemble[index](opcode), -40); } else { - uint16 opcode = read(Half | Nonsequential, _pc & ~1); + n16 opcode = read(Half | Nonsequential, _pc & ~1); return pad(thumbDisassemble[opcode](), -40); } } auto ARM7TDMI::disassembleContext() -> string { string output; - for(uint n : range(16)) { + for(u32 n : range(16)) { output.append(_r[n], ":", hex(r(n), 8L), " "); } @@ -59,22 +59,22 @@ auto ARM7TDMI::disassembleContext() -> string { // auto ARM7TDMI::armDisassembleBranch -(int24 displacement, uint1 link) -> string { +(i24 displacement, n1 link) -> string { return {"b", link ? "l" : "", _c, " 0x", hex(_pc + 8 + displacement * 4, 8L)}; } auto ARM7TDMI::armDisassembleBranchExchangeRegister -(uint4 m) -> string { +(n4 m) -> string { return {"bx", _c, " ", _r[m]}; } auto ARM7TDMI::armDisassembleDataImmediate -(uint8 immediate, uint4 shift, uint4 d, uint4 n, uint1 save, uint4 mode) -> string { +(n8 immediate, n4 shift, n4 d, n4 n, n1 save, n4 mode) -> string { static const string opcode[] = { "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc", "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn", }; - uint32 data = immediate >> (shift << 1) | immediate << 32 - (shift << 1); + n32 data = immediate >> (shift << 1) | immediate << 32 - (shift << 1); return {opcode[mode], _c, _move(mode) ? string{_s, " ", _r[d]} : string{}, _comp(mode) ? string{" ", _r[n]} : string{}, @@ -83,7 +83,7 @@ auto ARM7TDMI::armDisassembleDataImmediate } auto ARM7TDMI::armDisassembleDataImmediateShift -(uint4 m, uint2 type, uint5 shift, uint4 d, uint4 n, uint1 save, uint4 mode) -> string { +(n4 m, n2 type, n5 shift, n4 d, n4 n, n1 save, n4 mode) -> string { static const string opcode[] = { "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc", "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn", @@ -94,14 +94,14 @@ auto ARM7TDMI::armDisassembleDataImmediateShift _math(mode) ? string{_s, " ", _r[d], ",", _r[n]} : string{}, ",", _r[m], type == 0 && shift ? string{" lsl #", shift} : string{}, - type == 1 ? string{" lsr #", shift ? (uint)shift : 32} : string{}, - type == 2 ? string{" asr #", shift ? (uint)shift : 32} : string{}, + type == 1 ? string{" lsr #", shift ? (u32)shift : 32} : string{}, + type == 2 ? string{" asr #", shift ? (u32)shift : 32} : string{}, type == 3 && shift ? string{" ror #", shift} : string{}, type == 3 && !shift ? " rrx" : ""}; } auto ARM7TDMI::armDisassembleDataRegisterShift -(uint4 m, uint2 type, uint4 s, uint4 d, uint4 n, uint1 save, uint4 mode) -> string { +(n4 m, n2 type, n4 s, n4 d, n4 n, n1 save, n4 mode) -> string { static const string opcode[] = { "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc", "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn", @@ -119,7 +119,7 @@ auto ARM7TDMI::armDisassembleDataRegisterShift } auto ARM7TDMI::armDisassembleLoadImmediate -(uint8 immediate, uint1 half, uint4 d, uint4 n, uint1 writeback, uint1 up, uint1 pre) -> string { +(n8 immediate, n1 half, n4 d, n4 n, n1 writeback, n1 up, n1 pre) -> string { string data; if(n == 15) data = {" =0x", hex(read((half ? Half : Byte) | Nonsequential, _pc + 8 + (up ? +immediate : -immediate)), half ? 4L : 2L)}; @@ -133,7 +133,7 @@ auto ARM7TDMI::armDisassembleLoadImmediate } auto ARM7TDMI::armDisassembleLoadRegister -(uint4 m, uint1 half, uint4 d, uint4 n, uint1 writeback, uint1 up, uint1 pre) -> string { +(n4 m, n1 half, n4 d, n4 n, n1 writeback, n1 up, n1 pre) -> string { return {"ldr", _c, half ? "sh" : "sb", " ", _r[d], ",[", _r[n], pre == 0 ? "]" : "", @@ -143,12 +143,12 @@ auto ARM7TDMI::armDisassembleLoadRegister } auto ARM7TDMI::armDisassembleMemorySwap -(uint4 m, uint4 d, uint4 n, uint1 byte) -> string { +(n4 m, n4 d, n4 n, n1 byte) -> string { return {"swp", _c, byte ? "b" : "", " ", _r[d], ",", _r[m], ",[", _r[n], "]"}; } auto ARM7TDMI::armDisassembleMoveHalfImmediate -(uint8 immediate, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 up, uint1 pre) -> string { +(n8 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 up, n1 pre) -> string { string data; if(n == 15) data = {" =0x", hex(read(Half | Nonsequential, _pc + (up ? +immediate : -immediate)), 4L)}; @@ -161,7 +161,7 @@ auto ARM7TDMI::armDisassembleMoveHalfImmediate } auto ARM7TDMI::armDisassembleMoveHalfRegister -(uint4 m, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 up, uint1 pre) -> string { +(n4 m, n4 d, n4 n, n1 mode, n1 writeback, n1 up, n1 pre) -> string { return {mode ? "ldr" : "str", _c, "h ", _r[d], ",[", _r[n], pre == 0 ? "]" : "", @@ -171,7 +171,7 @@ auto ARM7TDMI::armDisassembleMoveHalfRegister } auto ARM7TDMI::armDisassembleMoveImmediateOffset -(uint12 immediate, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 byte, uint1 up, uint1 pre) -> string { +(n12 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 byte, n1 up, n1 pre) -> string { string data; if(n == 15) data = {" =0x", hex(read((byte ? Byte : Word) | Nonsequential, _pc + 8 + (up ? +immediate : -immediate)), byte ? 2L : 4L)}; @@ -183,9 +183,9 @@ auto ARM7TDMI::armDisassembleMoveImmediateOffset } auto ARM7TDMI::armDisassembleMoveMultiple -(uint16 list, uint4 n, uint1 mode, uint1 writeback, uint1 type, uint1 up, uint1 pre) -> string { +(n16 list, n4 n, n1 mode, n1 writeback, n1 type, n1 up, n1 pre) -> string { string registers; - for(uint index : range(16)) { + for(u32 index : range(16)) { if(list.bit(index)) registers.append(_r[index], ","); } registers.trimRight(",", 1L); @@ -199,13 +199,13 @@ auto ARM7TDMI::armDisassembleMoveMultiple } auto ARM7TDMI::armDisassembleMoveRegisterOffset -(uint4 m, uint2 type, uint5 shift, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 byte, uint1 up, uint1 pre) -> string { +(n4 m, n2 type, n5 shift, n4 d, n4 n, n1 mode, n1 writeback, n1 byte, n1 up, n1 pre) -> string { return {mode ? "ldr" : "str", _c, byte ? "b" : "", " ", _r[d], ",[", _r[n], pre == 0 ? "]" : "", ",", up ? "+" : "-", _r[m], type == 0 && shift ? string{" lsl #", shift} : string{}, - type == 1 ? string{" lsr #", shift ? (uint)shift : 32} : string{}, - type == 2 ? string{" asr #", shift ? (uint)shift : 32} : string{}, + type == 1 ? string{" lsr #", shift ? (u32)shift : 32} : string{}, + type == 2 ? string{" asr #", shift ? (u32)shift : 32} : string{}, type == 3 && shift ? string{" ror #", shift} : string{}, type == 3 && !shift ? " rrx" : "", pre == 1 ? "]" : "", @@ -213,13 +213,13 @@ auto ARM7TDMI::armDisassembleMoveRegisterOffset } auto ARM7TDMI::armDisassembleMoveToRegisterFromStatus -(uint4 d, uint1 mode) -> string { +(n4 d, n1 mode) -> string { return {"mrs", _c, " ", _r[d], ",", mode ? "spsr" : "cpsr"}; } auto ARM7TDMI::armDisassembleMoveToStatusFromImmediate -(uint8 immediate, uint4 rotate, uint4 field, uint1 mode) -> string { - uint32 data = immediate >> (rotate << 1) | immediate << 32 - (rotate << 1); +(n8 immediate, n4 rotate, n4 field, n1 mode) -> string { + n32 data = immediate >> (rotate << 1) | immediate << 32 - (rotate << 1); return {"msr", _c, " ", mode ? "spsr:" : "cpsr:", field.bit(0) ? "c" : "", field.bit(1) ? "x" : "", @@ -229,7 +229,7 @@ auto ARM7TDMI::armDisassembleMoveToStatusFromImmediate } auto ARM7TDMI::armDisassembleMoveToStatusFromRegister -(uint4 m, uint4 field, uint1 mode) -> string { +(n4 m, n4 field, n1 mode) -> string { return {"msr", _c, " ", mode ? "spsr:" : "cpsr:", field.bit(0) ? "c" : "", field.bit(1) ? "x" : "", @@ -239,7 +239,7 @@ auto ARM7TDMI::armDisassembleMoveToStatusFromRegister } auto ARM7TDMI::armDisassembleMultiply -(uint4 m, uint4 s, uint4 n, uint4 d, uint1 save, uint1 accumulate) -> string { +(n4 m, n4 s, n4 n, n4 d, n1 save, n1 accumulate) -> string { if(accumulate) { return {"mla", _c, _s, " ", _r[d], ",", _r[m], ",", _r[s], ",", _r[n]}; } else { @@ -248,13 +248,13 @@ auto ARM7TDMI::armDisassembleMultiply } auto ARM7TDMI::armDisassembleMultiplyLong -(uint4 m, uint4 s, uint4 l, uint4 h, uint1 save, uint1 accumulate, uint1 sign) -> string { +(n4 m, n4 s, n4 l, n4 h, n1 save, n1 accumulate, n1 sign) -> string { return {sign ? "s" : "u", accumulate ? "mlal" : "mull", _c, _s, " ", _r[l], ",", _r[h], ",", _r[m], ",", _r[s]}; } auto ARM7TDMI::armDisassembleSoftwareInterrupt -(uint24 immediate) -> string { +(n24 immediate) -> string { return {"swi #0x", hex(immediate, 6L)}; } @@ -266,7 +266,7 @@ auto ARM7TDMI::armDisassembleUndefined // auto ARM7TDMI::thumbDisassembleALU -(uint3 d, uint3 m, uint4 mode) -> string { +(n3 d, n3 m, n4 mode) -> string { static const string opcode[] = { "and", "eor", "lsl", "lsr", "asr", "adc", "sbc", "ror", "tst", "neg", "cmp", "cmn", "orr", "mul", "bic", "mvn", @@ -275,89 +275,89 @@ auto ARM7TDMI::thumbDisassembleALU } auto ARM7TDMI::thumbDisassembleALUExtended -(uint4 d, uint4 m, uint2 mode) -> string { +(n4 d, n4 m, n2 mode) -> string { static const string opcode[] = {"add", "sub", "mov"}; if(d == 8 && m == 8 && mode == 2) return {"nop"}; return {opcode[mode], " ", _r[d], ",", _r[m]}; } auto ARM7TDMI::thumbDisassembleAddRegister -(uint8 immediate, uint3 d, uint1 mode) -> string { +(n8 immediate, n3 d, n1 mode) -> string { return {"add ", _r[d], ",", mode ? "sp" : "pc", ",#0x", hex(immediate, 2L)}; } auto ARM7TDMI::thumbDisassembleAdjustImmediate -(uint3 d, uint3 n, uint3 immediate, uint1 mode) -> string { +(n3 d, n3 n, n3 immediate, n1 mode) -> string { return {!mode ? "add" : "sub", " ", _r[d], ",", _r[n], ",#", immediate}; } auto ARM7TDMI::thumbDisassembleAdjustRegister -(uint3 d, uint3 n, uint3 m, uint1 mode) -> string { +(n3 d, n3 n, n3 m, n1 mode) -> string { return {!mode ? "add" : "sub", " ", _r[d], ",", _r[n], ",", _r[m]}; } auto ARM7TDMI::thumbDisassembleAdjustStack -(uint7 immediate, uint1 mode) -> string { +(n7 immediate, n1 mode) -> string { return {!mode ? "add" : "sub", " sp,#0x", hex(immediate * 4, 3L)}; } auto ARM7TDMI::thumbDisassembleBranchExchange -(uint4 m) -> string { +(n4 m) -> string { return {"bx ", _r[m]}; } auto ARM7TDMI::thumbDisassembleBranchFarPrefix -(int11 displacementHi) -> string { - uint11 displacementLo = read(Half | Nonsequential, (_pc & ~1) + 2); - int22 displacement = displacementHi << 11 | displacementLo << 0; - uint32 address = _pc + 4 + displacement * 2; +(i11 displacementHi) -> string { + n11 displacementLo = read(Half | Nonsequential, (_pc & ~1) + 2); + i22 displacement = displacementHi << 11 | displacementLo << 0; + n32 address = _pc + 4 + displacement * 2; return {"bl 0x", hex(address, 8L)}; } auto ARM7TDMI::thumbDisassembleBranchFarSuffix -(uint11 displacement) -> string { +(n11 displacement) -> string { return {"bl (suffix)"}; } auto ARM7TDMI::thumbDisassembleBranchNear -(int11 displacement) -> string { - uint32 address = _pc + 4 + displacement * 2; +(i11 displacement) -> string { + n32 address = _pc + 4 + displacement * 2; return {"b 0x", hex(address, 8L)}; } auto ARM7TDMI::thumbDisassembleBranchTest -(int8 displacement, uint4 condition) -> string { - uint32 address = _pc + 4 + displacement * 2; +(i8 displacement, n4 condition) -> string { + n32 address = _pc + 4 + displacement * 2; return {"b", _conditions[condition], " 0x", hex(address, 8L)}; } auto ARM7TDMI::thumbDisassembleImmediate -(uint8 immediate, uint3 d, uint2 mode) -> string { +(n8 immediate, n3 d, n2 mode) -> string { static const string opcode[] = {"mov", "cmp", "add", "sub"}; return {opcode[mode], " ", _r[d], ",#0x", hex(immediate, 2L)}; } auto ARM7TDMI::thumbDisassembleLoadLiteral -(uint8 displacement, uint3 d) -> string { - uint32 address = ((_pc + 4) & ~3) + (displacement << 2); - uint32 data = read(Word | Nonsequential, address); +(n8 displacement, n3 d) -> string { + n32 address = ((_pc + 4) & ~3) + (displacement << 2); + n32 data = read(Word | Nonsequential, address); return {"ldr ", _r[d], ",[pc,#0x", hex(address, 8L), "] =0x", hex(data, 8L)}; } auto ARM7TDMI::thumbDisassembleMoveByteImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> string { +(n3 d, n3 n, n5 offset, n1 mode) -> string { return {mode ? "ldrb" : "strb", " ", _r[d], ",[", _r[n], ",#0x", hex(offset, 2L), "]"}; } auto ARM7TDMI::thumbDisassembleMoveHalfImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> string { +(n3 d, n3 n, n5 offset, n1 mode) -> string { return {mode ? "ldrh" : "strh", " ", _r[d], ",[", _r[n], ",#0x", hex(offset * 2, 2L), "]"}; } auto ARM7TDMI::thumbDisassembleMoveMultiple -(uint8 list, uint3 n, uint1 mode) -> string { +(n8 list, n3 n, n1 mode) -> string { string registers; - for(uint m : range(8)) { + for(u32 m : range(8)) { if(list.bit(m)) registers.append(_r[m], ","); } registers.trimRight(",", 1L); @@ -365,36 +365,36 @@ auto ARM7TDMI::thumbDisassembleMoveMultiple } auto ARM7TDMI::thumbDisassembleMoveRegisterOffset -(uint3 d, uint3 n, uint3 m, uint3 mode) -> string { +(n3 d, n3 n, n3 m, n3 mode) -> string { static const string opcode[] = {"str", "strh", "strb", "ldsb", "ldr", "ldrh", "ldrb", "ldsh"}; return {opcode[mode], " ", _r[d], ",[", _r[n], ",", _r[m], "]"}; } auto ARM7TDMI::thumbDisassembleMoveStack -(uint8 immediate, uint3 d, uint1 mode) -> string { +(n8 immediate, n3 d, n1 mode) -> string { return {mode ? "ldr" : "str", " ", _r[d], ",[sp,#0x", hex(immediate * 4, 3L), "]"}; } auto ARM7TDMI::thumbDisassembleMoveWordImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> string { +(n3 d, n3 n, n5 offset, n1 mode) -> string { return {mode ? "ldr" : "str", " ", _r[d], ",[", _r[n], ",#0x", hex(offset * 4, 2L), "]"}; } auto ARM7TDMI::thumbDisassembleShiftImmediate -(uint3 d, uint3 m, uint5 immediate, uint2 mode) -> string { +(n3 d, n3 m, n5 immediate, n2 mode) -> string { static const string opcode[] = {"lsl", "lsr", "asr"}; return {opcode[mode], " ", _r[d], ",", _r[m], ",#", immediate}; } auto ARM7TDMI::thumbDisassembleSoftwareInterrupt -(uint8 immediate) -> string { +(n8 immediate) -> string { return {"swi #0x", hex(immediate, 2L)}; } auto ARM7TDMI::thumbDisassembleStackMultiple -(uint8 list, uint1 lrpc, uint1 mode) -> string { +(n8 list, n1 lrpc, n1 mode) -> string { string registers; - for(uint m : range(8)) { + for(u32 m : range(8)) { if(list.bit(m)) registers.append(_r[m], ","); } if(lrpc) registers.append(!mode ? "lr," : "pc,"); diff --git a/ares/component/processor/arm7tdmi/instruction.cpp b/ares/component/processor/arm7tdmi/instruction.cpp index 928a8ef1eb..f705ff79f7 100644 --- a/ares/component/processor/arm7tdmi/instruction.cpp +++ b/ares/component/processor/arm7tdmi/instruction.cpp @@ -3,14 +3,14 @@ auto ARM7TDMI::fetch() -> void { pipeline.decode = pipeline.fetch; pipeline.decode.thumb = cpsr().t; - uint sequential = Sequential; + u32 sequential = Sequential; if(pipeline.nonsequential) { pipeline.nonsequential = false; sequential = Nonsequential; } - uint mask = !cpsr().t ? 3 : 1; - uint size = !cpsr().t ? Word : Half; + u32 mask = !cpsr().t ? 3 : 1; + u32 size = !cpsr().t ? Word : Half; r(15).data += size >> 3; pipeline.fetch.address = r(15) & ~mask; @@ -18,8 +18,8 @@ auto ARM7TDMI::fetch() -> void { } auto ARM7TDMI::instruction() -> void { - uint mask = !cpsr().t ? 3 : 1; - uint size = !cpsr().t ? Word : Half; + u32 mask = !cpsr().t ? 3 : 1; + u32 size = !cpsr().t ? Word : Half; if(pipeline.reload) { pipeline.reload = false; @@ -39,14 +39,14 @@ auto ARM7TDMI::instruction() -> void { opcode = pipeline.execute.instruction; if(!pipeline.execute.thumb) { if(!TST(opcode.bit(28,31))) return; - uint12 index = (opcode & 0x0ff00000) >> 16 | (opcode & 0x000000f0) >> 4; + n12 index = (opcode & 0x0ff00000) >> 16 | (opcode & 0x000000f0) >> 4; armInstruction[index](opcode); } else { - thumbInstruction[(uint16)opcode](); + thumbInstruction[(n16)opcode](); } } -auto ARM7TDMI::exception(uint mode, uint32 address) -> void { +auto ARM7TDMI::exception(u32 mode, n32 address) -> void { auto psr = cpsr(); cpsr().m = mode; spsr() = psr; @@ -59,21 +59,21 @@ auto ARM7TDMI::exception(uint mode, uint32 address) -> void { auto ARM7TDMI::armInitialize() -> void { #define bind(id, name, ...) { \ - uint index = (id & 0x0ff00000) >> 16 | (id & 0x000000f0) >> 4; \ + u32 index = (id & 0x0ff00000) >> 16 | (id & 0x000000f0) >> 4; \ assert(!armInstruction[index]); \ - armInstruction[index] = [&](uint32 opcode) { return armInstruction##name(arguments); }; \ - armDisassemble[index] = [&](uint32 opcode) { return armDisassemble##name(arguments); }; \ + armInstruction[index] = [&](n32 opcode) { return armInstruction##name(arguments); }; \ + armDisassemble[index] = [&](n32 opcode) { return armDisassemble##name(arguments); }; \ } #define pattern(s) \ - std::integral_constant::value + std::integral_constant::value #define arguments \ opcode.bit( 0,23), /* displacement */ \ opcode.bit(24) /* link */ - for(uint4 displacementLo : range(16)) - for(uint4 displacementHi : range(16)) - for(uint1 link : range(2)) { + for(n4 displacementLo : range(16)) + for(n4 displacementHi : range(16)) + for(n1 link : range(2)) { auto opcode = pattern(".... 101? ???? ???? ???? ???? ???? ????") | displacementLo << 4 | displacementHi << 20 | link << 24; bind(opcode, Branch); @@ -95,9 +95,9 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(16,19), /* n */ \ opcode.bit(20), /* save */ \ opcode.bit(21,24) /* mode */ - for(uint4 shiftHi : range(16)) - for(uint1 save : range(2)) - for(uint4 mode : range(16)) { + for(n4 shiftHi : range(16)) + for(n1 save : range(2)) + for(n4 mode : range(16)) { if(mode >= 8 && mode <= 11 && !save) continue; //TST, TEQ, CMP, CMN auto opcode = pattern(".... 001? ???? ???? ???? ???? ???? ????") | shiftHi << 4 | save << 20 | mode << 21; bind(opcode, DataImmediate); @@ -112,10 +112,10 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(16,19), /* n */ \ opcode.bit(20), /* save */ \ opcode.bit(21,24) /* mode */ - for(uint2 type : range(4)) - for(uint1 shiftLo : range(2)) - for(uint1 save : range(2)) - for(uint4 mode : range(16)) { + for(n2 type : range(4)) + for(n1 shiftLo : range(2)) + for(n1 save : range(2)) + for(n4 mode : range(16)) { if(mode >= 8 && mode <= 11 && !save) continue; //TST, TEQ, CMP, CMN auto opcode = pattern(".... 000? ???? ???? ???? ???? ???0 ????") | type << 5 | shiftLo << 7 | save << 20 | mode << 21; bind(opcode, DataImmediateShift); @@ -130,9 +130,9 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(16,19), /* n */ \ opcode.bit(20), /* save */ \ opcode.bit(21,24) /* mode */ - for(uint2 type : range(4)) - for(uint1 save : range(2)) - for(uint4 mode : range(16)) { + for(n2 type : range(4)) + for(n1 save : range(2)) + for(n4 mode : range(16)) { if(mode >= 8 && mode <= 11 && !save) continue; //TST, TEQ, CMP, CMN auto opcode = pattern(".... 000? ???? ???? ???? ???? 0??1 ????") | type << 5 | save << 20 | mode << 21; bind(opcode, DataRegisterShift); @@ -147,10 +147,10 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(21), /* writeback */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint1 half : range(2)) - for(uint1 writeback : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n1 half : range(2)) + for(n1 writeback : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 000? ?1?1 ???? ???? ???? 11?1 ????") | half << 5 | writeback << 21 | up << 23 | pre << 24; bind(opcode, LoadImmediate); } @@ -164,10 +164,10 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(21), /* writeback */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint1 half : range(2)) - for(uint1 writeback : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n1 half : range(2)) + for(n1 writeback : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 000? ?0?1 ???? ???? ---- 11?1 ????") | half << 5 | writeback << 21 | up << 23 | pre << 24; bind(opcode, LoadRegister); } @@ -178,7 +178,7 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(12,15), /* d */ \ opcode.bit(16,19), /* n */ \ opcode.bit(22) /* byte */ - for(uint1 byte : range(2)) { + for(n1 byte : range(2)) { auto opcode = pattern(".... 0001 0?00 ???? ???? ---- 1001 ????") | byte << 22; bind(opcode, MemorySwap); } @@ -192,10 +192,10 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(21), /* writeback */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint1 mode : range(2)) - for(uint1 writeback : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n1 mode : range(2)) + for(n1 writeback : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 000? ?1?? ???? ???? ???? 1011 ????") | mode << 20 | writeback << 21 | up << 23 | pre << 24; bind(opcode, MoveHalfImmediate); } @@ -209,10 +209,10 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(21), /* writeback */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint1 mode : range(2)) - for(uint1 writeback : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n1 mode : range(2)) + for(n1 writeback : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 000? ?0?? ???? ???? ---- 1011 ????") | mode << 20 | writeback << 21 | up << 23 | pre << 24; bind(opcode, MoveHalfRegister); } @@ -227,12 +227,12 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(22), /* byte */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint4 immediatePart : range(16)) - for(uint1 mode : range(2)) - for(uint1 writeback : range(2)) - for(uint1 byte : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n4 immediatePart : range(16)) + for(n1 mode : range(2)) + for(n1 writeback : range(2)) + for(n1 byte : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 010? ???? ???? ???? ???? ???? ????") | immediatePart << 4 | mode << 20 | writeback << 21 | byte << 22 | up << 23 | pre << 24; bind(opcode, MoveImmediateOffset); @@ -247,12 +247,12 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(22), /* type */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint4 listPart : range(16)) - for(uint1 mode : range(2)) - for(uint1 writeback : range(2)) - for(uint1 type : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n4 listPart : range(16)) + for(n1 mode : range(2)) + for(n1 writeback : range(2)) + for(n1 type : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 100? ???? ???? ???? ???? ???? ????") | listPart << 4 | mode << 20 | writeback << 21 | type << 22 | up << 23 | pre << 24; bind(opcode, MoveMultiple); @@ -270,13 +270,13 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(22), /* byte */ \ opcode.bit(23), /* up */ \ opcode.bit(24) /* pre */ - for(uint2 type : range(4)) - for(uint1 shiftLo : range(2)) - for(uint1 mode : range(2)) - for(uint1 writeback : range(2)) - for(uint1 byte : range(2)) - for(uint1 up : range(2)) - for(uint1 pre : range(2)) { + for(n2 type : range(4)) + for(n1 shiftLo : range(2)) + for(n1 mode : range(2)) + for(n1 writeback : range(2)) + for(n1 byte : range(2)) + for(n1 up : range(2)) + for(n1 pre : range(2)) { auto opcode = pattern(".... 011? ???? ???? ???? ???? ???0 ????") | type << 5 | shiftLo << 7 | mode << 20 | writeback << 21 | byte << 22 | up << 23 | pre << 24; bind(opcode, MoveRegisterOffset); @@ -286,7 +286,7 @@ auto ARM7TDMI::armInitialize() -> void { #define arguments \ opcode.bit(12,15), /* d */ \ opcode.bit(22) /* mode */ - for(uint1 mode : range(2)) { + for(n1 mode : range(2)) { auto opcode = pattern(".... 0001 0?00 ---- ???? ---- 0000 ----") | mode << 22; bind(opcode, MoveToRegisterFromStatus); } @@ -297,8 +297,8 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit( 8,11), /* rotate */ \ opcode.bit(16,19), /* field */ \ opcode.bit(22) /* mode */ - for(uint4 immediateHi : range(16)) - for(uint1 mode : range(2)) { + for(n4 immediateHi : range(16)) + for(n1 mode : range(2)) { auto opcode = pattern(".... 0011 0?10 ???? ---- ???? ???? ????") | immediateHi << 4 | mode << 22; bind(opcode, MoveToStatusFromImmediate); } @@ -308,7 +308,7 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit( 0, 3), /* m */ \ opcode.bit(16,19), /* field */ \ opcode.bit(22) /* mode */ - for(uint1 mode : range(2)) { + for(n1 mode : range(2)) { auto opcode = pattern(".... 0001 0?10 ???? ---- ---- 0000 ????") | mode << 22; bind(opcode, MoveToStatusFromRegister); } @@ -321,8 +321,8 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(16,19), /* d */ \ opcode.bit(20), /* save */ \ opcode.bit(21) /* accumulate */ - for(uint1 save : range(2)) - for(uint1 accumulate : range(2)) { + for(n1 save : range(2)) + for(n1 accumulate : range(2)) { auto opcode = pattern(".... 0000 00?? ???? ???? ???? 1001 ????") | save << 20 | accumulate << 21; bind(opcode, Multiply); } @@ -336,9 +336,9 @@ auto ARM7TDMI::armInitialize() -> void { opcode.bit(20), /* save */ \ opcode.bit(21), /* accumulate */ \ opcode.bit(22) /* sign */ - for(uint1 save : range(2)) - for(uint1 accumulate : range(2)) - for(uint1 sign : range(2)) { + for(n1 save : range(2)) + for(n1 accumulate : range(2)) + for(n1 sign : range(2)) { auto opcode = pattern(".... 0000 1??? ???? ???? ???? 1001 ????") | save << 20 | accumulate << 21 | sign << 22; bind(opcode, MultiplyLong); } @@ -346,15 +346,15 @@ auto ARM7TDMI::armInitialize() -> void { #define arguments \ opcode.bit( 0,23) /* immediate */ - for(uint4 immediateLo : range(16)) - for(uint4 immediateHi : range(16)) { + for(n4 immediateLo : range(16)) + for(n4 immediateHi : range(16)) { auto opcode = pattern(".... 1111 ???? ???? ???? ???? ???? ????") | immediateLo << 4 | immediateHi << 20; bind(opcode, SoftwareInterrupt); } #undef arguments #define arguments - for(uint12 id : range(4096)) { + for(n12 id : range(4096)) { if(armInstruction[id]) continue; auto opcode = pattern(".... ???? ???? ---- ---- ---- ???? ----") | id.bit(0,3) << 4 | id.bit(4,11) << 20; bind(opcode, Undefined); @@ -373,161 +373,161 @@ auto ARM7TDMI::thumbInitialize() -> void { } #define pattern(s) \ - std::integral_constant::value + std::integral_constant::value - for(uint3 d : range(8)) - for(uint3 m : range(8)) - for(uint4 mode : range(16)) { + for(n3 d : range(8)) + for(n3 m : range(8)) + for(n4 mode : range(16)) { auto opcode = pattern("0100 00?? ???? ????") | d << 0 | m << 3 | mode << 6; bind(opcode, ALU, d, m, mode); } - for(uint4 d : range(16)) - for(uint4 m : range(16)) - for(uint2 mode : range(4)) { + for(n4 d : range(16)) + for(n4 m : range(16)) + for(n2 mode : range(4)) { if(mode == 3) continue; auto opcode = pattern("0100 01?? ???? ????") | d.bit(0,2) << 0 | m << 3 | d.bit(3) << 7 | mode << 8; bind(opcode, ALUExtended, d, m, mode); } - for(uint8 immediate : range(256)) - for(uint3 d : range(8)) - for(uint1 mode : range(2)) { + for(n8 immediate : range(256)) + for(n3 d : range(8)) + for(n1 mode : range(2)) { auto opcode = pattern("1010 ???? ???? ????") | immediate << 0 | d << 8 | mode << 11; bind(opcode, AddRegister, immediate, d, mode); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint3 immediate : range(8)) - for(uint1 mode : range(2)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n3 immediate : range(8)) + for(n1 mode : range(2)) { auto opcode = pattern("0001 11?? ???? ????") | d << 0 | n << 3 | immediate << 6 | mode << 9; bind(opcode, AdjustImmediate, d, n, immediate, mode); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint3 m : range(8)) - for(uint1 mode : range(2)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n3 m : range(8)) + for(n1 mode : range(2)) { auto opcode = pattern("0001 10?? ???? ????") | d << 0 | n << 3 | m << 6 | mode << 9; bind(opcode, AdjustRegister, d, n, m, mode); } - for(uint7 immediate : range(128)) - for(uint1 mode : range(2)) { + for(n7 immediate : range(128)) + for(n1 mode : range(2)) { auto opcode = pattern("1011 0000 ???? ????") | immediate << 0 | mode << 7; bind(opcode, AdjustStack, immediate, mode); } - for(uint3 _ : range(8)) - for(uint4 m : range(16)) { + for(n3 _ : range(8)) + for(n4 m : range(16)) { auto opcode = pattern("0100 0111 0??? ?---") | _ << 0 | m << 3; bind(opcode, BranchExchange, m); } - for(uint11 displacement : range(2048)) { + for(n11 displacement : range(2048)) { auto opcode = pattern("1111 0??? ???? ????") | displacement << 0; bind(opcode, BranchFarPrefix, displacement); } - for(uint11 displacement : range(2048)) { + for(n11 displacement : range(2048)) { auto opcode = pattern("1111 1??? ???? ????") | displacement << 0; bind(opcode, BranchFarSuffix, displacement); } - for(uint11 displacement : range(2048)) { + for(n11 displacement : range(2048)) { auto opcode = pattern("1110 0??? ???? ????") | displacement << 0; bind(opcode, BranchNear, displacement); } - for(uint8 displacement : range(256)) - for(uint4 condition : range(16)) { + for(n8 displacement : range(256)) + for(n4 condition : range(16)) { if(condition == 15) continue; //BNV auto opcode = pattern("1101 ???? ???? ????") | displacement << 0 | condition << 8; bind(opcode, BranchTest, displacement, condition); } - for(uint8 immediate : range(256)) - for(uint3 d : range(8)) - for(uint2 mode : range(4)) { + for(n8 immediate : range(256)) + for(n3 d : range(8)) + for(n2 mode : range(4)) { auto opcode = pattern("001? ???? ???? ????") | immediate << 0 | d << 8 | mode << 11; bind(opcode, Immediate, immediate, d, mode); } - for(uint8 displacement : range(256)) - for(uint3 d : range(8)) { + for(n8 displacement : range(256)) + for(n3 d : range(8)) { auto opcode = pattern("0100 1??? ???? ????") | displacement << 0 | d << 8; bind(opcode, LoadLiteral, displacement, d); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint5 immediate : range(32)) - for(uint1 mode : range(2)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n5 immediate : range(32)) + for(n1 mode : range(2)) { auto opcode = pattern("0111 ???? ???? ????") | d << 0 | n << 3 | immediate << 6 | mode << 11; bind(opcode, MoveByteImmediate, d, n, immediate, mode); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint5 immediate : range(32)) - for(uint1 mode : range(2)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n5 immediate : range(32)) + for(n1 mode : range(2)) { auto opcode = pattern("1000 ???? ???? ????") | d << 0 | n << 3 | immediate << 6 | mode << 11; bind(opcode, MoveHalfImmediate, d, n, immediate, mode); } - for(uint8 list : range(256)) - for(uint3 n : range(8)) - for(uint1 mode : range(2)) { + for(n8 list : range(256)) + for(n3 n : range(8)) + for(n1 mode : range(2)) { auto opcode = pattern("1100 ???? ???? ????") | list << 0 | n << 8 | mode << 11; bind(opcode, MoveMultiple, list, n, mode); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint3 m : range(8)) - for(uint3 mode : range(8)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n3 m : range(8)) + for(n3 mode : range(8)) { auto opcode = pattern("0101 ???? ???? ????") | d << 0 | n << 3 | m << 6 | mode << 9; bind(opcode, MoveRegisterOffset, d, n, m, mode); } - for(uint8 immediate : range(256)) - for(uint3 d : range(8)) - for(uint1 mode : range(2)) { + for(n8 immediate : range(256)) + for(n3 d : range(8)) + for(n1 mode : range(2)) { auto opcode = pattern("1001 ???? ???? ????") | immediate << 0 | d << 8 | mode << 11; bind(opcode, MoveStack, immediate, d, mode); } - for(uint3 d : range(8)) - for(uint3 n : range(8)) - for(uint5 offset : range(32)) - for(uint1 mode : range(2)) { + for(n3 d : range(8)) + for(n3 n : range(8)) + for(n5 offset : range(32)) + for(n1 mode : range(2)) { auto opcode = pattern("0110 ???? ???? ????") | d << 0 | n << 3 | offset << 6 | mode << 11; bind(opcode, MoveWordImmediate, d, n, offset, mode); } - for(uint3 d : range(8)) - for(uint3 m : range(8)) - for(uint5 immediate : range(32)) - for(uint2 mode : range(4)) { + for(n3 d : range(8)) + for(n3 m : range(8)) + for(n5 immediate : range(32)) + for(n2 mode : range(4)) { if(mode == 3) continue; auto opcode = pattern("000? ???? ???? ????") | d << 0 | m << 3 | immediate << 6 | mode << 11; bind(opcode, ShiftImmediate, d, m, immediate, mode); } - for(uint8 immediate : range(256)) { + for(n8 immediate : range(256)) { auto opcode = pattern("1101 1111 ???? ????") | immediate << 0; bind(opcode, SoftwareInterrupt, immediate); } - for(uint8 list : range(256)) - for(uint1 lrpc : range(2)) - for(uint1 mode : range(2)) { + for(n8 list : range(256)) + for(n1 lrpc : range(2)) + for(n1 mode : range(2)) { auto opcode = pattern("1011 ?10? ???? ????") | list << 0 | lrpc << 8 | mode << 11; bind(opcode, StackMultiple, list, lrpc, mode); } - for(uint16 id : range(65536)) { + for(n16 id : range(65536)) { if(thumbInstruction[id]) continue; auto opcode = pattern("???? ???? ???? ????") | id << 0; bind(opcode, Undefined); diff --git a/ares/component/processor/arm7tdmi/instructions-arm.cpp b/ares/component/processor/arm7tdmi/instructions-arm.cpp index 4e4ad8170e..cc1ef269c7 100644 --- a/ares/component/processor/arm7tdmi/instructions-arm.cpp +++ b/ares/component/processor/arm7tdmi/instructions-arm.cpp @@ -1,5 +1,5 @@ -auto ARM7TDMI::armALU(uint4 mode, uint4 d, uint4 n, uint32 rm) -> void { - uint32 rn = r(n); +auto ARM7TDMI::armALU(n4 mode, n4 d, n4 n, n32 rm) -> void { + n32 rn = r(n); switch(mode) { case 0: r(d) = BIT(rn & rm); break; //AND @@ -25,7 +25,7 @@ auto ARM7TDMI::armALU(uint4 mode, uint4 d, uint4 n, uint32 rm) -> void { } } -auto ARM7TDMI::armMoveToStatus(uint4 field, uint1 mode, uint32 data) -> void { +auto ARM7TDMI::armMoveToStatus(n4 field, n1 mode, n32 data) -> void { if(mode && (cpsr().m == PSR::USR || cpsr().m == PSR::SYS)) return; PSR& psr = mode ? spsr() : cpsr(); @@ -50,35 +50,35 @@ auto ARM7TDMI::armMoveToStatus(uint4 field, uint1 mode, uint32 data) -> void { // auto ARM7TDMI::armInstructionBranch -(int24 displacement, uint1 link) -> void { +(i24 displacement, n1 link) -> void { if(link) r(14) = r(15) - 4; r(15) = r(15) + displacement * 4; } auto ARM7TDMI::armInstructionBranchExchangeRegister -(uint4 m) -> void { - uint32 address = r(m); +(n4 m) -> void { + n32 address = r(m); cpsr().t = address.bit(0); r(15) = address; } auto ARM7TDMI::armInstructionDataImmediate -(uint8 immediate, uint4 shift, uint4 d, uint4 n, uint1 save, uint4 mode) -> void { - uint32 data = immediate; +(n8 immediate, n4 shift, n4 d, n4 n, n1 save, n4 mode) -> void { + n32 data = immediate; carry = cpsr().c; if(shift) data = ROR(data, shift << 1); armALU(mode, d, n, data); } auto ARM7TDMI::armInstructionDataImmediateShift -(uint4 m, uint2 type, uint5 shift, uint4 d, uint4 n, uint1 save, uint4 mode) -> void { - uint32 rm = r(m); +(n4 m, n2 type, n5 shift, n4 d, n4 n, n1 save, n4 mode) -> void { + n32 rm = r(m); carry = cpsr().c; switch(type) { case 0: rm = LSL(rm, shift); break; - case 1: rm = LSR(rm, shift ? (uint)shift : 32); break; - case 2: rm = ASR(rm, shift ? (uint)shift : 32); break; + case 1: rm = LSR(rm, shift ? (u32)shift : 32); break; + case 2: rm = ASR(rm, shift ? (u32)shift : 32); break; case 3: rm = shift ? ROR(rm, shift) : RRX(rm); break; } @@ -86,25 +86,25 @@ auto ARM7TDMI::armInstructionDataImmediateShift } auto ARM7TDMI::armInstructionDataRegisterShift -(uint4 m, uint2 type, uint4 s, uint4 d, uint4 n, uint1 save, uint4 mode) -> void { - uint8 rs = r(s) + (s == 15 ? 4 : 0); - uint32 rm = r(m) + (m == 15 ? 4 : 0); +(n4 m, n2 type, n4 s, n4 d, n4 n, n1 save, n4 mode) -> void { + n8 rs = r(s) + (s == 15 ? 4 : 0); + n32 rm = r(m) + (m == 15 ? 4 : 0); carry = cpsr().c; switch(type) { - case 0: rm = LSL(rm, rs < 33 ? rs : (uint8)33); break; - case 1: rm = LSR(rm, rs < 33 ? rs : (uint8)33); break; - case 2: rm = ASR(rm, rs < 32 ? rs : (uint8)32); break; - case 3: if(rs) rm = ROR(rm, rs & 31 ? uint(rs & 31) : 32); break; + case 0: rm = LSL(rm, rs < 33 ? rs : (n8)33); break; + case 1: rm = LSR(rm, rs < 33 ? rs : (n8)33); break; + case 2: rm = ASR(rm, rs < 32 ? rs : (n8)32); break; + case 3: if(rs) rm = ROR(rm, rs & 31 ? u32(rs & 31) : 32); break; } armALU(mode, d, n, rm); } auto ARM7TDMI::armInstructionLoadImmediate -(uint8 immediate, uint1 half, uint4 d, uint4 n, uint1 writeback, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); - uint32 rd = r(d); +(n8 immediate, n1 half, n4 d, n4 n, n1 writeback, n1 up, n1 pre) -> void { + n32 rn = r(n); + n32 rd = r(d); if(pre == 1) rn = up ? rn + immediate : rn - immediate; rd = load((half ? Half : Byte) | Nonsequential | Signed, rn); @@ -115,10 +115,10 @@ auto ARM7TDMI::armInstructionLoadImmediate } auto ARM7TDMI::armInstructionLoadRegister -(uint4 m, uint1 half, uint4 d, uint4 n, uint1 writeback, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); - uint32 rm = r(m); - uint32 rd = r(d); +(n4 m, n1 half, n4 d, n4 n, n1 writeback, n1 up, n1 pre) -> void { + n32 rn = r(n); + n32 rm = r(m); + n32 rd = r(d); if(pre == 1) rn = up ? rn + rm : rn - rm; rd = load((half ? Half : Byte) | Nonsequential | Signed, rn); @@ -129,16 +129,16 @@ auto ARM7TDMI::armInstructionLoadRegister } auto ARM7TDMI::armInstructionMemorySwap -(uint4 m, uint4 d, uint4 n, uint1 byte) -> void { - uint32 word = load((byte ? Byte : Word) | Nonsequential, r(n)); +(n4 m, n4 d, n4 n, n1 byte) -> void { + n32 word = load((byte ? Byte : Word) | Nonsequential, r(n)); store((byte ? Byte : Word) | Nonsequential, r(n), r(m)); r(d) = word; } auto ARM7TDMI::armInstructionMoveHalfImmediate -(uint8 immediate, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); - uint32 rd = r(d); +(n8 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 up, n1 pre) -> void { + n32 rn = r(n); + n32 rd = r(d); if(pre == 1) rn = up ? rn + immediate : rn - immediate; if(mode == 1) rd = load(Half | Nonsequential, rn); @@ -150,10 +150,10 @@ auto ARM7TDMI::armInstructionMoveHalfImmediate } auto ARM7TDMI::armInstructionMoveHalfRegister -(uint4 m, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); - uint32 rm = r(m); - uint32 rd = r(d); +(n4 m, n4 d, n4 n, n1 mode, n1 writeback, n1 up, n1 pre) -> void { + n32 rn = r(n); + n32 rm = r(m); + n32 rd = r(d); if(pre == 1) rn = up ? rn + rm : rn - rm; if(mode == 1) rd = load(Half | Nonsequential, rn); @@ -165,9 +165,9 @@ auto ARM7TDMI::armInstructionMoveHalfRegister } auto ARM7TDMI::armInstructionMoveImmediateOffset -(uint12 immediate, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 byte, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); - uint32 rd = r(d); +(n12 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 byte, n1 up, n1 pre) -> void { + n32 rn = r(n); + n32 rd = r(d); if(pre == 1) rn = up ? rn + immediate : rn - immediate; if(mode == 1) rd = load((byte ? Byte : Word) | Nonsequential, rn); @@ -179,8 +179,8 @@ auto ARM7TDMI::armInstructionMoveImmediateOffset } auto ARM7TDMI::armInstructionMoveMultiple -(uint16 list, uint4 n, uint1 mode, uint1 writeback, uint1 type, uint1 up, uint1 pre) -> void { - uint32 rn = r(n); +(n16 list, n4 n, n1 mode, n1 writeback, n1 type, n1 up, n1 pre) -> void { + n32 rn = r(n); if(pre == 0 && up == 1) rn = rn + 0; //IA if(pre == 1 && up == 1) rn = rn + 4; //IB if(pre == 1 && up == 0) rn = rn - bit::count(list) * 4 + 0; //DB @@ -197,8 +197,8 @@ auto ARM7TDMI::armInstructionMoveMultiple if(type && mode == 0) usr = true; if(usr) cpsr().m = PSR::USR; - uint sequential = Nonsequential; - for(uint m : range(16)) { + u32 sequential = Nonsequential; + for(u32 m : range(16)) { if(!list.bit(m)) continue; if(mode == 1) r(m) = read(Word | sequential, rn); if(mode == 0) write(Word | sequential, rn, r(m)); @@ -224,16 +224,16 @@ auto ARM7TDMI::armInstructionMoveMultiple } auto ARM7TDMI::armInstructionMoveRegisterOffset -(uint4 m, uint2 type, uint5 shift, uint4 d, uint4 n, uint1 mode, uint1 writeback, uint1 byte, uint1 up, uint1 pre) -> void { - uint32 rm = r(m); - uint32 rd = r(d); - uint32 rn = r(n); +(n4 m, n2 type, n5 shift, n4 d, n4 n, n1 mode, n1 writeback, n1 byte, n1 up, n1 pre) -> void { + n32 rm = r(m); + n32 rd = r(d); + n32 rn = r(n); carry = cpsr().c; switch(type) { case 0: rm = LSL(rm, shift); break; - case 1: rm = LSR(rm, shift ? (uint)shift : 32); break; - case 2: rm = ASR(rm, shift ? (uint)shift : 32); break; + case 1: rm = LSR(rm, shift ? (u32)shift : 32); break; + case 2: rm = ASR(rm, shift ? (u32)shift : 32); break; case 3: rm = shift ? ROR(rm, shift) : RRX(rm); break; } @@ -247,33 +247,33 @@ auto ARM7TDMI::armInstructionMoveRegisterOffset } auto ARM7TDMI::armInstructionMoveToRegisterFromStatus -(uint4 d, uint1 mode) -> void { +(n4 d, n1 mode) -> void { if(mode && (cpsr().m == PSR::USR || cpsr().m == PSR::SYS)) return; r(d) = mode ? spsr() : cpsr(); } auto ARM7TDMI::armInstructionMoveToStatusFromImmediate -(uint8 immediate, uint4 rotate, uint4 field, uint1 mode) -> void { - uint32 data = immediate; +(n8 immediate, n4 rotate, n4 field, n1 mode) -> void { + n32 data = immediate; if(rotate) data = ROR(data, rotate << 1); armMoveToStatus(field, mode, data); } auto ARM7TDMI::armInstructionMoveToStatusFromRegister -(uint4 m, uint4 field, uint1 mode) -> void { +(n4 m, n4 field, n1 mode) -> void { armMoveToStatus(field, mode, r(m)); } auto ARM7TDMI::armInstructionMultiply -(uint4 m, uint4 s, uint4 n, uint4 d, uint1 save, uint1 accumulate) -> void { +(n4 m, n4 s, n4 n, n4 d, n1 save, n1 accumulate) -> void { if(accumulate) idle(); r(d) = MUL(accumulate ? r(n) : 0, r(m), r(s)); } auto ARM7TDMI::armInstructionMultiplyLong -(uint4 m, uint4 s, uint4 l, uint4 h, uint1 save, uint1 accumulate, uint1 sign) -> void { - uint64 rm = r(m); - uint64 rs = r(s); +(n4 m, n4 s, n4 l, n4 h, n1 save, n1 accumulate, n1 sign) -> void { + n64 rm = r(m); + n64 rs = r(s); idle(); idle(); @@ -283,16 +283,16 @@ auto ARM7TDMI::armInstructionMultiplyLong if(rs >> 8 && rs >> 8 != 0xffffff) idle(); if(rs >> 16 && rs >> 16 != 0xffff) idle(); if(rs >> 24 && rs >> 24 != 0xff) idle(); - rm = (int32)rm; - rs = (int32)rs; + rm = (i32)rm; + rs = (i32)rs; } else { if(rs >> 8) idle(); if(rs >> 16) idle(); if(rs >> 24) idle(); } - uint64 rd = rm * rs; - if(accumulate) rd += (uint64)r(h) << 32 | (uint64)r(l) << 0; + n64 rd = rm * rs; + if(accumulate) rd += (n64)r(h) << 32 | (n64)r(l) << 0; r(h) = rd >> 32; r(l) = rd >> 0; @@ -304,7 +304,7 @@ auto ARM7TDMI::armInstructionMultiplyLong } auto ARM7TDMI::armInstructionSoftwareInterrupt -(uint24 immediate) -> void { +(n24 immediate) -> void { exception(PSR::SVC, 0x08); } diff --git a/ares/component/processor/arm7tdmi/instructions-thumb.cpp b/ares/component/processor/arm7tdmi/instructions-thumb.cpp index 628a5dc650..2ad2e692e0 100644 --- a/ares/component/processor/arm7tdmi/instructions-thumb.cpp +++ b/ares/component/processor/arm7tdmi/instructions-thumb.cpp @@ -1,5 +1,5 @@ auto ARM7TDMI::thumbInstructionALU -(uint3 d, uint3 m, uint4 mode) -> void { +(n3 d, n3 m, n4 mode) -> void { switch(mode) { case 0: r(d) = BIT(r(d) & r(m)); break; //AND case 1: r(d) = BIT(r(d) ^ r(m)); break; //EOR @@ -21,7 +21,7 @@ auto ARM7TDMI::thumbInstructionALU } auto ARM7TDMI::thumbInstructionALUExtended -(uint4 d, uint4 m, uint2 mode) -> void { +(n4 d, n4 m, n2 mode) -> void { switch(mode) { case 0: r(d) = r(d) + r(m); break; //ADD case 1: SUB(r(d), r(m), 1); break; //SUBS @@ -30,7 +30,7 @@ auto ARM7TDMI::thumbInstructionALUExtended } auto ARM7TDMI::thumbInstructionAddRegister -(uint8 immediate, uint3 d, uint1 mode) -> void { +(n8 immediate, n3 d, n1 mode) -> void { switch(mode) { case 0: r(d) = (r(15) & ~3) + immediate * 4; break; //ADD pc case 1: r(d) = r(13) + immediate * 4; break; //ADD sp @@ -38,7 +38,7 @@ auto ARM7TDMI::thumbInstructionAddRegister } auto ARM7TDMI::thumbInstructionAdjustImmediate -(uint3 d, uint3 n, uint3 immediate, uint1 mode) -> void { +(n3 d, n3 n, n3 immediate, n1 mode) -> void { switch(mode) { case 0: r(d) = ADD(r(n), immediate, 0); break; //ADD case 1: r(d) = SUB(r(n), immediate, 1); break; //SUB @@ -46,7 +46,7 @@ auto ARM7TDMI::thumbInstructionAdjustImmediate } auto ARM7TDMI::thumbInstructionAdjustRegister -(uint3 d, uint3 n, uint3 m, uint1 mode) -> void { +(n3 d, n3 n, n3 m, n1 mode) -> void { switch(mode) { case 0: r(d) = ADD(r(n), r(m), 0); break; //ADD case 1: r(d) = SUB(r(n), r(m), 1); break; //SUB @@ -54,7 +54,7 @@ auto ARM7TDMI::thumbInstructionAdjustRegister } auto ARM7TDMI::thumbInstructionAdjustStack -(uint7 immediate, uint1 mode) -> void { +(n7 immediate, n1 mode) -> void { switch(mode) { case 0: r(13) = r(13) + immediate * 4; break; //ADD case 1: r(13) = r(13) - immediate * 4; break; //SUB @@ -62,36 +62,36 @@ auto ARM7TDMI::thumbInstructionAdjustStack } auto ARM7TDMI::thumbInstructionBranchExchange -(uint4 m) -> void { - uint32 address = r(m); +(n4 m) -> void { + n32 address = r(m); cpsr().t = address.bit(0); r(15) = address; } auto ARM7TDMI::thumbInstructionBranchFarPrefix -(int11 displacement) -> void { +(i11 displacement) -> void { r(14) = r(15) + (displacement * 2 << 11); } auto ARM7TDMI::thumbInstructionBranchFarSuffix -(uint11 displacement) -> void { +(n11 displacement) -> void { r(15) = r(14) + (displacement * 2); r(14) = pipeline.decode.address | 1; } auto ARM7TDMI::thumbInstructionBranchNear -(int11 displacement) -> void { +(i11 displacement) -> void { r(15) = r(15) + displacement * 2; } auto ARM7TDMI::thumbInstructionBranchTest -(int8 displacement, uint4 condition) -> void { +(i8 displacement, n4 condition) -> void { if(!TST(condition)) return; r(15) = r(15) + displacement * 2; } auto ARM7TDMI::thumbInstructionImmediate -(uint8 immediate, uint3 d, uint2 mode) -> void { +(n8 immediate, n3 d, n2 mode) -> void { switch(mode) { case 0: r(d) = BIT(immediate); break; //MOV case 1: SUB(r(d), immediate, 1); break; //CMP @@ -101,13 +101,13 @@ auto ARM7TDMI::thumbInstructionImmediate } auto ARM7TDMI::thumbInstructionLoadLiteral -(uint8 displacement, uint3 d) -> void { - uint32 address = (r(15) & ~3) + (displacement << 2); +(n8 displacement, n3 d) -> void { + n32 address = (r(15) & ~3) + (displacement << 2); r(d) = load(Word | Nonsequential, address); } auto ARM7TDMI::thumbInstructionMoveByteImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> void { +(n3 d, n3 n, n5 offset, n1 mode) -> void { switch(mode) { case 0: store(Byte | Nonsequential, r(n) + offset, r(d)); break; //STRB case 1: r(d) = load(Byte | Nonsequential, r(n) + offset); break; //LDRB @@ -115,7 +115,7 @@ auto ARM7TDMI::thumbInstructionMoveByteImmediate } auto ARM7TDMI::thumbInstructionMoveHalfImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> void { +(n3 d, n3 n, n5 offset, n1 mode) -> void { switch(mode) { case 0: store(Half | Nonsequential, r(n) + offset * 2, r(d)); break; //STRH case 1: r(d) = load(Half | Nonsequential, r(n) + offset * 2); break; //LDRH @@ -123,10 +123,10 @@ auto ARM7TDMI::thumbInstructionMoveHalfImmediate } auto ARM7TDMI::thumbInstructionMoveMultiple -(uint8 list, uint3 n, uint1 mode) -> void { - uint32 rn = r(n); +(n8 list, n3 n, n1 mode) -> void { + n32 rn = r(n); - for(uint m : range(8)) { + for(u32 m : range(8)) { if(!list.bit(m)) continue; switch(mode) { case 0: write(Word | Nonsequential, rn, r(m)); break; //STMIA @@ -140,7 +140,7 @@ auto ARM7TDMI::thumbInstructionMoveMultiple } auto ARM7TDMI::thumbInstructionMoveRegisterOffset -(uint3 d, uint3 n, uint3 m, uint3 mode) -> void { +(n3 d, n3 n, n3 m, n3 mode) -> void { switch(mode) { case 0: store(Word | Nonsequential, r(n) + r(m), r(d)); break; //STR case 1: store(Half | Nonsequential, r(n) + r(m), r(d)); break; //STRH @@ -154,7 +154,7 @@ auto ARM7TDMI::thumbInstructionMoveRegisterOffset } auto ARM7TDMI::thumbInstructionMoveStack -(uint8 immediate, uint3 d, uint1 mode) -> void { +(n8 immediate, n3 d, n1 mode) -> void { switch(mode) { case 0: store(Word | Nonsequential, r(13) + immediate * 4, r(d)); break; //STR case 1: r(d) = load(Word | Nonsequential, r(13) + immediate * 4); break; //LDR @@ -162,7 +162,7 @@ auto ARM7TDMI::thumbInstructionMoveStack } auto ARM7TDMI::thumbInstructionMoveWordImmediate -(uint3 d, uint3 n, uint5 offset, uint1 mode) -> void { +(n3 d, n3 n, n5 offset, n1 mode) -> void { switch(mode) { case 0: store(Word | Nonsequential, r(n) + offset * 4, r(d)); break; //STR case 1: r(d) = load(Word | Nonsequential, r(n) + offset * 4); break; //LDR @@ -170,29 +170,29 @@ auto ARM7TDMI::thumbInstructionMoveWordImmediate } auto ARM7TDMI::thumbInstructionShiftImmediate -(uint3 d, uint3 m, uint5 immediate, uint2 mode) -> void { +(n3 d, n3 m, n5 immediate, n2 mode) -> void { switch(mode) { case 0: r(d) = BIT(LSL(r(m), immediate)); break; //LSL - case 1: r(d) = BIT(LSR(r(m), immediate ? (uint)immediate : 32)); break; //LSR - case 2: r(d) = BIT(ASR(r(m), immediate ? (uint)immediate : 32)); break; //ASR + case 1: r(d) = BIT(LSR(r(m), immediate ? (u32)immediate : 32)); break; //LSR + case 2: r(d) = BIT(ASR(r(m), immediate ? (u32)immediate : 32)); break; //ASR } } auto ARM7TDMI::thumbInstructionSoftwareInterrupt -(uint8 immediate) -> void { +(n8 immediate) -> void { exception(PSR::SVC, 0x08); } auto ARM7TDMI::thumbInstructionStackMultiple -(uint8 list, uint1 lrpc, uint1 mode) -> void { - uint32 sp; +(n8 list, n1 lrpc, n1 mode) -> void { + n32 sp; switch(mode) { case 0: sp = r(13) - (bit::count(list) + lrpc) * 4; break; //PUSH case 1: sp = r(13); //POP } - uint sequential = Nonsequential; - for(uint m : range(8)) { + u32 sequential = Nonsequential; + for(u32 m : range(8)) { if(!list.bit(m)) continue; switch(mode) { case 0: write(Word | sequential, sp, r(m)); break; //PUSH diff --git a/ares/component/processor/arm7tdmi/memory.cpp b/ares/component/processor/arm7tdmi/memory.cpp index 9719ca0367..e6c6e6b7f1 100644 --- a/ares/component/processor/arm7tdmi/memory.cpp +++ b/ares/component/processor/arm7tdmi/memory.cpp @@ -3,20 +3,20 @@ auto ARM7TDMI::idle() -> void { sleep(); } -auto ARM7TDMI::read(uint mode, uint32 address) -> uint32 { +auto ARM7TDMI::read(u32 mode, n32 address) -> n32 { return get(mode, address); } -auto ARM7TDMI::load(uint mode, uint32 address) -> uint32 { +auto ARM7TDMI::load(u32 mode, n32 address) -> n32 { pipeline.nonsequential = true; auto word = get(Load | mode, address); if(mode & Half) { address &= 1; - word = mode & Signed ? (uint32)(int16)word : (uint32)(uint16)word; + word = mode & Signed ? (n32)(i16)word : (n32)(n16)word; } if(mode & Byte) { address &= 0; - word = mode & Signed ? (uint32)(int8)word : (uint32)(uint8)word; + word = mode & Signed ? (n32)(i8)word : (n32)(n8)word; } if(mode & Signed) { word = ASR(word, address.bit(0,1) << 3); @@ -27,12 +27,12 @@ auto ARM7TDMI::load(uint mode, uint32 address) -> uint32 { return word; } -auto ARM7TDMI::write(uint mode, uint32 address, uint32 word) -> void { +auto ARM7TDMI::write(u32 mode, n32 address, n32 word) -> void { pipeline.nonsequential = true; return set(mode, address, word); } -auto ARM7TDMI::store(uint mode, uint32 address, uint32 word) -> void { +auto ARM7TDMI::store(u32 mode, n32 address, n32 word) -> void { pipeline.nonsequential = true; if(mode & Half) { word &= 0xffff; word |= word << 16; } if(mode & Byte) { word &= 0xff; word |= word << 8; word |= word << 16; } diff --git a/ares/component/processor/arm7tdmi/registers.cpp b/ares/component/processor/arm7tdmi/registers.cpp index b3792f48e5..1c6513de26 100644 --- a/ares/component/processor/arm7tdmi/registers.cpp +++ b/ares/component/processor/arm7tdmi/registers.cpp @@ -1,4 +1,4 @@ -inline auto ARM7TDMI::r(uint4 index) -> GPR& { +inline auto ARM7TDMI::r(n4 index) -> GPR& { switch(index) { case 0: return processor.r0; case 1: return processor.r1; diff --git a/ares/component/processor/gsu/disassembler.cpp b/ares/component/processor/gsu/disassembler.cpp index f4864ea9d7..1d34dc2ccf 100644 --- a/ares/component/processor/gsu/disassembler.cpp +++ b/ares/component/processor/gsu/disassembler.cpp @@ -7,7 +7,7 @@ auto GSU::disassembleInstruction() -> string { auto GSU::disassembleContext() -> string { string s; - for(uint n : range(16)) { + for(u32 n : range(16)) { s.append("r", n, ":", hex(regs.r[n].data, 4L), " "); } @@ -26,7 +26,7 @@ auto GSU::disassembleOpcode(char* output) -> void { case 3: disassembleALT3(output); break; } - uint length = strlen(output); + u32 length = strlen(output); while(length++ < 20) strcat(output, " "); } @@ -56,17 +56,17 @@ auto GSU::disassembleALT0(char* output) -> void { case (0x02): sprintf(t, "cache"); break; case (0x03): sprintf(t, "lsr"); break; case (0x04): sprintf(t, "rol"); break; - case (0x05): sprintf(t, "bra %+d", (int8_t)op1); break; - case (0x06): sprintf(t, "blt %+d", (int8_t)op1); break; - case (0x07): sprintf(t, "bge %+d", (int8_t)op1); break; - case (0x08): sprintf(t, "bne %+d", (int8_t)op1); break; - case (0x09): sprintf(t, "beq %+d", (int8_t)op1); break; - case (0x0a): sprintf(t, "bpl %+d", (int8_t)op1); break; - case (0x0b): sprintf(t, "bmi %+d", (int8_t)op1); break; - case (0x0c): sprintf(t, "bcc %+d", (int8_t)op1); break; - case (0x0d): sprintf(t, "bcs %+d", (int8_t)op1); break; - case (0x0e): sprintf(t, "bvc %+d", (int8_t)op1); break; - case (0x0f): sprintf(t, "bvs %+d", (int8_t)op1); break; + case (0x05): sprintf(t, "bra %+d", (s8)op1); break; + case (0x06): sprintf(t, "blt %+d", (s8)op1); break; + case (0x07): sprintf(t, "bge %+d", (s8)op1); break; + case (0x08): sprintf(t, "bne %+d", (s8)op1); break; + case (0x09): sprintf(t, "beq %+d", (s8)op1); break; + case (0x0a): sprintf(t, "bpl %+d", (s8)op1); break; + case (0x0b): sprintf(t, "bmi %+d", (s8)op1); break; + case (0x0c): sprintf(t, "bcc %+d", (s8)op1); break; + case (0x0d): sprintf(t, "bcs %+d", (s8)op1); break; + case (0x0e): sprintf(t, "bvc %+d", (s8)op1); break; + case (0x0f): sprintf(t, "bvs %+d", (s8)op1); break; case16(0x10): sprintf(t, "to r%u", op0 & 15); break; case16(0x20): sprintf(t, "with r%u", op0 & 15); break; case12(0x30): sprintf(t, "stw (r%u)", op0 & 15); break; @@ -113,17 +113,17 @@ auto GSU::disassembleALT1(char* output) -> void { case (0x02): sprintf(t, "cache"); break; case (0x03): sprintf(t, "lsr"); break; case (0x04): sprintf(t, "rol"); break; - case (0x05): sprintf(t, "bra %+d", (int8_t)op1); break; - case (0x06): sprintf(t, "blt %+d", (int8_t)op1); break; - case (0x07): sprintf(t, "bge %+d", (int8_t)op1); break; - case (0x08): sprintf(t, "bne %+d", (int8_t)op1); break; - case (0x09): sprintf(t, "beq %+d", (int8_t)op1); break; - case (0x0a): sprintf(t, "bpl %+d", (int8_t)op1); break; - case (0x0b): sprintf(t, "bmi %+d", (int8_t)op1); break; - case (0x0c): sprintf(t, "bcc %+d", (int8_t)op1); break; - case (0x0d): sprintf(t, "bcs %+d", (int8_t)op1); break; - case (0x0e): sprintf(t, "bvc %+d", (int8_t)op1); break; - case (0x0f): sprintf(t, "bvs %+d", (int8_t)op1); break; + case (0x05): sprintf(t, "bra %+d", (s8)op1); break; + case (0x06): sprintf(t, "blt %+d", (s8)op1); break; + case (0x07): sprintf(t, "bge %+d", (s8)op1); break; + case (0x08): sprintf(t, "bne %+d", (s8)op1); break; + case (0x09): sprintf(t, "beq %+d", (s8)op1); break; + case (0x0a): sprintf(t, "bpl %+d", (s8)op1); break; + case (0x0b): sprintf(t, "bmi %+d", (s8)op1); break; + case (0x0c): sprintf(t, "bcc %+d", (s8)op1); break; + case (0x0d): sprintf(t, "bcs %+d", (s8)op1); break; + case (0x0e): sprintf(t, "bvc %+d", (s8)op1); break; + case (0x0f): sprintf(t, "bvs %+d", (s8)op1); break; case16(0x10): sprintf(t, "to r%u", op0 & 15); break; case16(0x20): sprintf(t, "with r%u", op0 & 15); break; case12(0x30): sprintf(t, "stb (r%u)", op0 & 15); break; @@ -170,17 +170,17 @@ auto GSU::disassembleALT2(char* output) -> void { case (0x02): sprintf(t, "cache"); break; case (0x03): sprintf(t, "lsr"); break; case (0x04): sprintf(t, "rol"); break; - case (0x05): sprintf(t, "bra %+d", (int8_t)op1); break; - case (0x06): sprintf(t, "blt %+d", (int8_t)op1); break; - case (0x07): sprintf(t, "bge %+d", (int8_t)op1); break; - case (0x08): sprintf(t, "bne %+d", (int8_t)op1); break; - case (0x09): sprintf(t, "beq %+d", (int8_t)op1); break; - case (0x0a): sprintf(t, "bpl %+d", (int8_t)op1); break; - case (0x0b): sprintf(t, "bmi %+d", (int8_t)op1); break; - case (0x0c): sprintf(t, "bcc %+d", (int8_t)op1); break; - case (0x0d): sprintf(t, "bcs %+d", (int8_t)op1); break; - case (0x0e): sprintf(t, "bvc %+d", (int8_t)op1); break; - case (0x0f): sprintf(t, "bvs %+d", (int8_t)op1); break; + case (0x05): sprintf(t, "bra %+d", (s8)op1); break; + case (0x06): sprintf(t, "blt %+d", (s8)op1); break; + case (0x07): sprintf(t, "bge %+d", (s8)op1); break; + case (0x08): sprintf(t, "bne %+d", (s8)op1); break; + case (0x09): sprintf(t, "beq %+d", (s8)op1); break; + case (0x0a): sprintf(t, "bpl %+d", (s8)op1); break; + case (0x0b): sprintf(t, "bmi %+d", (s8)op1); break; + case (0x0c): sprintf(t, "bcc %+d", (s8)op1); break; + case (0x0d): sprintf(t, "bcs %+d", (s8)op1); break; + case (0x0e): sprintf(t, "bvc %+d", (s8)op1); break; + case (0x0f): sprintf(t, "bvs %+d", (s8)op1); break; case16(0x10): sprintf(t, "to r%u", op0 & 15); break; case16(0x20): sprintf(t, "with r%u", op0 & 15); break; case12(0x30): sprintf(t, "stw (r%u)", op0 & 15); break; @@ -227,17 +227,17 @@ auto GSU::disassembleALT3(char* output) -> void { case (0x02): sprintf(t, "cache"); break; case (0x03): sprintf(t, "lsr"); break; case (0x04): sprintf(t, "rol"); break; - case (0x05): sprintf(t, "bra %+d", (int8_t)op1); break; - case (0x06): sprintf(t, "blt %+d", (int8_t)op1); break; - case (0x07): sprintf(t, "bge %+d", (int8_t)op1); break; - case (0x08): sprintf(t, "bne %+d", (int8_t)op1); break; - case (0x09): sprintf(t, "beq %+d", (int8_t)op1); break; - case (0x0a): sprintf(t, "bpl %+d", (int8_t)op1); break; - case (0x0b): sprintf(t, "bmi %+d", (int8_t)op1); break; - case (0x0c): sprintf(t, "bcc %+d", (int8_t)op1); break; - case (0x0d): sprintf(t, "bcs %+d", (int8_t)op1); break; - case (0x0e): sprintf(t, "bvc %+d", (int8_t)op1); break; - case (0x0f): sprintf(t, "bvs %+d", (int8_t)op1); break; + case (0x05): sprintf(t, "bra %+d", (s8)op1); break; + case (0x06): sprintf(t, "blt %+d", (s8)op1); break; + case (0x07): sprintf(t, "bge %+d", (s8)op1); break; + case (0x08): sprintf(t, "bne %+d", (s8)op1); break; + case (0x09): sprintf(t, "beq %+d", (s8)op1); break; + case (0x0a): sprintf(t, "bpl %+d", (s8)op1); break; + case (0x0b): sprintf(t, "bmi %+d", (s8)op1); break; + case (0x0c): sprintf(t, "bcc %+d", (s8)op1); break; + case (0x0d): sprintf(t, "bcs %+d", (s8)op1); break; + case (0x0e): sprintf(t, "bvc %+d", (s8)op1); break; + case (0x0f): sprintf(t, "bvs %+d", (s8)op1); break; case16(0x10): sprintf(t, "to r%u", op0 & 15); break; case16(0x20): sprintf(t, "with r%u", op0 & 15); break; case12(0x30): sprintf(t, "stb (r%u)", op0 & 15); break; diff --git a/ares/component/processor/gsu/gsu.hpp b/ares/component/processor/gsu/gsu.hpp index 8b8aafe8b0..01945eaefa 100644 --- a/ares/component/processor/gsu/gsu.hpp +++ b/ares/component/processor/gsu/gsu.hpp @@ -5,71 +5,71 @@ namespace ares { struct GSU { #include "registers.hpp" - virtual auto step(uint clocks) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; virtual auto stop() -> void = 0; - virtual auto color(uint8 source) -> uint8 = 0; - virtual auto plot(uint8 x, uint8 y) -> void = 0; - virtual auto rpix(uint8 x, uint8 y) -> uint8 = 0; + virtual auto color(n8 source) -> n8 = 0; + virtual auto plot(n8 x, n8 y) -> void = 0; + virtual auto rpix(n8 x, n8 y) -> n8 = 0; - virtual auto pipe() -> uint8 = 0; + virtual auto pipe() -> n8 = 0; virtual auto syncROMBuffer() -> void = 0; - virtual auto readROMBuffer() -> uint8 = 0; + virtual auto readROMBuffer() -> n8 = 0; virtual auto syncRAMBuffer() -> void = 0; - virtual auto readRAMBuffer(uint16 address) -> uint8 = 0; - virtual auto writeRAMBuffer(uint16 address, uint8 data) -> void = 0; + virtual auto readRAMBuffer(n16 address) -> n8 = 0; + virtual auto writeRAMBuffer(n16 address, n8 data) -> void = 0; virtual auto flushCache() -> void = 0; - virtual auto read(uint24 address, uint8 data = 0x00) -> uint8 = 0; - virtual auto write(uint24 address, uint8 data) -> void = 0; + virtual auto read(n24 address, n8 data = 0x00) -> n8 = 0; + virtual auto write(n24 address, n8 data) -> void = 0; //gsu.cpp auto power() -> void; //instructions.cpp - auto instructionADD_ADC(uint n) -> void; + auto instructionADD_ADC(u32 n) -> void; auto instructionALT1() -> void; auto instructionALT2() -> void; auto instructionALT3() -> void; - auto instructionAND_BIC(uint n) -> void; + auto instructionAND_BIC(u32 n) -> void; auto instructionASR_DIV2() -> void; auto instructionBranch(bool c) -> void; auto instructionCACHE() -> void; auto instructionCOLOR_CMODE() -> void; - auto instructionDEC(uint n) -> void; + auto instructionDEC(u32 n) -> void; auto instructionFMULT_LMULT() -> void; - auto instructionFROM_MOVES(uint n) -> void; + auto instructionFROM_MOVES(u32 n) -> void; auto instructionGETB() -> void; auto instructionGETC_RAMB_ROMB() -> void; auto instructionHIB() -> void; - auto instructionIBT_LMS_SMS(uint n) -> void; - auto instructionINC(uint n) -> void; - auto instructionIWT_LM_SM(uint n) -> void; - auto instructionJMP_LJMP(uint n) -> void; - auto instructionLINK(uint n) -> void; - auto instructionLoad(uint n) -> void; + auto instructionIBT_LMS_SMS(u32 n) -> void; + auto instructionINC(u32 n) -> void; + auto instructionIWT_LM_SM(u32 n) -> void; + auto instructionJMP_LJMP(u32 n) -> void; + auto instructionLINK(u32 n) -> void; + auto instructionLoad(u32 n) -> void; auto instructionLOB() -> void; auto instructionLOOP() -> void; auto instructionLSR() -> void; auto instructionMERGE() -> void; - auto instructionMULT_UMULT(uint n) -> void; + auto instructionMULT_UMULT(u32 n) -> void; auto instructionNOP() -> void; auto instructionNOT() -> void; - auto instructionOR_XOR(uint n) -> void; + auto instructionOR_XOR(u32 n) -> void; auto instructionPLOT_RPIX() -> void; auto instructionROL() -> void; auto instructionROR() -> void; auto instructionSBK() -> void; auto instructionSEX() -> void; - auto instructionStore(uint n) -> void; + auto instructionStore(u32 n) -> void; auto instructionSTOP() -> void; - auto instructionSUB_SBC_CMP(uint n) -> void; + auto instructionSUB_SBC_CMP(u32 n) -> void; auto instructionSWAP() -> void; - auto instructionTO_MOVE(uint n) -> void; - auto instructionWITH(uint n) -> void; + auto instructionTO_MOVE(u32 n) -> void; + auto instructionWITH(u32 n) -> void; //switch.cpp - auto instruction(uint8 opcode) -> void; + auto instruction(n8 opcode) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/component/processor/gsu/instruction.cpp b/ares/component/processor/gsu/instruction.cpp index 969e611823..042fe9dbb3 100644 --- a/ares/component/processor/gsu/instruction.cpp +++ b/ares/component/processor/gsu/instruction.cpp @@ -1,36 +1,36 @@ -auto GSU::instruction(uint8 opcode) -> void { +auto GSU::instruction(n8 opcode) -> void { #define op(id, name, ...) \ case id: return instruction##name(__VA_ARGS__); \ #define op4(id, name) \ - case id+ 0: return instruction##name((uint4)opcode); \ - case id+ 1: return instruction##name((uint4)opcode); \ - case id+ 2: return instruction##name((uint4)opcode); \ - case id+ 3: return instruction##name((uint4)opcode); \ + case id+ 0: return instruction##name((n4)opcode); \ + case id+ 1: return instruction##name((n4)opcode); \ + case id+ 2: return instruction##name((n4)opcode); \ + case id+ 3: return instruction##name((n4)opcode); \ #define op6(id, name) \ op4(id, name) \ - case id+ 4: return instruction##name((uint4)opcode); \ - case id+ 5: return instruction##name((uint4)opcode); \ + case id+ 4: return instruction##name((n4)opcode); \ + case id+ 5: return instruction##name((n4)opcode); \ #define op12(id, name) \ op6(id, name) \ - case id+ 6: return instruction##name((uint4)opcode); \ - case id+ 7: return instruction##name((uint4)opcode); \ - case id+ 8: return instruction##name((uint4)opcode); \ - case id+ 9: return instruction##name((uint4)opcode); \ - case id+10: return instruction##name((uint4)opcode); \ - case id+11: return instruction##name((uint4)opcode); \ + case id+ 6: return instruction##name((n4)opcode); \ + case id+ 7: return instruction##name((n4)opcode); \ + case id+ 8: return instruction##name((n4)opcode); \ + case id+ 9: return instruction##name((n4)opcode); \ + case id+10: return instruction##name((n4)opcode); \ + case id+11: return instruction##name((n4)opcode); \ #define op15(id, name) \ op12(id, name) \ - case id+12: return instruction##name((uint4)opcode); \ - case id+13: return instruction##name((uint4)opcode); \ - case id+14: return instruction##name((uint4)opcode); \ + case id+12: return instruction##name((n4)opcode); \ + case id+13: return instruction##name((n4)opcode); \ + case id+14: return instruction##name((n4)opcode); \ #define op16(id, name) \ op15(id, name) \ - case id+15: return instruction##name((uint4)opcode); \ + case id+15: return instruction##name((n4)opcode); \ switch(opcode) { op (0x00, STOP) diff --git a/ares/component/processor/gsu/instructions.cpp b/ares/component/processor/gsu/instructions.cpp index 56e89d411f..8afa9679b7 100644 --- a/ares/component/processor/gsu/instructions.cpp +++ b/ares/component/processor/gsu/instructions.cpp @@ -54,13 +54,13 @@ auto GSU::instructionROL() -> void { //$0e bvc e //$0f bvs e auto GSU::instructionBranch(bool take) -> void { - auto displacement = (int8)pipe(); + auto displacement = (i8)pipe(); if(take) regs.r[15] += displacement; } //$10-1f(b0) to rN //$10-1f(b1) move rN -auto GSU::instructionTO_MOVE(uint n) -> void { +auto GSU::instructionTO_MOVE(u32 n) -> void { if(!regs.sfr.b) { regs.dreg = n; } else { @@ -70,7 +70,7 @@ auto GSU::instructionTO_MOVE(uint n) -> void { } //$20-2f with rN -auto GSU::instructionWITH(uint n) -> void { +auto GSU::instructionWITH(u32 n) -> void { regs.sreg = n; regs.dreg = n; regs.sfr.b = 1; @@ -78,7 +78,7 @@ auto GSU::instructionWITH(uint n) -> void { //$30-3b(alt0) stw (rN) //$30-3b(alt1) stb (rN) -auto GSU::instructionStore(uint n) -> void { +auto GSU::instructionStore(u32 n) -> void { regs.ramaddr = regs.r[n]; writeRAMBuffer(regs.ramaddr, regs.sr()); if(!regs.sfr.alt1) writeRAMBuffer(regs.ramaddr ^ 1, regs.sr() >> 8); @@ -115,7 +115,7 @@ auto GSU::instructionALT3() -> void { //$40-4b(alt0) ldw (rN) //$40-4b(alt1) ldb (rN) -auto GSU::instructionLoad(uint n) -> void { +auto GSU::instructionLoad(u32 n) -> void { regs.ramaddr = regs.r[n]; regs.dr() = readRAMBuffer(regs.ramaddr); if(!regs.sfr.alt1) regs.dr() |= readRAMBuffer(regs.ramaddr ^ 1) << 8; @@ -167,13 +167,13 @@ auto GSU::instructionNOT() -> void { //$50-5f(alt1) adc rN //$50-5f(alt2) add #N //$50-5f(alt3) adc #N -auto GSU::instructionADD_ADC(uint n) -> void { +auto GSU::instructionADD_ADC(u32 n) -> void { if(!regs.sfr.alt2) n = regs.r[n]; - int r = regs.sr() + n + (regs.sfr.alt1 ? regs.sfr.cy : 0); + s32 r = regs.sr() + n + (regs.sfr.alt1 ? regs.sfr.cy : 0); regs.sfr.ov = ~(regs.sr() ^ n) & (n ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); regs.sfr.cy = (r >= 0x10000); - regs.sfr.z = ((uint16)r == 0); + regs.sfr.z = ((n16)r == 0); regs.dr() = r; regs.reset(); } @@ -182,13 +182,13 @@ auto GSU::instructionADD_ADC(uint n) -> void { //$60-6f(alt1) sbc rN //$60-6f(alt2) sub #N //$60-6f(alt3) cmp rN -auto GSU::instructionSUB_SBC_CMP(uint n) -> void { +auto GSU::instructionSUB_SBC_CMP(u32 n) -> void { if(!regs.sfr.alt2 || regs.sfr.alt1) n = regs.r[n]; - int r = regs.sr() - n - (!regs.sfr.alt2 && regs.sfr.alt1 ? !regs.sfr.cy : 0); + s32 r = regs.sr() - n - (!regs.sfr.alt2 && regs.sfr.alt1 ? !regs.sfr.cy : 0); regs.sfr.ov = (regs.sr() ^ n) & (regs.sr() ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); regs.sfr.cy = (r >= 0); - regs.sfr.z = ((uint16)r == 0); + regs.sfr.z = ((n16)r == 0); if(!regs.sfr.alt2 || !regs.sfr.alt1) regs.dr() = r; regs.reset(); } @@ -207,7 +207,7 @@ auto GSU::instructionMERGE() -> void { //$71-7f(alt1) bic rN //$71-7f(alt2) and #N //$71-7f(alt3) bic #N -auto GSU::instructionAND_BIC(uint n) -> void { +auto GSU::instructionAND_BIC(u32 n) -> void { if(!regs.sfr.alt2) n = regs.r[n]; regs.dr() = regs.sr() & (regs.sfr.alt1 ? ~n : n); regs.sfr.s = (regs.dr() & 0x8000); @@ -219,9 +219,9 @@ auto GSU::instructionAND_BIC(uint n) -> void { //$80-8f(alt1) umult rN //$80-8f(alt2) mult #N //$80-8f(alt3) umult #N -auto GSU::instructionMULT_UMULT(uint n) -> void { +auto GSU::instructionMULT_UMULT(u32 n) -> void { if(!regs.sfr.alt2) n = regs.r[n]; - regs.dr() = (!regs.sfr.alt1 ? uint16((int8)regs.sr() * (int8)n) : uint16((uint8)regs.sr() * (uint8)n)); + regs.dr() = (!regs.sfr.alt1 ? n16((i8)regs.sr() * (i8)n) : n16((n8)regs.sr() * (n8)n)); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); @@ -236,14 +236,14 @@ auto GSU::instructionSBK() -> void { } //$91-94 link #N -auto GSU::instructionLINK(uint n) -> void { +auto GSU::instructionLINK(u32 n) -> void { regs.r[11] = regs.r[15] + n; regs.reset(); } //$95 sex auto GSU::instructionSEX() -> void { - regs.dr() = (int8)regs.sr(); + regs.dr() = (i8)regs.sr(); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); @@ -253,7 +253,7 @@ auto GSU::instructionSEX() -> void { //$96(alt1) div2 auto GSU::instructionASR_DIV2() -> void { regs.sfr.cy = (regs.sr() & 1); - regs.dr() = ((int16)regs.sr() >> 1) + (regs.sfr.alt1 ? ((regs.sr() + 1) >> 16) : 0); + regs.dr() = ((i16)regs.sr() >> 1) + (regs.sfr.alt1 ? ((regs.sr() + 1) >> 16) : 0); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); @@ -271,7 +271,7 @@ auto GSU::instructionROR() -> void { //$98-9d(alt0) jmp rN //$98-9d(alt1) ljmp rN -auto GSU::instructionJMP_LJMP(uint n) -> void { +auto GSU::instructionJMP_LJMP(u32 n) -> void { if(!regs.sfr.alt1) { regs.r[15] = regs.r[n]; } else { @@ -294,7 +294,7 @@ auto GSU::instructionLOB() -> void { //$9f(alt0) fmult //$9f(alt1) lmult auto GSU::instructionFMULT_LMULT() -> void { - uint32 result = (int16)regs.sr() * (int16)regs.r[6]; + n32 result = (i16)regs.sr() * (i16)regs.r[6]; if(regs.sfr.alt1) regs.r[4] = result; regs.dr() = result >> 16; regs.sfr.s = (regs.dr() & 0x8000); @@ -307,24 +307,24 @@ auto GSU::instructionFMULT_LMULT() -> void { //$a0-af(alt0) ibt rN,#pp //$a0-af(alt1) lms rN,(yy) //$a0-af(alt2) sms (yy),rN -auto GSU::instructionIBT_LMS_SMS(uint n) -> void { +auto GSU::instructionIBT_LMS_SMS(u32 n) -> void { if(regs.sfr.alt1) { regs.ramaddr = pipe() << 1; - uint8 lo = readRAMBuffer(regs.ramaddr ^ 0) << 0; + n8 lo = readRAMBuffer(regs.ramaddr ^ 0) << 0; regs.r[n] = readRAMBuffer(regs.ramaddr ^ 1) << 8 | lo; } else if(regs.sfr.alt2) { regs.ramaddr = pipe() << 1; writeRAMBuffer(regs.ramaddr ^ 0, regs.r[n] >> 0); writeRAMBuffer(regs.ramaddr ^ 1, regs.r[n] >> 8); } else { - regs.r[n] = (int8)pipe(); + regs.r[n] = (i8)pipe(); } regs.reset(); } //$b0-bf(b0) from rN //$b0-bf(b1) moves rN -auto GSU::instructionFROM_MOVES(uint n) -> void { +auto GSU::instructionFROM_MOVES(u32 n) -> void { if(!regs.sfr.b) { regs.sreg = n; } else { @@ -348,7 +348,7 @@ auto GSU::instructionHIB() -> void { //$c1-cf(alt1) xor rN //$c1-cf(alt2) or #N //$c1-cf(alt3) xor #N -auto GSU::instructionOR_XOR(uint n) -> void { +auto GSU::instructionOR_XOR(u32 n) -> void { if(!regs.sfr.alt2) n = regs.r[n]; regs.dr() = (!regs.sfr.alt1 ? (regs.sr() | n) : (regs.sr() ^ n)); regs.sfr.s = (regs.dr() & 0x8000); @@ -357,7 +357,7 @@ auto GSU::instructionOR_XOR(uint n) -> void { } //$d0-de inc rN -auto GSU::instructionINC(uint n) -> void { +auto GSU::instructionINC(u32 n) -> void { regs.r[n]++; regs.sfr.s = (regs.r[n] & 0x8000); regs.sfr.z = (regs.r[n] == 0); @@ -381,7 +381,7 @@ auto GSU::instructionGETC_RAMB_ROMB() -> void { } //$e0-ee dec rN -auto GSU::instructionDEC(uint n) -> void { +auto GSU::instructionDEC(u32 n) -> void { regs.r[n]--; regs.sfr.s = (regs.r[n] & 0x8000); regs.sfr.z = (regs.r[n] == 0); @@ -395,9 +395,9 @@ auto GSU::instructionDEC(uint n) -> void { auto GSU::instructionGETB() -> void { switch(regs.sfr.alt2 << 1 | regs.sfr.alt1 << 0) { case 0: regs.dr() = readROMBuffer(); break; - case 1: regs.dr() = readROMBuffer() << 8 | (uint8)regs.sr(); break; + case 1: regs.dr() = readROMBuffer() << 8 | (n8)regs.sr(); break; case 2: regs.dr() = (regs.sr() & 0xff00) | readROMBuffer(); break; - case 3: regs.dr() = (int8)readROMBuffer(); break; + case 3: regs.dr() = (i8)readROMBuffer(); break; } regs.reset(); } @@ -405,11 +405,11 @@ auto GSU::instructionGETB() -> void { //$f0-ff(alt0) iwt rN,#xx //$f0-ff(alt1) lm rN,(xx) //$f0-ff(alt2) sm (xx),rN -auto GSU::instructionIWT_LM_SM(uint n) -> void { +auto GSU::instructionIWT_LM_SM(u32 n) -> void { if(regs.sfr.alt1) { regs.ramaddr = pipe() << 0; regs.ramaddr |= pipe() << 8; - uint8 lo = readRAMBuffer(regs.ramaddr ^ 0) << 0; + n8 lo = readRAMBuffer(regs.ramaddr ^ 0) << 0; regs.r[n] = readRAMBuffer(regs.ramaddr ^ 1) << 8 | lo; } else if(regs.sfr.alt2) { regs.ramaddr = pipe() << 0; @@ -417,7 +417,7 @@ auto GSU::instructionIWT_LM_SM(uint n) -> void { writeRAMBuffer(regs.ramaddr ^ 0, regs.r[n] >> 0); writeRAMBuffer(regs.ramaddr ^ 1, regs.r[n] >> 8); } else { - uint8 lo = pipe(); + n8 lo = pipe(); regs.r[n] = pipe() << 8 | lo; } regs.reset(); diff --git a/ares/component/processor/gsu/registers.hpp b/ares/component/processor/gsu/registers.hpp index 373bf707df..b3a31223de 100644 --- a/ares/component/processor/gsu/registers.hpp +++ b/ares/component/processor/gsu/registers.hpp @@ -1,31 +1,31 @@ struct Register { - uint16 data = 0; + n16 data = 0; bool modified = false; - operator uint() const { + operator u32() const { return data; } - auto assign(uint value) -> uint16 { + auto assign(u32 value) -> n16 { modified = true; return data = value; } auto operator++() { return assign(data + 1); } auto operator--() { return assign(data - 1); } - auto operator++(int) { uint r = data; assign(data + 1); return r; } - auto operator--(int) { uint r = data; assign(data - 1); return r; } - auto operator = (uint i) { return assign(i); } - auto operator |= (uint i) { return assign(data | i); } - auto operator ^= (uint i) { return assign(data ^ i); } - auto operator &= (uint i) { return assign(data & i); } - auto operator <<= (uint i) { return assign(data << i); } - auto operator >>= (uint i) { return assign(data >> i); } - auto operator += (uint i) { return assign(data + i); } - auto operator -= (uint i) { return assign(data - i); } - auto operator *= (uint i) { return assign(data * i); } - auto operator /= (uint i) { return assign(data / i); } - auto operator %= (uint i) { return assign(data % i); } + auto operator++(s32) { u32 r = data; assign(data + 1); return r; } + auto operator--(s32) { u32 r = data; assign(data - 1); return r; } + auto operator = (u32 i) { return assign(i); } + auto operator |= (u32 i) { return assign(data | i); } + auto operator ^= (u32 i) { return assign(data ^ i); } + auto operator &= (u32 i) { return assign(data & i); } + auto operator <<= (u32 i) { return assign(data << i); } + auto operator >>= (u32 i) { return assign(data >> i); } + auto operator += (u32 i) { return assign(data + i); } + auto operator -= (u32 i) { return assign(data - i); } + auto operator *= (u32 i) { return assign(data * i); } + auto operator /= (u32 i) { return assign(data / i); } + auto operator %= (u32 i) { return assign(data % i); } auto operator = (const Register& value) { return assign(value); } @@ -34,7 +34,7 @@ struct Register { }; struct SFR { - uint16 data; + n16 data; BitField<16, 1> z {&data}; //zero flag BitField<16, 2> cy {&data}; //carry flag BitField<16, 3> s {&data}; //sign flag @@ -54,21 +54,21 @@ struct SFR { SFR(const SFR&) = delete; auto operator=(const SFR&) = delete; - operator uint() const { return data & 0x9f7e; } - auto& operator=(const uint value) { return data = value, *this; } + operator u32() const { return data & 0x9f7e; } + auto& operator=(const u32 value) { return data = value, *this; } }; struct SCMR { - uint ht; + u32 ht; bool ron; bool ran; - uint md; + u32 md; - operator uint() const { + operator u32() const { return ((ht >> 1) << 5) | (ron << 4) | (ran << 3) | ((ht & 1) << 2) | (md); } - auto& operator=(uint data) { + auto& operator=(u32 data) { ht = (bool)(data & 0x20) << 1; ht |= (bool)(data & 0x04) << 0; ron = data & 0x10; @@ -85,11 +85,11 @@ struct POR { bool dither; bool transparent; - operator uint() const { + operator u32() const { return (obj << 4) | (freezehigh << 3) | (highnibble << 2) | (dither << 1) | (transparent); } - auto& operator=(uint data) { + auto& operator=(u32 data) { obj = data & 0x10; freezehigh = data & 0x08; highnibble = data & 0x04; @@ -103,11 +103,11 @@ struct CFGR { bool irq; bool ms0; - operator uint() const { + operator u32() const { return (irq << 7) | (ms0 << 5); } - auto& operator=(uint data) { + auto& operator=(u32 data) { irq = data & 0x80; ms0 = data & 0x20; return *this; @@ -115,33 +115,33 @@ struct CFGR { }; struct Registers { - uint8 pipeline; - uint16 ramaddr; - - Register r[16]; //general purpose registers - SFR sfr; //status flag register - uint8 pbr; //program bank register - uint8 rombr; //game pack ROM bank register - bool rambr; //game pack RAM bank register - uint16 cbr; //cache base register - uint8 scbr; //screen base register - SCMR scmr; //screen mode register - uint8 colr; //color register - POR por; //plot option register - bool bramr; //back-up RAM register - uint8 vcr; //version code register - CFGR cfgr; //config register - bool clsr; //clock select register - - uint romcl; //clock ticks until romdr is valid - uint8 romdr; //ROM buffer data register - - uint ramcl; //clock ticks until ramdr is valid - uint16 ramar; //RAM buffer address register - uint8 ramdr; //RAM buffer data register - - uint sreg; - uint dreg; + n8 pipeline; + n16 ramaddr; + + Register r[16]; //general purpose registers + SFR sfr; //status flag register + n8 pbr; //program bank register + n8 rombr; //game pack ROM bank register + bool rambr; //game pack RAM bank register + n16 cbr; //cache base register + n8 scbr; //screen base register + SCMR scmr; //screen mode register + n8 colr; //color register + POR por; //plot option register + bool bramr; //back-up RAM register + n8 vcr; //version code register + CFGR cfgr; //config register + bool clsr; //clock select register + + u32 romcl; //clock ticks until romdr is valid + n8 romdr; //ROM buffer data register + + u32 ramcl; //clock ticks until ramdr is valid + n16 ramar; //RAM buffer address register + n8 ramdr; //RAM buffer data register + + u32 sreg; + u32 dreg; auto& sr() { return r[sreg]; } //source register (from) auto& dr() { return r[dreg]; } //destination register (to) @@ -156,12 +156,12 @@ struct Registers { } regs; struct Cache { - uint8 buffer[512]; + n8 buffer[512]; bool valid[32]; } cache; struct PixelCache { - uint16 offset; - uint8 bitpend; - uint8 data[8]; + n16 offset; + n8 bitpend; + n8 data[8]; } pixelcache[2]; diff --git a/ares/component/processor/gsu/serialization.cpp b/ares/component/processor/gsu/serialization.cpp index 38ef7a04c8..947a2ad5f0 100644 --- a/ares/component/processor/gsu/serialization.cpp +++ b/ares/component/processor/gsu/serialization.cpp @@ -2,7 +2,7 @@ auto GSU::serialize(serializer& s) -> void { s(regs.pipeline); s(regs.ramaddr); - for(uint n : range(16)) { + for(u32 n : range(16)) { s(regs.r[n].data); s(regs.r[n].modified); } @@ -48,7 +48,7 @@ auto GSU::serialize(serializer& s) -> void { s(cache.buffer); s(cache.valid); - for(uint n : range(2)) { + for(u32 n : range(2)) { s(pixelcache[n].offset); s(pixelcache[n].bitpend); s(pixelcache[n].data); diff --git a/ares/component/processor/hg51b/disassembler.cpp b/ares/component/processor/hg51b/disassembler.cpp index 2fd781eab4..d2bc316b8a 100644 --- a/ares/component/processor/hg51b/disassembler.cpp +++ b/ares/component/processor/hg51b/disassembler.cpp @@ -1,31 +1,31 @@ -auto HG51B::disassembleInstruction(maybe _pb, maybe _pc) -> string { - uint15 pb = _pb ? *_pb : (uint15)r.pb; - uint8 pc = _pc ? *_pc : (uint8)r.pc; +auto HG51B::disassembleInstruction(maybe _pb, maybe _pc) -> string { + n15 pb = _pb ? *_pb : (n15)r.pb; + n8 pc = _pc ? *_pc : (n8 )r.pc; return {}; //todo } -auto HG51B::disassembleADD(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleADD(n7 reg, n5 shift) -> string { return {"add "}; } -auto HG51B::disassembleADD(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleADD(n8 imm, n5 shift) -> string { return {"add "}; } -auto HG51B::disassembleAND(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleAND(n7 reg, n5 shift) -> string { return {"and "}; } -auto HG51B::disassembleAND(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleAND(n8 imm, n5 shift) -> string { return {"and "}; } -auto HG51B::disassembleASR(uint7 reg) -> string { +auto HG51B::disassembleASR(n7 reg) -> string { return {"asr "}; } -auto HG51B::disassembleASR(uint5 imm) -> string { +auto HG51B::disassembleASR(n5 imm) -> string { return {"imm "}; } @@ -33,19 +33,19 @@ auto HG51B::disassembleCLEAR() -> string { return {"clear "}; } -auto HG51B::disassembleCMP(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleCMP(n7 reg, n5 shift) -> string { return {"cmp "}; } -auto HG51B::disassembleCMP(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleCMP(n8 imm, n5 shift) -> string { return {"cmp "}; } -auto HG51B::disassembleCMPR(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleCMPR(n7 reg, n5 shift) -> string { return {"cmpr "}; } -auto HG51B::disassembleCMPR(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleCMPR(n8 imm, n5 shift) -> string { return {"cmpr "}; } @@ -53,47 +53,47 @@ auto HG51B::disassembleHALT() -> string { return {"halt "}; } -auto HG51B::disassembleINC(uint24& reg) -> string { +auto HG51B::disassembleINC(n24& reg) -> string { return {"inc "}; } -auto HG51B::disassembleJMP(uint8 data, uint1 far, const uint1& take) -> string { +auto HG51B::disassembleJMP(n8 data, n1 far, const n1& take) -> string { return {"jmp "}; } -auto HG51B::disassembleJSR(uint8 data, uint1 far, const uint1& take) -> string { +auto HG51B::disassembleJSR(n8 data, n1 far, const n1& take) -> string { return {"jsr "}; } -auto HG51B::disassembleLD(uint24& out, uint7 reg) -> string { +auto HG51B::disassembleLD(n24& out, n7 reg) -> string { return {"ld "}; } -auto HG51B::disassembleLD(uint15& out, uint4 reg) -> string { +auto HG51B::disassembleLD(n15& out, n4 reg) -> string { return {"ld "}; } -auto HG51B::disassembleLD(uint24& out, uint8 imm) -> string { +auto HG51B::disassembleLD(n24& out, n8 imm) -> string { return {"ld "}; } -auto HG51B::disassembleLD(uint15& out, uint8 imm) -> string { +auto HG51B::disassembleLD(n15& out, n8 imm) -> string { return {"ld "}; } -auto HG51B::disassembleLDL(uint15& out, uint8 imm) -> string { +auto HG51B::disassembleLDL(n15& out, n8 imm) -> string { return {"ldl "}; } -auto HG51B::disassembleLDH(uint15& out, uint7 imm) -> string { +auto HG51B::disassembleLDH(n15& out, n7 imm) -> string { return {"ldh "}; } -auto HG51B::disassembleMUL(uint7 reg) -> string { +auto HG51B::disassembleMUL(n7 reg) -> string { return {"mul "}; } -auto HG51B::disassembleMUL(uint8 imm) -> string { +auto HG51B::disassembleMUL(n8 imm) -> string { return {"mul "}; } @@ -101,35 +101,35 @@ auto HG51B::disassembleNOP() -> string { return {"nop "}; } -auto HG51B::disassembleOR(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleOR(n7 reg, n5 shift) -> string { return {"or "}; } -auto HG51B::disassembleOR(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleOR(n8 imm, n5 shift) -> string { return {"or "}; } -auto HG51B::disassembleRDRAM(uint2 byte, uint24& a) -> string { +auto HG51B::disassembleRDRAM(n2 byte, n24& a) -> string { return {"rdram "}; } -auto HG51B::disassembleRDRAM(uint2 byte, uint8 imm) -> string { +auto HG51B::disassembleRDRAM(n2 byte, n8 imm) -> string { return {"rdram "}; } -auto HG51B::disassembleRDROM(uint24& reg) -> string { +auto HG51B::disassembleRDROM(n24& reg) -> string { return {"rdrom "}; } -auto HG51B::disassembleRDROM(uint10 imm) -> string { +auto HG51B::disassembleRDROM(n10 imm) -> string { return {"rdrom "}; } -auto HG51B::disassembleROR(uint7 reg) -> string { +auto HG51B::disassembleROR(n7 reg) -> string { return {"ror "}; } -auto HG51B::disassembleROR(uint5 imm) -> string { +auto HG51B::disassembleROR(n5 imm) -> string { return {"ror "}; } @@ -137,47 +137,47 @@ auto HG51B::disassembleRTS() -> string { return {"rts "}; } -auto HG51B::disassembleSHL(uint7 reg) -> string { +auto HG51B::disassembleSHL(n7 reg) -> string { return {"shl "}; } -auto HG51B::disassembleSHL(uint5 imm) -> string { +auto HG51B::disassembleSHL(n5 imm) -> string { return {"shl "}; } -auto HG51B::disassembleSHR(uint7 reg) -> string { +auto HG51B::disassembleSHR(n7 reg) -> string { return {"shr "}; } -auto HG51B::disassembleSHR(uint5 imm) -> string { +auto HG51B::disassembleSHR(n5 imm) -> string { return {"shr "}; } -auto HG51B::disassembleSKIP(uint1 take, const uint1& flag) -> string { +auto HG51B::disassembleSKIP(n1 take, const n1& flag) -> string { return {"skip "}; } -auto HG51B::disassembleST(uint7 reg, uint24& in) -> string { +auto HG51B::disassembleST(n7 reg, n24& in) -> string { return {"st "}; } -auto HG51B::disassembleSUB(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleSUB(n7 reg, n5 shift) -> string { return {"sub "}; } -auto HG51B::disassembleSUB(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleSUB(n8 imm, n5 shift) -> string { return {"sub "}; } -auto HG51B::disassembleSUBR(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleSUBR(n7 reg, n5 shift) -> string { return {"subr "}; } -auto HG51B::disassembleSUBR(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleSUBR(n8 imm, n5 shift) -> string { return {"subr "}; } -auto HG51B::disassembleSWAP(uint24& a, uint4 reg) -> string { +auto HG51B::disassembleSWAP(n24& a, n4 reg) -> string { return {"swap "}; } @@ -193,27 +193,27 @@ auto HG51B::disassembleWAIT() -> string { return {"wait "}; } -auto HG51B::disassembleWRRAM(uint2 byte, uint24& a) -> string { +auto HG51B::disassembleWRRAM(n2 byte, n24& a) -> string { return {"wrram "}; } -auto HG51B::disassembleWRRAM(uint2 byte, uint8 imm) -> string { +auto HG51B::disassembleWRRAM(n2 byte, n8 imm) -> string { return {"wrram "}; } -auto HG51B::disassembleXNOR(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleXNOR(n7 reg, n5 shift) -> string { return {"xnor "}; } -auto HG51B::disassembleXNOR(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleXNOR(n8 imm, n5 shift) -> string { return {"xnor "}; } -auto HG51B::disassembleXOR(uint7 reg, uint5 shift) -> string { +auto HG51B::disassembleXOR(n7 reg, n5 shift) -> string { return {"xor "}; } -auto HG51B::disassembleXOR(uint8 imm, uint5 shift) -> string { +auto HG51B::disassembleXOR(n8 imm, n5 shift) -> string { return {"xor "}; } @@ -222,7 +222,7 @@ auto HG51B::disassembleContext() -> string { output.append("a:", hex(r.a, 6L), " "); output.append("p:", hex(r.p, 4L), " "); - for(uint n : range(16)) { + for(u32 n : range(16)) { output.append("r", n, ":", hex(r.gpr[n], 6L), " "); } diff --git a/ares/component/processor/hg51b/hg51b.cpp b/ares/component/processor/hg51b/hg51b.cpp index d86564f2ec..b96994bc1d 100644 --- a/ares/component/processor/hg51b/hg51b.cpp +++ b/ares/component/processor/hg51b/hg51b.cpp @@ -17,7 +17,7 @@ auto HG51B::halt() -> void { io.halt = 1; } -auto HG51B::wait(uint24 address) -> uint { +auto HG51B::wait(n24 address) -> u32 { if(isROM(address)) return 1 + io.wait.rom; if(isRAM(address)) return 1 + io.wait.ram; return 1; @@ -32,7 +32,7 @@ auto HG51B::main() -> void { return execute(); } -auto HG51B::step(uint clocks) -> void { +auto HG51B::step(u32 clocks) -> void { if(io.bus.enable) { if(io.bus.pending > clocks) { io.bus.pending -= clocks; @@ -71,7 +71,7 @@ auto HG51B::suspend() -> void { } auto HG51B::cache() -> bool { - uint24 address = io.cache.base + r.pb * 512; + n24 address = io.cache.base + r.pb * 512; //try to use the current page ... if(io.cache.address[io.cache.page] == address) return io.cache.enable = 0, true; @@ -84,7 +84,7 @@ auto HG51B::cache() -> bool { if(io.cache.lock[io.cache.page]) return io.cache.enable = 0, false; io.cache.address[io.cache.page] = address; - for(uint offset : range(256)) { + for(u32 offset : range(256)) { step(wait(address)); programRAM[io.cache.page][offset].byte(0) = read(address++); programRAM[io.cache.page][offset].byte(1) = read(address++); @@ -93,9 +93,9 @@ auto HG51B::cache() -> bool { } auto HG51B::dma() -> void { - for(uint offset : range(io.dma.length)) { - uint24 source = io.dma.source + offset; - uint24 target = io.dma.target + offset; + for(u32 offset : range(io.dma.length)) { + n24 source = io.dma.source + offset; + n24 target = io.dma.target + offset; if(isROM(source) && isROM(target)) return lock(); if(isRAM(source) && isRAM(target)) return lock(); diff --git a/ares/component/processor/hg51b/hg51b.hpp b/ares/component/processor/hg51b/hg51b.hpp index fdde7bf81f..34a1599c71 100644 --- a/ares/component/processor/hg51b/hg51b.hpp +++ b/ares/component/processor/hg51b/hg51b.hpp @@ -9,14 +9,14 @@ struct HG51B { HG51B(); //hg51b.cpp - virtual auto step(uint clocks) -> void; - virtual auto isROM(uint24 address) -> bool = 0; - virtual auto isRAM(uint24 address) -> bool = 0; - virtual auto read(uint24 address) -> uint8 = 0; - virtual auto write(uint24 address, uint8 data) -> void = 0; + virtual auto step(u32 clocks) -> void; + virtual auto isROM(n24 address) -> bool = 0; + virtual auto isRAM(n24 address) -> bool = 0; + virtual auto read(n24 address) -> n8 = 0; + virtual auto write(n24 address, n8 data) -> void = 0; virtual auto lock() -> void; virtual auto halt() -> void; - auto wait(uint24 address) -> uint; + auto wait(n24 address) -> u32; auto main() -> void; auto execute() -> void; auto advance() -> void; @@ -32,210 +32,210 @@ struct HG51B { auto push() -> void; auto pull() -> void; - auto algorithmADD(uint24 x, uint24 y) -> uint24; - auto algorithmAND(uint24 x, uint24 y) -> uint24; - auto algorithmASR(uint24 a, uint5 s) -> uint24; - auto algorithmMUL(int24 x, int24 y) -> uint48; - auto algorithmOR(uint24 x, uint24 y) -> uint24; - auto algorithmROR(uint24 a, uint5 s) -> uint24; - auto algorithmSHL(uint24 a, uint5 s) -> uint24; - auto algorithmSHR(uint24 a, uint5 s) -> uint24; - auto algorithmSUB(uint24 x, uint24 y) -> uint24; - auto algorithmSX(uint24 x) -> uint24; - auto algorithmXNOR(uint24 x, uint24 y) -> uint24; - auto algorithmXOR(uint24 x, uint24 y) -> uint24; - - auto instructionADD(uint7 reg, uint5 shift) -> void; - auto instructionADD(uint8 imm, uint5 shift) -> void; - auto instructionAND(uint7 reg, uint5 shift) -> void; - auto instructionAND(uint8 imm, uint5 shift) -> void; - auto instructionASR(uint7 reg) -> void; - auto instructionASR(uint5 imm) -> void; + auto algorithmADD(n24 x, n24 y) -> n24; + auto algorithmAND(n24 x, n24 y) -> n24; + auto algorithmASR(n24 a, n5 s) -> n24; + auto algorithmMUL(i24 x, i24 y) -> n48; + auto algorithmOR(n24 x, n24 y) -> n24; + auto algorithmROR(n24 a, n5 s) -> n24; + auto algorithmSHL(n24 a, n5 s) -> n24; + auto algorithmSHR(n24 a, n5 s) -> n24; + auto algorithmSUB(n24 x, n24 y) -> n24; + auto algorithmSX(n24 x) -> n24; + auto algorithmXNOR(n24 x, n24 y) -> n24; + auto algorithmXOR(n24 x, n24 y) -> n24; + + auto instructionADD(n7 reg, n5 shift) -> void; + auto instructionADD(n8 imm, n5 shift) -> void; + auto instructionAND(n7 reg, n5 shift) -> void; + auto instructionAND(n8 imm, n5 shift) -> void; + auto instructionASR(n7 reg) -> void; + auto instructionASR(n5 imm) -> void; auto instructionCLEAR() -> void; - auto instructionCMP(uint7 reg, uint5 shift) -> void; - auto instructionCMP(uint8 imm, uint5 shift) -> void; - auto instructionCMPR(uint7 reg, uint5 shift) -> void; - auto instructionCMPR(uint8 imm, uint5 shift) -> void; + auto instructionCMP(n7 reg, n5 shift) -> void; + auto instructionCMP(n8 imm, n5 shift) -> void; + auto instructionCMPR(n7 reg, n5 shift) -> void; + auto instructionCMPR(n8 imm, n5 shift) -> void; auto instructionHALT() -> void; - auto instructionINC(uint24& reg) -> void; - auto instructionJMP(uint8 data, uint1 far, const uint1& take) -> void; - auto instructionJSR(uint8 data, uint1 far, const uint1& take) -> void; - auto instructionLD(uint24& out, uint7 reg) -> void; - auto instructionLD(uint15& out, uint4 reg) -> void; - auto instructionLD(uint24& out, uint8 imm) -> void; - auto instructionLD(uint15& out, uint8 imm) -> void; - auto instructionLDL(uint15& out, uint8 imm) -> void; - auto instructionLDH(uint15& out, uint7 imm) -> void; - auto instructionMUL(uint7 reg) -> void; - auto instructionMUL(uint8 imm) -> void; + auto instructionINC(n24& reg) -> void; + auto instructionJMP(n8 data, n1 far, const n1& take) -> void; + auto instructionJSR(n8 data, n1 far, const n1& take) -> void; + auto instructionLD(n24& out, n7 reg) -> void; + auto instructionLD(n15& out, n4 reg) -> void; + auto instructionLD(n24& out, n8 imm) -> void; + auto instructionLD(n15& out, n8 imm) -> void; + auto instructionLDL(n15& out, n8 imm) -> void; + auto instructionLDH(n15& out, n7 imm) -> void; + auto instructionMUL(n7 reg) -> void; + auto instructionMUL(n8 imm) -> void; auto instructionNOP() -> void; - auto instructionOR(uint7 reg, uint5 shift) -> void; - auto instructionOR(uint8 imm, uint5 shift) -> void; - auto instructionRDRAM(uint2 byte, uint24& a) -> void; - auto instructionRDRAM(uint2 byte, uint8 imm) -> void; - auto instructionRDROM(uint24& reg) -> void; - auto instructionRDROM(uint10 imm) -> void; - auto instructionROR(uint7 reg) -> void; - auto instructionROR(uint5 imm) -> void; + auto instructionOR(n7 reg, n5 shift) -> void; + auto instructionOR(n8 imm, n5 shift) -> void; + auto instructionRDRAM(n2 byte, n24& a) -> void; + auto instructionRDRAM(n2 byte, n8 imm) -> void; + auto instructionRDROM(n24& reg) -> void; + auto instructionRDROM(n10 imm) -> void; + auto instructionROR(n7 reg) -> void; + auto instructionROR(n5 imm) -> void; auto instructionRTS() -> void; - auto instructionSHL(uint7 reg) -> void; - auto instructionSHL(uint5 imm) -> void; - auto instructionSHR(uint7 reg) -> void; - auto instructionSHR(uint5 imm) -> void; - auto instructionSKIP(uint1 take, const uint1& flag) -> void; - auto instructionST(uint7 reg, uint24& in) -> void; - auto instructionSUB(uint7 reg, uint5 shift) -> void; - auto instructionSUB(uint8 imm, uint5 shift) -> void; - auto instructionSUBR(uint7 reg, uint5 shift) -> void; - auto instructionSUBR(uint8 imm, uint5 shift) -> void; - auto instructionSWAP(uint24& a, uint4 reg) -> void; + auto instructionSHL(n7 reg) -> void; + auto instructionSHL(n5 imm) -> void; + auto instructionSHR(n7 reg) -> void; + auto instructionSHR(n5 imm) -> void; + auto instructionSKIP(n1 take, const n1& flag) -> void; + auto instructionST(n7 reg, n24& in) -> void; + auto instructionSUB(n7 reg, n5 shift) -> void; + auto instructionSUB(n8 imm, n5 shift) -> void; + auto instructionSUBR(n7 reg, n5 shift) -> void; + auto instructionSUBR(n8 imm, n5 shift) -> void; + auto instructionSWAP(n24& a, n4 reg) -> void; auto instructionSXB() -> void; auto instructionSXW() -> void; auto instructionWAIT() -> void; - auto instructionWRRAM(uint2 byte, uint24& a) -> void; - auto instructionWRRAM(uint2 byte, uint8 imm) -> void; - auto instructionXNOR(uint7 reg, uint5 shift) -> void; - auto instructionXNOR(uint8 imm, uint5 shift) -> void; - auto instructionXOR(uint7 reg, uint5 shift) -> void; - auto instructionXOR(uint8 imm, uint5 shift) -> void; + auto instructionWRRAM(n2 byte, n24& a) -> void; + auto instructionWRRAM(n2 byte, n8 imm) -> void; + auto instructionXNOR(n7 reg, n5 shift) -> void; + auto instructionXNOR(n8 imm, n5 shift) -> void; + auto instructionXOR(n7 reg, n5 shift) -> void; + auto instructionXOR(n8 imm, n5 shift) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint16 programRAM[2][256]; //instruction cache - uint24 dataROM[1024]; - uint8 dataRAM[3072]; + n16 programRAM[2][256]; //instruction cache + n24 dataROM[1024]; + n8 dataRAM[3072]; //registers.cpp - auto readRegister(uint7 address) -> uint24; - auto writeRegister(uint7 address, uint24 data) -> void; + auto readRegister(n7 address) -> n24; + auto writeRegister(n7 address, n24 data) -> void; //disassembler.cpp - noinline auto disassembleInstruction(maybe pb = {}, maybe pc = {}) -> string; + noinline auto disassembleInstruction(maybe pb = {}, maybe pc = {}) -> string; noinline auto disassembleContext() -> string; protected: struct Registers { - uint15 pb; //program bank - uint8 pc; //program counter - - boolean n; //negative - boolean z; //zero - boolean c; //carry - boolean v; //overflow - boolean i; //interrupt - - uint24 a; //accumulator - uint15 p; //page register - uint48 mul; //multiplier - uint24 mdr; //bus memory data register - uint24 rom; //data ROM data buffer - uint24 ram; //data RAM data buffer - uint24 mar; //bus memory address register - uint24 dpr; //data RAM address pointer - uint24 gpr[16]; //general purpose registers + n15 pb; //program bank + n8 pc; //program counter + + b1 n; //negative + b1 z; //zero + b1 c; //carry + b1 v; //overflow + b1 i; //interrupt + + n24 a; //accumulator + n15 p; //page register + n48 mul; //multiplier + n24 mdr; //bus memory data register + n24 rom; //data ROM data buffer + n24 ram; //data RAM data buffer + n24 mar; //bus memory address register + n24 dpr; //data RAM address pointer + n24 gpr[16]; //general purpose registers } r; struct IO { - uint1 lock; - uint1 halt = 1; - uint1 irq; //0 = enable, 1 = disable - uint1 rom = 1; //0 = 2 ROMs, 1 = 1 ROM - uint8 vector[32]; + n1 lock; + n1 halt = 1; + n1 irq; //0 = enable, 1 = disable + n1 rom = 1; //0 = 2 ROMs, 1 = 1 ROM + n8 vector[32]; struct Wait { - uint3 rom = 3; - uint3 ram = 3; + n3 rom = 3; + n3 ram = 3; } wait; struct Suspend { - uint1 enable; - uint8 duration; + n1 enable; + n8 duration; } suspend; struct Cache { - uint1 enable; - uint1 page; - uint1 lock[2]; - uint24 address[2]; //cache address is in bytes; so 24-bit - uint24 base; //base address is also in bytes - uint15 pb; - uint8 pc; + n1 enable; + n1 page; + n1 lock[2]; + n24 address[2]; //cache address is in bytes; so 24-bit + n24 base; //base address is also in bytes + n15 pb; + n8 pc; } cache; struct DMA { - uint1 enable; - uint24 source; - uint24 target; - uint16 length; + n1 enable; + n24 source; + n24 target; + n16 length; } dma; struct Bus { - uint1 enable; - uint1 reading; - uint1 writing; - uint4 pending; - uint24 address; + n1 enable; + n1 reading; + n1 writing; + n4 pending; + n24 address; } bus; } io; - uint23 stack[8]; - function instructionTable[65536]; + n23 stack[8]; + function instructionTable[65536]; function disassembleTable[65536]; - auto disassembleADD(uint7 reg, uint5 shift) -> string; - auto disassembleADD(uint8 imm, uint5 shift) -> string; - auto disassembleAND(uint7 reg, uint5 shift) -> string; - auto disassembleAND(uint8 imm, uint5 shift) -> string; - auto disassembleASR(uint7 reg) -> string; - auto disassembleASR(uint5 imm) -> string; + auto disassembleADD(n7 reg, n5 shift) -> string; + auto disassembleADD(n8 imm, n5 shift) -> string; + auto disassembleAND(n7 reg, n5 shift) -> string; + auto disassembleAND(n8 imm, n5 shift) -> string; + auto disassembleASR(n7 reg) -> string; + auto disassembleASR(n5 imm) -> string; auto disassembleCLEAR() -> string; - auto disassembleCMP(uint7 reg, uint5 shift) -> string; - auto disassembleCMP(uint8 imm, uint5 shift) -> string; - auto disassembleCMPR(uint7 reg, uint5 shift) -> string; - auto disassembleCMPR(uint8 imm, uint5 shift) -> string; + auto disassembleCMP(n7 reg, n5 shift) -> string; + auto disassembleCMP(n8 imm, n5 shift) -> string; + auto disassembleCMPR(n7 reg, n5 shift) -> string; + auto disassembleCMPR(n8 imm, n5 shift) -> string; auto disassembleHALT() -> string; - auto disassembleINC(uint24& reg) -> string; - auto disassembleJMP(uint8 data, uint1 far, const uint1& take) -> string; - auto disassembleJSR(uint8 data, uint1 far, const uint1& take) -> string; - auto disassembleLD(uint24& out, uint7 reg) -> string; - auto disassembleLD(uint15& out, uint4 reg) -> string; - auto disassembleLD(uint24& out, uint8 imm) -> string; - auto disassembleLD(uint15& out, uint8 imm) -> string; - auto disassembleLDL(uint15& out, uint8 imm) -> string; - auto disassembleLDH(uint15& out, uint7 imm) -> string; - auto disassembleMUL(uint7 reg) -> string; - auto disassembleMUL(uint8 imm) -> string; + auto disassembleINC(n24& reg) -> string; + auto disassembleJMP(n8 data, n1 far, const n1& take) -> string; + auto disassembleJSR(n8 data, n1 far, const n1& take) -> string; + auto disassembleLD(n24& out, n7 reg) -> string; + auto disassembleLD(n15& out, n4 reg) -> string; + auto disassembleLD(n24& out, n8 imm) -> string; + auto disassembleLD(n15& out, n8 imm) -> string; + auto disassembleLDL(n15& out, n8 imm) -> string; + auto disassembleLDH(n15& out, n7 imm) -> string; + auto disassembleMUL(n7 reg) -> string; + auto disassembleMUL(n8 imm) -> string; auto disassembleNOP() -> string; - auto disassembleOR(uint7 reg, uint5 shift) -> string; - auto disassembleOR(uint8 imm, uint5 shift) -> string; - auto disassembleRDRAM(uint2 byte, uint24& a) -> string; - auto disassembleRDRAM(uint2 byte, uint8 imm) -> string; - auto disassembleRDROM(uint24& reg) -> string; - auto disassembleRDROM(uint10 imm) -> string; - auto disassembleROR(uint7 reg) -> string; - auto disassembleROR(uint5 imm) -> string; + auto disassembleOR(n7 reg, n5 shift) -> string; + auto disassembleOR(n8 imm, n5 shift) -> string; + auto disassembleRDRAM(n2 byte, n24& a) -> string; + auto disassembleRDRAM(n2 byte, n8 imm) -> string; + auto disassembleRDROM(n24& reg) -> string; + auto disassembleRDROM(n10 imm) -> string; + auto disassembleROR(n7 reg) -> string; + auto disassembleROR(n5 imm) -> string; auto disassembleRTS() -> string; - auto disassembleSHL(uint7 reg) -> string; - auto disassembleSHL(uint5 imm) -> string; - auto disassembleSHR(uint7 reg) -> string; - auto disassembleSHR(uint5 imm) -> string; - auto disassembleSKIP(uint1 take, const uint1& flag) -> string; - auto disassembleST(uint7 reg, uint24& in) -> string; - auto disassembleSUB(uint7 reg, uint5 shift) -> string; - auto disassembleSUB(uint8 imm, uint5 shift) -> string; - auto disassembleSUBR(uint7 reg, uint5 shift) -> string; - auto disassembleSUBR(uint8 imm, uint5 shift) -> string; - auto disassembleSWAP(uint24& a, uint4 reg) -> string; + auto disassembleSHL(n7 reg) -> string; + auto disassembleSHL(n5 imm) -> string; + auto disassembleSHR(n7 reg) -> string; + auto disassembleSHR(n5 imm) -> string; + auto disassembleSKIP(n1 take, const n1& flag) -> string; + auto disassembleST(n7 reg, n24& in) -> string; + auto disassembleSUB(n7 reg, n5 shift) -> string; + auto disassembleSUB(n8 imm, n5 shift) -> string; + auto disassembleSUBR(n7 reg, n5 shift) -> string; + auto disassembleSUBR(n8 imm, n5 shift) -> string; + auto disassembleSWAP(n24& a, n4 reg) -> string; auto disassembleSXB() -> string; auto disassembleSXW() -> string; auto disassembleWAIT() -> string; - auto disassembleWRRAM(uint2 byte, uint24& a) -> string; - auto disassembleWRRAM(uint2 byte, uint8 imm) -> string; - auto disassembleXNOR(uint7 reg, uint5 shift) -> string; - auto disassembleXNOR(uint8 imm, uint5 shift) -> string; - auto disassembleXOR(uint7 reg, uint5 shift) -> string; - auto disassembleXOR(uint8 imm, uint5 shift) -> string; + auto disassembleWRRAM(n2 byte, n24& a) -> string; + auto disassembleWRRAM(n2 byte, n8 imm) -> string; + auto disassembleXNOR(n7 reg, n5 shift) -> string; + auto disassembleXNOR(n8 imm, n5 shift) -> string; + auto disassembleXOR(n7 reg, n5 shift) -> string; + auto disassembleXOR(n8 imm, n5 shift) -> string; }; } diff --git a/ares/component/processor/hg51b/instruction.cpp b/ares/component/processor/hg51b/instruction.cpp index 82050c5861..7ed6df6174 100644 --- a/ares/component/processor/hg51b/instruction.cpp +++ b/ares/component/processor/hg51b/instruction.cpp @@ -8,625 +8,625 @@ HG51B::HG51B() { #define pattern(s) \ std::integral_constant::value - static const uint5 shifts[] = {0, 1, 8, 16}; + static const n5 shifts[] = {0, 1, 8, 16}; //NOP - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0000 00.. .... ...."); bind(opcode | null << 0, NOP); } //??? - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0000 01.. .... ...."); bind(opcode | null << 0, NOP); } //JMP imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0000 10f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JMP, data, far, 1); } //JMP EQ,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0000 11f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JMP, data, far, r.z); } //JMP GE,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0001 00f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JMP, data, far, r.c); } //JMP MI,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0001 01f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JMP, data, far, r.n); } //JMP VS,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0001 10f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JMP, data, far, r.v); } //WAIT - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0001 11.. .... ...."); bind(opcode | null << 0, WAIT); } //??? - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0010 00.. .... ...."); bind(opcode | null << 0, NOP); } //SKIP V - for(uint1 take : range( 2)) - for(uint7 null : range(128)) { + for(n1 take : range( 2)) + for(n7 null : range(128)) { auto opcode = pattern("0010 0100 .... ...t"); bind(opcode | take << 0 | null << 1, SKIP, take, r.v); } //SKIP C - for(uint1 take : range( 2)) - for(uint7 null : range(128)) { + for(n1 take : range( 2)) + for(n7 null : range(128)) { auto opcode = pattern("0010 0101 .... ...t"); bind(opcode | take << 0 | null << 1, SKIP, take, r.c); } //SKIP Z - for(uint1 take : range( 2)) - for(uint7 null : range(128)) { + for(n1 take : range( 2)) + for(n7 null : range(128)) { auto opcode = pattern("0010 0110 .... ...t"); bind(opcode | take << 0 | null << 1, SKIP, take, r.z); } //SKIP N - for(uint1 take : range( 2)) - for(uint7 null : range(128)) { + for(n1 take : range( 2)) + for(n7 null : range(128)) { auto opcode = pattern("0010 0111 .... ...t"); bind(opcode | take << 0 | null << 1, SKIP, take, r.n); } //JSR - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0010 10f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JSR, data, far, 1); } //JSR EQ,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0010 11f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JSR, data, far, r.z); } //JSR GE,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0011 00f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JSR, data, far, r.c); } //JSR MI,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0011 01f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JSR, data, far, r.n); } //JSR VS,imm - for(uint8 data : range(256)) - for(uint1 null : range( 2)) - for(uint1 far : range( 2)) { + for(n8 data : range(256)) + for(n1 null : range( 2)) + for(n1 far : range( 2)) { auto opcode = pattern("0011 10f. dddd dddd"); bind(opcode | data << 0 | null << 8 | far << 9, JSR, data, far, r.v); } //RTS - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0011 11.. .... ...."); bind(opcode | null << 0, RTS); } //INC MAR - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0100 00.. .... ...."); bind(opcode | null << 0, INC, r.mar); } //??? - for(uint10 null : range(1024)) { + for(n10 null : range(1024)) { auto opcode = pattern("0100 01.. .... ...."); bind(opcode | null << 0, NOP); } //CMPR A< void { // -auto HG51B::algorithmADD(uint24 x, uint24 y) -> uint24 { - int z = x + y; +auto HG51B::algorithmADD(n24 x, n24 y) -> n24 { + s32 z = x + y; r.n = z & 0x800000; - r.z = (uint24)z == 0; + r.z = (n24)z == 0; r.c = z > 0xffffff; r.v = ~(x ^ y) & (x ^ z) & 0x800000; return z; } -auto HG51B::algorithmAND(uint24 x, uint24 y) -> uint24 { +auto HG51B::algorithmAND(n24 x, n24 y) -> n24 { x = x & y; r.n = x & 0x800000; r.z = x == 0; return x; } -auto HG51B::algorithmASR(uint24 a, uint5 s) -> uint24 { +auto HG51B::algorithmASR(n24 a, n5 s) -> n24 { if(s > 24) s = 0; - a = (int24)a >> s; + a = (i24)a >> s; r.n = a & 0x800000; r.z = a == 0; return a; } -auto HG51B::algorithmMUL(int24 x, int24 y) -> uint48 { - return (int48)x * (int48)y; +auto HG51B::algorithmMUL(i24 x, i24 y) -> n48 { + return (i48)x * (i48)y; } -auto HG51B::algorithmOR(uint24 x, uint24 y) -> uint24 { +auto HG51B::algorithmOR(n24 x, n24 y) -> n24 { x = x | y; r.n = x & 0x800000; r.z = x == 0; return x; } -auto HG51B::algorithmROR(uint24 a, uint5 s) -> uint24 { +auto HG51B::algorithmROR(n24 a, n5 s) -> n24 { if(s > 24) s = 0; a = (a >> s) | (a << 24 - s); r.n = a & 0x800000; @@ -69,7 +69,7 @@ auto HG51B::algorithmROR(uint24 a, uint5 s) -> uint24 { return a; } -auto HG51B::algorithmSHL(uint24 a, uint5 s) -> uint24 { +auto HG51B::algorithmSHL(n24 a, n5 s) -> n24 { if(s > 24) s = 0; a = a << s; r.n = a & 0x800000; @@ -77,7 +77,7 @@ auto HG51B::algorithmSHL(uint24 a, uint5 s) -> uint24 { return a; } -auto HG51B::algorithmSHR(uint24 a, uint5 s) -> uint24 { +auto HG51B::algorithmSHR(n24 a, n5 s) -> n24 { if(s > 24) s = 0; a = a >> s; r.n = a & 0x800000; @@ -85,29 +85,29 @@ auto HG51B::algorithmSHR(uint24 a, uint5 s) -> uint24 { return a; } -auto HG51B::algorithmSUB(uint24 x, uint24 y) -> uint24 { - int z = x - y; +auto HG51B::algorithmSUB(n24 x, n24 y) -> n24 { + s32 z = x - y; r.n = z & 0x800000; - r.z = (uint24)z == 0; + r.z = (n24)z == 0; r.c = z >= 0; r.v = ~(x ^ y) & (x ^ z) & 0x800000; return z; } -auto HG51B::algorithmSX(uint24 x) -> uint24 { +auto HG51B::algorithmSX(n24 x) -> n24 { r.n = x & 0x800000; r.z = x == 0; return x; } -auto HG51B::algorithmXNOR(uint24 x, uint24 y) -> uint24 { +auto HG51B::algorithmXNOR(n24 x, n24 y) -> n24 { x = ~x ^ y; r.n = x & 0x800000; r.z = x == 0; return x; } -auto HG51B::algorithmXOR(uint24 x, uint24 y) -> uint24 { +auto HG51B::algorithmXOR(n24 x, n24 y) -> n24 { x = x ^ y; r.n = x & 0x800000; r.z = x == 0; @@ -116,27 +116,27 @@ auto HG51B::algorithmXOR(uint24 x, uint24 y) -> uint24 { // -auto HG51B::instructionADD(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionADD(n7 reg, n5 shift) -> void { r.a = algorithmADD(r.a << shift, readRegister(reg)); } -auto HG51B::instructionADD(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionADD(n8 imm, n5 shift) -> void { r.a = algorithmADD(r.a << shift, imm); } -auto HG51B::instructionAND(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionAND(n7 reg, n5 shift) -> void { r.a = algorithmAND(r.a << shift, readRegister(reg)); } -auto HG51B::instructionAND(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionAND(n8 imm, n5 shift) -> void { r.a = algorithmAND(r.a << shift, imm); } -auto HG51B::instructionASR(uint7 reg) -> void { +auto HG51B::instructionASR(n7 reg) -> void { r.a = algorithmASR(r.a, readRegister(reg)); } -auto HG51B::instructionASR(uint5 imm) -> void { +auto HG51B::instructionASR(n5 imm) -> void { r.a = algorithmASR(r.a, imm); } @@ -147,19 +147,19 @@ auto HG51B::instructionCLEAR() -> void { r.dpr = 0; } -auto HG51B::instructionCMP(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionCMP(n7 reg, n5 shift) -> void { algorithmSUB(r.a << shift, readRegister(reg)); } -auto HG51B::instructionCMP(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionCMP(n8 imm, n5 shift) -> void { algorithmSUB(r.a << shift, imm); } -auto HG51B::instructionCMPR(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionCMPR(n7 reg, n5 shift) -> void { algorithmSUB(readRegister(reg), r.a << shift); } -auto HG51B::instructionCMPR(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionCMPR(n8 imm, n5 shift) -> void { algorithmSUB(imm, r.a << shift); } @@ -167,18 +167,18 @@ auto HG51B::instructionHALT() -> void { halt(); } -auto HG51B::instructionINC(uint24& reg) -> void { +auto HG51B::instructionINC(n24& reg) -> void { reg++; } -auto HG51B::instructionJMP(uint8 data, uint1 far, const uint1& take) -> void { +auto HG51B::instructionJMP(n8 data, n1 far, const n1& take) -> void { if(!take) return; if(far) r.pb = r.p; r.pc = data; step(2); } -auto HG51B::instructionJSR(uint8 data, uint1 far, const uint1& take) -> void { +auto HG51B::instructionJSR(n8 data, n1 far, const n1& take) -> void { if(!take) return; push(); if(far) r.pb = r.p; @@ -186,74 +186,74 @@ auto HG51B::instructionJSR(uint8 data, uint1 far, const uint1& take) -> void { step(2); } -auto HG51B::instructionLD(uint24& out, uint7 reg) -> void { +auto HG51B::instructionLD(n24& out, n7 reg) -> void { out = readRegister(reg); } -auto HG51B::instructionLD(uint15& out, uint4 reg) -> void { +auto HG51B::instructionLD(n15& out, n4 reg) -> void { out = r.gpr[reg]; } -auto HG51B::instructionLD(uint24& out, uint8 imm) -> void { +auto HG51B::instructionLD(n24& out, n8 imm) -> void { out = imm; } -auto HG51B::instructionLD(uint15& out, uint8 imm) -> void { +auto HG51B::instructionLD(n15& out, n8 imm) -> void { out = imm; } -auto HG51B::instructionLDL(uint15& out, uint8 imm) -> void { +auto HG51B::instructionLDL(n15& out, n8 imm) -> void { out.bit(0,7) = imm; } -auto HG51B::instructionLDH(uint15& out, uint7 imm) -> void { +auto HG51B::instructionLDH(n15& out, n7 imm) -> void { out.bit(8,14) = imm; } -auto HG51B::instructionMUL(uint7 reg) -> void { +auto HG51B::instructionMUL(n7 reg) -> void { r.mul = algorithmMUL(r.a, readRegister(reg)); } -auto HG51B::instructionMUL(uint8 imm) -> void { +auto HG51B::instructionMUL(n8 imm) -> void { r.mul = algorithmMUL(r.a, imm); } auto HG51B::instructionNOP() -> void { } -auto HG51B::instructionOR(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionOR(n7 reg, n5 shift) -> void { r.a = algorithmOR(r.a << shift, readRegister(reg)); } -auto HG51B::instructionOR(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionOR(n8 imm, n5 shift) -> void { r.a = algorithmOR(r.a << shift, imm); } -auto HG51B::instructionRDRAM(uint2 byte, uint24& a) -> void { - uint12 address = a; +auto HG51B::instructionRDRAM(n2 byte, n24& a) -> void { + n12 address = a; if(address >= 0xc00) address -= 0x400; r.ram.byte(byte) = dataRAM[address]; } -auto HG51B::instructionRDRAM(uint2 byte, uint8 imm) -> void { - uint12 address = r.dpr + imm; +auto HG51B::instructionRDRAM(n2 byte, n8 imm) -> void { + n12 address = r.dpr + imm; if(address >= 0xc00) address -= 0x400; r.ram.byte(byte) = dataRAM[address]; } -auto HG51B::instructionRDROM(uint24& reg) -> void { - r.rom = dataROM[(uint10)reg]; +auto HG51B::instructionRDROM(n24& reg) -> void { + r.rom = dataROM[(n10)reg]; } -auto HG51B::instructionRDROM(uint10 imm) -> void { +auto HG51B::instructionRDROM(n10 imm) -> void { r.rom = dataROM[imm]; } -auto HG51B::instructionROR(uint7 reg) -> void { +auto HG51B::instructionROR(n7 reg) -> void { r.a = algorithmROR(r.a, readRegister(reg)); } -auto HG51B::instructionROR(uint5 imm) -> void { +auto HG51B::instructionROR(n5 imm) -> void { r.a = algorithmROR(r.a, imm); } @@ -262,58 +262,58 @@ auto HG51B::instructionRTS() -> void { step(2); } -auto HG51B::instructionSKIP(uint1 take, const uint1& flag) -> void { +auto HG51B::instructionSKIP(n1 take, const n1& flag) -> void { if(flag != take) return; advance(); step(1); } -auto HG51B::instructionSHL(uint7 reg) -> void { +auto HG51B::instructionSHL(n7 reg) -> void { r.a = algorithmSHL(r.a, readRegister(reg)); } -auto HG51B::instructionSHL(uint5 imm) -> void { +auto HG51B::instructionSHL(n5 imm) -> void { r.a = algorithmSHL(r.a, imm); } -auto HG51B::instructionSHR(uint7 reg) -> void { +auto HG51B::instructionSHR(n7 reg) -> void { r.a = algorithmSHR(r.a, readRegister(reg)); } -auto HG51B::instructionSHR(uint5 imm) -> void { +auto HG51B::instructionSHR(n5 imm) -> void { r.a = algorithmSHR(r.a, imm); } -auto HG51B::instructionST(uint7 reg, uint24& in) -> void { +auto HG51B::instructionST(n7 reg, n24& in) -> void { writeRegister(reg, in); } -auto HG51B::instructionSUB(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionSUB(n7 reg, n5 shift) -> void { r.a = algorithmSUB(r.a << shift, readRegister(reg)); } -auto HG51B::instructionSUB(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionSUB(n8 imm, n5 shift) -> void { r.a = algorithmSUB(r.a << shift, imm); } -auto HG51B::instructionSUBR(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionSUBR(n7 reg, n5 shift) -> void { r.a = algorithmSUB(readRegister(reg), r.a << shift); } -auto HG51B::instructionSUBR(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionSUBR(n8 imm, n5 shift) -> void { r.a = algorithmSUB(imm, r.a << shift); } -auto HG51B::instructionSWAP(uint24& a, uint4 reg) -> void { +auto HG51B::instructionSWAP(n24& a, n4 reg) -> void { swap(a, r.gpr[reg]); } auto HG51B::instructionSXB() -> void { - r.a = algorithmSX((int8)r.a); + r.a = algorithmSX((i8)r.a); } auto HG51B::instructionSXW() -> void { - r.a = algorithmSX((int16)r.a); + r.a = algorithmSX((i16)r.a); } auto HG51B::instructionWAIT() -> void { @@ -321,8 +321,8 @@ auto HG51B::instructionWAIT() -> void { return step(io.bus.pending); } -auto HG51B::instructionWRRAM(uint2 byte, uint24& a) -> void { - uint12 address = a; +auto HG51B::instructionWRRAM(n2 byte, n24& a) -> void { + n12 address = a; if(address >= 0xc00) address -= 0x400; switch(byte) { case 0: dataRAM[address] = r.ram >> 0; break; @@ -331,8 +331,8 @@ auto HG51B::instructionWRRAM(uint2 byte, uint24& a) -> void { } } -auto HG51B::instructionWRRAM(uint2 byte, uint8 imm) -> void { - uint12 address = r.dpr + imm; +auto HG51B::instructionWRRAM(n2 byte, n8 imm) -> void { + n12 address = r.dpr + imm; if(address >= 0xc00) address -= 0x400; switch(byte) { case 0: dataRAM[address] = r.ram >> 0; break; @@ -341,18 +341,18 @@ auto HG51B::instructionWRRAM(uint2 byte, uint8 imm) -> void { } } -auto HG51B::instructionXNOR(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionXNOR(n7 reg, n5 shift) -> void { r.a = algorithmXNOR(r.a << shift, readRegister(reg)); } -auto HG51B::instructionXNOR(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionXNOR(n8 imm, n5 shift) -> void { r.a = algorithmXNOR(r.a << shift, imm); } -auto HG51B::instructionXOR(uint7 reg, uint5 shift) -> void { +auto HG51B::instructionXOR(n7 reg, n5 shift) -> void { r.a = algorithmXOR(r.a << shift, readRegister(reg)); } -auto HG51B::instructionXOR(uint8 imm, uint5 shift) -> void { +auto HG51B::instructionXOR(n8 imm, n5 shift) -> void { r.a = algorithmXOR(r.a << shift, imm); } diff --git a/ares/component/processor/hg51b/registers.cpp b/ares/component/processor/hg51b/registers.cpp index edfb9327f3..212d1a302b 100644 --- a/ares/component/processor/hg51b/registers.cpp +++ b/ares/component/processor/hg51b/registers.cpp @@ -1,4 +1,4 @@ -auto HG51B::readRegister(uint7 address) -> uint24 { +auto HG51B::readRegister(n7 address) -> n24 { switch(address) { case 0x01: return r.mul.bit(24,47); case 0x02: return r.mul.bit( 0,23); @@ -62,7 +62,7 @@ auto HG51B::readRegister(uint7 address) -> uint24 { return 0x000000; //verified } -auto HG51B::writeRegister(uint7 address, uint24 data) -> void { +auto HG51B::writeRegister(n7 address, n24 data) -> void { switch(address) { case 0x01: r.mul.bit(24,47) = data; return; case 0x02: r.mul.bit( 0,23) = data; return; diff --git a/ares/component/processor/huc6280/algorithms.cpp b/ares/component/processor/huc6280/algorithms.cpp index 0db26032aa..d20371c13e 100644 --- a/ares/component/processor/huc6280/algorithms.cpp +++ b/ares/component/processor/huc6280/algorithms.cpp @@ -1,5 +1,5 @@ -auto HuC6280::algorithmADC(uint8 i) -> uint8 { - int16 o; +auto HuC6280::algorithmADC(n8 i) -> n8 { + i16 o; if(!D) { o = A + i + C; V = ~(A ^ i) & (A ^ o) & 0x80; @@ -12,19 +12,19 @@ auto HuC6280::algorithmADC(uint8 i) -> uint8 { if(o > 0x9f) o += 0x60; } C = o.bit(8); - Z = uint8(o) == 0; + Z = n8(o) == 0; N = o.bit(7); return o; } -auto HuC6280::algorithmAND(uint8 i) -> uint8 { - uint8 o = A & i; +auto HuC6280::algorithmAND(n8 i) -> n8 { + n8 o = A & i; Z = o == 0; N = o.bit(7); return o; } -auto HuC6280::algorithmASL(uint8 i) -> uint8 { +auto HuC6280::algorithmASL(n8 i) -> n8 { C = i.bit(7); i <<= 1; Z = i == 0; @@ -32,65 +32,65 @@ auto HuC6280::algorithmASL(uint8 i) -> uint8 { return i; } -auto HuC6280::algorithmBIT(uint8 i) -> uint8 { +auto HuC6280::algorithmBIT(n8 i) -> n8 { Z = (A & i) == 0; V = i.bit(6); N = i.bit(7); return A; } -auto HuC6280::algorithmCMP(uint8 i) -> uint8 { - uint9 o = A - i; +auto HuC6280::algorithmCMP(n8 i) -> n8 { + n9 o = A - i; C = !o.bit(8); - Z = uint8(o) == 0; + Z = n8(o) == 0; N = o.bit(7); return A; } -auto HuC6280::algorithmCPX(uint8 i) -> uint8 { - uint9 o = X - i; +auto HuC6280::algorithmCPX(n8 i) -> n8 { + n9 o = X - i; C = !o.bit(8); - Z = uint8(o) == 0; + Z = n8(o) == 0; N = o.bit(7); return X; } -auto HuC6280::algorithmCPY(uint8 i) -> uint8 { - uint9 o = Y - i; +auto HuC6280::algorithmCPY(n8 i) -> n8 { + n9 o = Y - i; C = !o.bit(8); - Z = uint8(o) == 0; + Z = n8(o) == 0; N = o.bit(7); return Y; } -auto HuC6280::algorithmDEC(uint8 i) -> uint8 { +auto HuC6280::algorithmDEC(n8 i) -> n8 { i--; Z = i == 0; N = i.bit(7); return i; } -auto HuC6280::algorithmEOR(uint8 i) -> uint8 { - uint8 o = A ^ i; +auto HuC6280::algorithmEOR(n8 i) -> n8 { + n8 o = A ^ i; Z = o == 0; N = o.bit(7); return o; } -auto HuC6280::algorithmINC(uint8 i) -> uint8 { +auto HuC6280::algorithmINC(n8 i) -> n8 { i++; Z = i == 0; N = i.bit(7); return i; } -auto HuC6280::algorithmLD(uint8 i) -> uint8 { +auto HuC6280::algorithmLD(n8 i) -> n8 { Z = i == 0; N = i.bit(7); return i; } -auto HuC6280::algorithmLSR(uint8 i) -> uint8 { +auto HuC6280::algorithmLSR(n8 i) -> n8 { C = i.bit(0); i >>= 1; Z = i == 0; @@ -98,14 +98,14 @@ auto HuC6280::algorithmLSR(uint8 i) -> uint8 { return i; } -auto HuC6280::algorithmORA(uint8 i) -> uint8 { - uint8 o = A | i; +auto HuC6280::algorithmORA(n8 i) -> n8 { + n8 o = A | i; Z = o == 0; N = o.bit(7); return o; } -auto HuC6280::algorithmROL(uint8 i) -> uint8 { +auto HuC6280::algorithmROL(n8 i) -> n8 { bool c = C; C = i.bit(7); i = i << 1 | c; @@ -114,7 +114,7 @@ auto HuC6280::algorithmROL(uint8 i) -> uint8 { return i; } -auto HuC6280::algorithmROR(uint8 i) -> uint8 { +auto HuC6280::algorithmROR(n8 i) -> n8 { bool c = C; C = i.bit(0); i = c << 7 | i >> 1; @@ -123,9 +123,9 @@ auto HuC6280::algorithmROR(uint8 i) -> uint8 { return i; } -auto HuC6280::algorithmSBC(uint8 i) -> uint8 { +auto HuC6280::algorithmSBC(n8 i) -> n8 { i ^= 0xff; - int16 o; + i16 o; if(!D) { o = A + i + C; V = ~(A ^ i) & (A ^ o) & 0x80; @@ -138,19 +138,19 @@ auto HuC6280::algorithmSBC(uint8 i) -> uint8 { if(o <= 0xff) o -= 0x60; } C = o.bit(8); - Z = uint8(o) == 0; + Z = n8(o) == 0; N = o.bit(7); return o; } -auto HuC6280::algorithmTRB(uint8 i) -> uint8 { +auto HuC6280::algorithmTRB(n8 i) -> n8 { Z = (A & i) == 0; V = i.bit(6); N = i.bit(7); return ~A & i; } -auto HuC6280::algorithmTSB(uint8 i) -> uint8 { +auto HuC6280::algorithmTSB(n8 i) -> n8 { Z = (A & i) == 0; V = i.bit(6); N = i.bit(7); @@ -159,26 +159,26 @@ auto HuC6280::algorithmTSB(uint8 i) -> uint8 { // -auto HuC6280::algorithmTAI(uint16& source, uint16& target, bool alternate) -> void { +auto HuC6280::algorithmTAI(n16& source, n16& target, bool alternate) -> void { !alternate ? source++ : source--; target++; } -auto HuC6280::algorithmTDD(uint16& source, uint16& target, bool) -> void { +auto HuC6280::algorithmTDD(n16& source, n16& target, bool) -> void { source--; target--; } -auto HuC6280::algorithmTIA(uint16& source, uint16& target, bool alternate) -> void { +auto HuC6280::algorithmTIA(n16& source, n16& target, bool alternate) -> void { source++; !alternate ? target++ : target--; } -auto HuC6280::algorithmTII(uint16& source, uint16& target, bool) -> void { +auto HuC6280::algorithmTII(n16& source, n16& target, bool) -> void { source++; target++; } -auto HuC6280::algorithmTIN(uint16& source, uint16& target, bool) -> void { +auto HuC6280::algorithmTIN(n16& source, n16& target, bool) -> void { source++; } diff --git a/ares/component/processor/huc6280/disassembler.cpp b/ares/component/processor/huc6280/disassembler.cpp index 0e87ec9e6c..3e814fa9e8 100644 --- a/ares/component/processor/huc6280/disassembler.cpp +++ b/ares/component/processor/huc6280/disassembler.cpp @@ -1,51 +1,51 @@ auto HuC6280::disassembleInstruction() -> string { - uint16 pc = r.pc; - maybe effectiveAddress; + n16 pc = r.pc; + maybe effectiveAddress; string s; - auto readByte = [&]() -> uint8 { - uint8 data = read(MPR[pc >> 13], pc & 0x1fff); + auto readByte = [&]() -> n8 { + n8 data = read(MPR[pc >> 13], pc & 0x1fff); return pc++, data; }; - auto readWord = [&]() -> uint16 { - uint16 data = readByte() << 0; + auto readWord = [&]() -> n16 { + n16 data = readByte() << 0; return data | readByte() << 8; }; - auto computeAbsolute = [&](uint16 address) { + auto computeAbsolute = [&](n16 address) { effectiveAddress = MPR[address >> 13] << 16 | address & 0x1fff; }; - auto computeIndirect = [&](uint8 address) { - uint16 absolute = 0; + auto computeIndirect = [&](n8 address) { + n16 absolute = 0; absolute |= read(MPR[1], address + 0) << 0; absolute |= read(MPR[1], address + 1) << 8; effectiveAddress = absolute; }; - auto computeIndirectX = [&](uint8 address) { - uint16 absolute = 0; + auto computeIndirectX = [&](n8 address) { + n16 absolute = 0; absolute |= read(MPR[1], address + r.x + 0) << 0; absolute |= read(MPR[1], address + r.x + 1) << 8; effectiveAddress = absolute; }; - auto computeIndirectY = [&](uint8 address) { - uint16 absolute = 0; + auto computeIndirectY = [&](n8 address) { + n16 absolute = 0; absolute |= read(MPR[1], address + 0) << 0; absolute |= read(MPR[1], address + 1) << 8; effectiveAddress = absolute + r.y; }; - auto computeIndirectLong = [&](uint16 address, uint8 index = 0) { - uint16 absolute = 0; + auto computeIndirectLong = [&](n16 address, n8 index = 0) { + n16 absolute = 0; absolute |= read(MPR[address >> 13], address & 0x1fff) << 0; address++; absolute |= read(MPR[address >> 13], address & 0x1fff) << 8; effectiveAddress = absolute + index; }; - auto computeZeroPage = [&](uint8 address) { + auto computeZeroPage = [&](n8 address) { effectiveAddress = MPR[1] << 16 | address; }; @@ -103,8 +103,8 @@ auto HuC6280::disassembleInstruction() -> string { auto relative = [&]() -> string { auto displacement = readByte(); - computeAbsolute(pc + (int8)displacement); - return {"$", hex(pc + (int8)displacement, 4L)}; + computeAbsolute(pc + (i8)displacement); + return {"$", hex(pc + (i8)displacement, 4L)}; }; auto zeropage = [&]() -> string { @@ -128,7 +128,7 @@ auto HuC6280::disassembleInstruction() -> string { auto immediateAbsolute = [&](string index = "") -> string { auto immediate = readByte(); auto absolute = readWord(); - computeAbsolute(absolute + (index == "x" ? r.x : (uint8)0)); + computeAbsolute(absolute + (index == "x" ? r.x : (n8)0)); if(index) index.prepend(","); return {"#$", hex(immediate, 2L), ",$", hex(absolute, 4L), index}; }; @@ -136,22 +136,22 @@ auto HuC6280::disassembleInstruction() -> string { auto immediateZeropage = [&](string index = "") -> string { auto immediate = readByte(); auto zeroPage = readByte(); - computeZeroPage(zeroPage + (index == "x" ? r.x : (uint8)0)); + computeZeroPage(zeroPage + (index == "x" ? r.x : (n8)0)); if(index) index.prepend(","); return {"#$", hex(immediate, 2L), ",$", hex(zeroPage, 2L), index}; }; - auto zeropageBit = [&](uint3 bit) -> string { + auto zeropageBit = [&](n3 bit) -> string { auto zeroPage = readByte(); computeZeroPage(zeroPage); return {"$", hex(zeroPage, 2L), ":", bit}; }; - auto zeropageBitRelative = [&](uint3 bit) -> string { + auto zeropageBitRelative = [&](n3 bit) -> string { auto zeroPage = readByte(); auto displacement = readByte(); computeZeroPage(zeroPage); - return {"$", hex(zeroPage, 2L), ":", bit, ",$", hex(pc + (int8)displacement, 4L)}; + return {"$", hex(zeroPage, 2L), ":", bit, ",$", hex(pc + (i8)displacement, 4L)}; }; auto blockMove = [&]() -> string { @@ -161,7 +161,7 @@ auto HuC6280::disassembleInstruction() -> string { return {"$", hex(source, 4L), ",$", hex(target, 4L), ",$", hex(length, 4L)}; }; - uint8 opcode = readByte(); + n8 opcode = readByte(); #define op(id, name, ...) case id: o = {name, " ", vector{__VA_ARGS__}.merge(",")}; break; string o; diff --git a/ares/component/processor/huc6280/huc6280.hpp b/ares/component/processor/huc6280/huc6280.hpp index 8c298a63c2..7d2a98a9ee 100644 --- a/ares/component/processor/huc6280/huc6280.hpp +++ b/ares/component/processor/huc6280/huc6280.hpp @@ -5,108 +5,108 @@ namespace ares { struct HuC6280 { - virtual auto step(uint clocks) -> void = 0; - virtual auto read(uint8 bank, uint13 address) -> uint8 = 0; - virtual auto write(uint8 bank, uint13 address, uint8 data) -> void = 0; - virtual auto store(uint2 address, uint8 data) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; + virtual auto read(n8 bank, n13 address) -> n8 = 0; + virtual auto write(n8 bank, n13 address, n8 data) -> void = 0; + virtual auto store(n2 address, n8 data) -> void = 0; virtual auto lastCycle() -> void = 0; //huc6280.cpp auto power() -> void; //memory.cpp - auto load8(uint8) -> uint8; - auto load16(uint16) -> uint8; - auto store8(uint8, uint8) -> void; - auto store16(uint16, uint8) -> void; + auto load8(n8) -> n8; + auto load16(n16) -> n8; + auto store8(n8, n8) -> void; + auto store16(n16, n8) -> void; auto idle() -> void; - auto opcode() -> uint8; - auto operand() -> uint8; + auto opcode() -> n8; + auto operand() -> n8; - auto push(uint8) -> void; - auto pull() -> uint8; + auto push(n8) -> void; + auto pull() -> n8; //instructions.cpp - using fp = auto (HuC6280::*)(uint8) -> uint8; - auto algorithmADC(uint8) -> uint8; - auto algorithmAND(uint8) -> uint8; - auto algorithmASL(uint8) -> uint8; - auto algorithmBIT(uint8) -> uint8; - auto algorithmCMP(uint8) -> uint8; - auto algorithmCPX(uint8) -> uint8; - auto algorithmCPY(uint8) -> uint8; - auto algorithmDEC(uint8) -> uint8; - auto algorithmEOR(uint8) -> uint8; - auto algorithmINC(uint8) -> uint8; - auto algorithmLD (uint8) -> uint8; - auto algorithmLSR(uint8) -> uint8; - auto algorithmORA(uint8) -> uint8; - auto algorithmROL(uint8) -> uint8; - auto algorithmROR(uint8) -> uint8; - auto algorithmSBC(uint8) -> uint8; - auto algorithmTRB(uint8) -> uint8; - auto algorithmTSB(uint8) -> uint8; - - using bp = auto (HuC6280::*)(uint16&, uint16&, bool) -> void; - auto algorithmTAI(uint16&, uint16&, bool) -> void; - auto algorithmTDD(uint16&, uint16&, bool) -> void; - auto algorithmTIA(uint16&, uint16&, bool) -> void; - auto algorithmTII(uint16&, uint16&, bool) -> void; - auto algorithmTIN(uint16&, uint16&, bool) -> void; + using fp = auto (HuC6280::*)(n8) -> n8; + auto algorithmADC(n8) -> n8; + auto algorithmAND(n8) -> n8; + auto algorithmASL(n8) -> n8; + auto algorithmBIT(n8) -> n8; + auto algorithmCMP(n8) -> n8; + auto algorithmCPX(n8) -> n8; + auto algorithmCPY(n8) -> n8; + auto algorithmDEC(n8) -> n8; + auto algorithmEOR(n8) -> n8; + auto algorithmINC(n8) -> n8; + auto algorithmLD (n8) -> n8; + auto algorithmLSR(n8) -> n8; + auto algorithmORA(n8) -> n8; + auto algorithmROL(n8) -> n8; + auto algorithmROR(n8) -> n8; + auto algorithmSBC(n8) -> n8; + auto algorithmTRB(n8) -> n8; + auto algorithmTSB(n8) -> n8; + + using bp = auto (HuC6280::*)(n16&, n16&, bool) -> void; + auto algorithmTAI(n16&, n16&, bool) -> void; + auto algorithmTDD(n16&, n16&, bool) -> void; + auto algorithmTIA(n16&, n16&, bool) -> void; + auto algorithmTII(n16&, n16&, bool) -> void; + auto algorithmTIN(n16&, n16&, bool) -> void; //instruction.cpp - auto interrupt(uint16 vector) -> void; + auto interrupt(n16 vector) -> void; auto instruction() -> void; //instructions.cpp - auto instructionAbsoluteModify(fp, uint8 = 0) -> void; - auto instructionAbsoluteRead(fp, uint8&, uint8 = 0) -> void; - auto instructionAbsoluteReadMemory(fp, uint8 = 0) -> void; - auto instructionAbsoluteWrite(uint8, uint8 = 0) -> void; + auto instructionAbsoluteModify(fp, n8 = 0) -> void; + auto instructionAbsoluteRead(fp, n8&, n8 = 0) -> void; + auto instructionAbsoluteReadMemory(fp, n8 = 0) -> void; + auto instructionAbsoluteWrite(n8, n8 = 0) -> void; auto instructionBlockMove(bp) -> void; auto instructionBranch(bool) -> void; - auto instructionBranchIfBitReset(uint3) -> void; - auto instructionBranchIfBitSet(uint3) -> void; + auto instructionBranchIfBitReset(n3) -> void; + auto instructionBranchIfBitSet(n3) -> void; auto instructionBranchSubroutine() -> void; auto instructionBreak() -> void; auto instructionCallAbsolute() -> void; auto instructionChangeSpeedLow() -> void; auto instructionChangeSpeedHigh() -> void; - auto instructionClear(uint8&) -> void; + auto instructionClear(n8&) -> void; auto instructionClear(bool&) -> void; - auto instructionImmediate(fp, uint8&) -> void; + auto instructionImmediate(fp, n8&) -> void; auto instructionImmediateMemory(fp) -> void; - auto instructionImplied(fp, uint8&) -> void; - auto instructionIndirectRead(fp, uint8&, uint8 = 0) -> void; - auto instructionIndirectReadMemory(fp, uint8 = 0) -> void; - auto instructionIndirectWrite(uint8, uint8 = 0) -> void; - auto instructionIndirectYRead(fp, uint8&) -> void; + auto instructionImplied(fp, n8&) -> void; + auto instructionIndirectRead(fp, n8&, n8 = 0) -> void; + auto instructionIndirectReadMemory(fp, n8 = 0) -> void; + auto instructionIndirectWrite(n8, n8 = 0) -> void; + auto instructionIndirectYRead(fp, n8&) -> void; auto instructionIndirectYReadMemory(fp) -> void; - auto instructionIndirectYWrite(uint8) -> void; + auto instructionIndirectYWrite(n8) -> void; auto instructionJumpAbsolute() -> void; - auto instructionJumpIndirect(uint8 = 0) -> void; + auto instructionJumpIndirect(n8 = 0) -> void; auto instructionNoOperation() -> void; - auto instructionPull(uint8&) -> void; + auto instructionPull(n8&) -> void; auto instructionPullP() -> void; - auto instructionPush(uint8) -> void; - auto instructionResetMemoryBit(uint3) -> void; + auto instructionPush(n8) -> void; + auto instructionResetMemoryBit(n3) -> void; auto instructionReturnInterrupt() -> void; auto instructionReturnSubroutine() -> void; auto instructionSet(bool&) -> void; - auto instructionSetMemoryBit(uint3) -> void; - auto instructionStoreImplied(uint2) -> void; - auto instructionSwap(uint8&, uint8&) -> void; - auto instructionTestAbsolute(uint8 = 0) -> void; - auto instructionTestZeroPage(uint8 = 0) -> void; - auto instructionTransfer(uint8&, uint8&) -> void; + auto instructionSetMemoryBit(n3) -> void; + auto instructionStoreImplied(n2) -> void; + auto instructionSwap(n8&, n8&) -> void; + auto instructionTestAbsolute(n8 = 0) -> void; + auto instructionTestZeroPage(n8 = 0) -> void; + auto instructionTransfer(n8&, n8&) -> void; auto instructionTransferAccumulatorToMPR() -> void; auto instructionTransferMPRToAccumulator() -> void; auto instructionTransferXS() -> void; - auto instructionZeroPageModify(fp, uint8 = 0) -> void; - auto instructionZeroPageRead(fp, uint8&, uint8 = 0) -> void; - auto instructionZeroPageReadMemory(fp, uint8 = 0) -> void; - auto instructionZeroPageWrite(uint8, uint8 = 0) -> void; + auto instructionZeroPageModify(fp, n8 = 0) -> void; + auto instructionZeroPageRead(fp, n8&, n8 = 0) -> void; + auto instructionZeroPageReadMemory(fp, n8 = 0) -> void; + auto instructionZeroPageWrite(n8, n8 = 0) -> void; //disassembler.cpp auto disassembleInstruction() -> string; @@ -125,15 +125,15 @@ struct HuC6280 { bool v; //overflow bool n; //negative - operator uint8() const { + operator n8() const { return c << 0 | z << 1 | i << 2 | d << 3 | b << 4 | t << 5 | v << 6 | n << 7; } - auto operator()() const -> uint8 { - return operator uint8(); + auto operator()() const -> n8 { + return operator n8(); } - auto& operator=(uint8 data) { + auto& operator=(n8 data) { c = data.bit(0); z = data.bit(1); i = data.bit(2); @@ -147,15 +147,15 @@ struct HuC6280 { }; struct Registers { - uint8 a; - uint8 x; - uint8 y; - uint8 s; - uint16 pc; - uint8 mpr[8]; - uint8 mpl; //MPR latch - uint8 cs; //code speed (3 = fast, 12 = slow) - Flags p; + n8 a; + n8 x; + n8 y; + n8 s; + n16 pc; + n8 mpr[8]; + n8 mpl; //MPR latch + n8 cs; //code speed (3 = fast, 12 = slow) + Flags p; } r; bool blockMove; diff --git a/ares/component/processor/huc6280/instruction.cpp b/ares/component/processor/huc6280/instruction.cpp index 08edcebf7d..518d7461ba 100644 --- a/ares/component/processor/huc6280/instruction.cpp +++ b/ares/component/processor/huc6280/instruction.cpp @@ -1,7 +1,7 @@ #define op(id, name, ...) case id: return instruction##name(__VA_ARGS__); #define fp(name) &HuC6280::algorithm##name -auto HuC6280::interrupt(uint16 vector) -> void { +auto HuC6280::interrupt(n16 vector) -> void { idle(); idle(); idle(); diff --git a/ares/component/processor/huc6280/instructions.cpp b/ares/component/processor/huc6280/instructions.cpp index baf9bfafcb..1d187b006d 100644 --- a/ares/component/processor/huc6280/instructions.cpp +++ b/ares/component/processor/huc6280/instructions.cpp @@ -1,5 +1,5 @@ -auto HuC6280::instructionAbsoluteModify(fp alu, uint8 index) -> void { - uint16 absolute = operand(); +auto HuC6280::instructionAbsoluteModify(fp alu, n8 index) -> void { + n16 absolute = operand(); absolute |= operand() << 8; idle(); idle(); @@ -7,18 +7,18 @@ auto HuC6280::instructionAbsoluteModify(fp alu, uint8 index) -> void { L store16(absolute + index, data); } -auto HuC6280::instructionAbsoluteRead(fp alu, uint8& data, uint8 index) -> void { - uint16 absolute = operand(); +auto HuC6280::instructionAbsoluteRead(fp alu, n8& data, n8 index) -> void { + n16 absolute = operand(); absolute |= operand() << 8; idle(); L data = ALU(load16(absolute + index)); } -auto HuC6280::instructionAbsoluteReadMemory(fp alu, uint8 index) -> void { +auto HuC6280::instructionAbsoluteReadMemory(fp alu, n8 index) -> void { auto a = A; A = load8(X); - uint16 absolute = operand(); + n16 absolute = operand(); absolute |= operand() << 8; idle(); A = ALU(load16(absolute + index)); @@ -27,19 +27,19 @@ L store8(X, A); A = a; } -auto HuC6280::instructionAbsoluteWrite(uint8 data, uint8 index) -> void { - uint16 absolute = operand(); +auto HuC6280::instructionAbsoluteWrite(n8 data, n8 index) -> void { + n16 absolute = operand(); absolute |= operand() << 8; idle(); L store16(absolute + index, data); } auto HuC6280::instructionBlockMove(bp alu) -> void { - uint16 source = operand(); + n16 source = operand(); source |= operand() << 8; - uint16 target = operand(); + n16 target = operand(); target |= operand() << 8; - uint16 length = operand(); + n16 length = operand(); length |= operand() << 8; push(Y); push(A); @@ -73,11 +73,11 @@ auto HuC6280::instructionBranch(bool take) -> void { auto displacement = operand(); idle(); L idle(); - PC += (int8)displacement; + PC += (i8)displacement; } } -auto HuC6280::instructionBranchIfBitReset(uint3 index) -> void { +auto HuC6280::instructionBranchIfBitReset(n3 index) -> void { auto zeropage = operand(); auto displacement = operand(); idle(); @@ -86,11 +86,11 @@ L auto data = load8(zeropage); if(data.bit(index) == 0) { idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } } -auto HuC6280::instructionBranchIfBitSet(uint3 index) -> void { +auto HuC6280::instructionBranchIfBitSet(n3 index) -> void { auto zeropage = operand(); auto displacement = operand(); idle(); @@ -99,7 +99,7 @@ L auto data = load8(zeropage); if(data.bit(index) == 1) { idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } } @@ -111,7 +111,7 @@ auto HuC6280::instructionBranchSubroutine() -> void { idle(); push(PC - 1 >> 8); L push(PC - 1 >> 0); - PC += (int8)displacement; + PC += (i8)displacement; } auto HuC6280::instructionBreak() -> void { @@ -128,7 +128,7 @@ L PC.byte(1) = load16(0xfff7); } auto HuC6280::instructionCallAbsolute() -> void { - uint16 address = operand(); + n16 address = operand(); address |= operand() << 8; idle(); idle(); @@ -149,7 +149,7 @@ auto HuC6280::instructionChangeSpeedHigh() -> void { L idle(); } -auto HuC6280::instructionClear(uint8& data) -> void { +auto HuC6280::instructionClear(n8& data) -> void { L idle(); data = 0; } @@ -159,7 +159,7 @@ L idle(); flag = 0; } -auto HuC6280::instructionImmediate(fp alu, uint8& data) -> void { +auto HuC6280::instructionImmediate(fp alu, n8& data) -> void { L data = ALU(operand()); } @@ -173,27 +173,27 @@ L store8(X, A); A = a; } -auto HuC6280::instructionImplied(fp alu, uint8& data) -> void { +auto HuC6280::instructionImplied(fp alu, n8& data) -> void { L idle(); data = ALU(data); } -auto HuC6280::instructionIndirectRead(fp alu, uint8& data, uint8 index) -> void { +auto HuC6280::instructionIndirectRead(fp alu, n8& data, n8 index) -> void { auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + index + 0); + n16 absolute = load8(zeropage + index + 0); absolute |= load8(zeropage + index + 1) << 8; idle(); L data = ALU(load16(absolute)); } -auto HuC6280::instructionIndirectReadMemory(fp alu, uint8 index) -> void { +auto HuC6280::instructionIndirectReadMemory(fp alu, n8 index) -> void { auto a = A; A = load8(X); auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + index + 0); + n16 absolute = load8(zeropage + index + 0); absolute |= load8(zeropage + index + 1) << 8; idle(); A = ALU(load16(absolute)); @@ -202,19 +202,19 @@ L store8(X, A); A = a; } -auto HuC6280::instructionIndirectWrite(uint8 data, uint8 index) -> void { +auto HuC6280::instructionIndirectWrite(n8 data, n8 index) -> void { auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + index + 0); + n16 absolute = load8(zeropage + index + 0); absolute |= load8(zeropage + index + 1) << 8; idle(); L store16(absolute, data); } -auto HuC6280::instructionIndirectYRead(fp alu, uint8& data) -> void { +auto HuC6280::instructionIndirectYRead(fp alu, n8& data) -> void { auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + 0); + n16 absolute = load8(zeropage + 0); absolute |= load8(zeropage + 1) << 8; idle(); L data = ALU(load16(absolute + Y)); @@ -226,7 +226,7 @@ auto HuC6280::instructionIndirectYReadMemory(fp alu) -> void { auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + 0); + n16 absolute = load8(zeropage + 0); absolute |= load8(zeropage + 1) << 8; idle(); A = ALU(load16(absolute + Y)); @@ -235,24 +235,24 @@ L store8(X, A); A = a; } -auto HuC6280::instructionIndirectYWrite(uint8 data) -> void { +auto HuC6280::instructionIndirectYWrite(n8 data) -> void { auto zeropage = operand(); idle(); - uint16 absolute = load8(zeropage + 0); + n16 absolute = load8(zeropage + 0); absolute |= load8(zeropage + 1) << 8; idle(); L store16(absolute + Y, data); } auto HuC6280::instructionJumpAbsolute() -> void { - uint16 address = operand(); + n16 address = operand(); address |= operand() << 8; L idle(); PC = address; } -auto HuC6280::instructionJumpIndirect(uint8 index) -> void { - uint16 address = operand(); +auto HuC6280::instructionJumpIndirect(n8 index) -> void { + n16 address = operand(); address |= operand() << 8; idle(); idle(); @@ -264,7 +264,7 @@ auto HuC6280::instructionNoOperation() -> void { L idle(); } -auto HuC6280::instructionPull(uint8& data) -> void { +auto HuC6280::instructionPull(n8& data) -> void { idle(); idle(); L data = pull(); @@ -278,12 +278,12 @@ auto HuC6280::instructionPullP() -> void { L P = pull() | 0x10; //B flag is set } -auto HuC6280::instructionPush(uint8 data) -> void { +auto HuC6280::instructionPush(n8 data) -> void { idle(); L push(data); } -auto HuC6280::instructionResetMemoryBit(uint3 index) -> void { +auto HuC6280::instructionResetMemoryBit(n3 index) -> void { auto zeropage = operand(); idle(); idle(); @@ -317,7 +317,7 @@ L idle(); flag = 1; } -auto HuC6280::instructionSetMemoryBit(uint3 index) -> void { +auto HuC6280::instructionSetMemoryBit(n3 index) -> void { auto zeropage = operand(); idle(); idle(); @@ -327,45 +327,45 @@ auto HuC6280::instructionSetMemoryBit(uint3 index) -> void { L store8(zeropage, data); } -auto HuC6280::instructionStoreImplied(uint2 index) -> void { +auto HuC6280::instructionStoreImplied(n2 index) -> void { auto data = operand(); idle(); idle(); L store(index, data); } -auto HuC6280::instructionSwap(uint8& lhs, uint8& rhs) -> void { +auto HuC6280::instructionSwap(n8& lhs, n8& rhs) -> void { idle(); L idle(); swap(lhs, rhs); } -auto HuC6280::instructionTestAbsolute(uint8 index) -> void { +auto HuC6280::instructionTestAbsolute(n8 index) -> void { auto mask = operand(); - uint16 absolute = operand(); + n16 absolute = operand(); absolute |= operand() << 8; idle(); idle(); idle(); -L uint8 data = load16(absolute + index); +L n8 data = load16(absolute + index); Z = (data & mask) == 0; V = data.bit(6); N = data.bit(7); } -auto HuC6280::instructionTestZeroPage(uint8 index) -> void { +auto HuC6280::instructionTestZeroPage(n8 index) -> void { auto mask = operand(); auto zeropage = operand(); idle(); idle(); idle(); -L uint8 data = load8(zeropage + index); +L n8 data = load8(zeropage + index); Z = (data & mask) == 0; V = data.bit(6); N = data.bit(7); } -auto HuC6280::instructionTransfer(uint8& source, uint8& target) -> void { +auto HuC6280::instructionTransfer(n8& source, n8& target) -> void { L idle(); target = source; Z = target == 0; @@ -377,7 +377,7 @@ auto HuC6280::instructionTransferAccumulatorToMPR() -> void { idle(); idle(); L idle(); - for(uint index : range(8)) { + for(u32 index : range(8)) { if(mask.bit(index)) MPR[index] = MPL = A; } } @@ -387,7 +387,7 @@ auto HuC6280::instructionTransferMPRToAccumulator() -> void { idle(); L idle(); if(mask) MPL = ~0; - for(uint index : range(8)) { + for(u32 index : range(8)) { //exact logic if multiple bits are set is unknown; but it is combinatorial if(mask.bit(index)) MPL &= MPR[index]; } @@ -400,7 +400,7 @@ L idle(); S = X; } -auto HuC6280::instructionZeroPageModify(fp alu, uint8 index) -> void { +auto HuC6280::instructionZeroPageModify(fp alu, n8 index) -> void { auto zeropage = operand(); idle(); idle(); @@ -408,13 +408,13 @@ auto HuC6280::instructionZeroPageModify(fp alu, uint8 index) -> void { L store8(zeropage + index, data); } -auto HuC6280::instructionZeroPageRead(fp alu, uint8& data, uint8 index) -> void { +auto HuC6280::instructionZeroPageRead(fp alu, n8& data, n8 index) -> void { auto zeropage = operand(); idle(); L data = ALU(load8(zeropage + index)); } -auto HuC6280::instructionZeroPageReadMemory(fp alu, uint8 index) -> void { +auto HuC6280::instructionZeroPageReadMemory(fp alu, n8 index) -> void { auto a = A; A = load8(X); @@ -426,7 +426,7 @@ L store8(X, A); A = a; } -auto HuC6280::instructionZeroPageWrite(uint8 data, uint8 index) -> void { +auto HuC6280::instructionZeroPageWrite(n8 data, n8 index) -> void { auto zeropage = operand(); idle(); L store8(zeropage + index, data); diff --git a/ares/component/processor/huc6280/memory.cpp b/ares/component/processor/huc6280/memory.cpp index d551a664e9..0231ec3161 100644 --- a/ares/component/processor/huc6280/memory.cpp +++ b/ares/component/processor/huc6280/memory.cpp @@ -1,21 +1,21 @@ -inline auto HuC6280::load8(uint8 address) -> uint8 { +inline auto HuC6280::load8(n8 address) -> n8 { step(CS); return read(MPR[1], address); } -inline auto HuC6280::load16(uint16 address) -> uint8 { +inline auto HuC6280::load16(n16 address) -> n8 { step(CS); - return read(MPR[address >> 13], (uint13)address); + return read(MPR[address >> 13], (n13)address); } -inline auto HuC6280::store8(uint8 address, uint8 data) -> void { +inline auto HuC6280::store8(n8 address, n8 data) -> void { step(CS); return write(MPR[1], address, data); } -inline auto HuC6280::store16(uint16 address, uint8 data) -> void { +inline auto HuC6280::store16(n16 address, n8 data) -> void { step(CS); - return write(MPR[address >> 13], (uint13)address, data); + return write(MPR[address >> 13], (n13)address, data); } // @@ -24,22 +24,22 @@ auto HuC6280::idle() -> void { step(CS); } -inline auto HuC6280::opcode() -> uint8 { +inline auto HuC6280::opcode() -> n8 { return load16(PC++); } -inline auto HuC6280::operand() -> uint8 { +inline auto HuC6280::operand() -> n8 { return load16(PC++); } // -inline auto HuC6280::push(uint8 data) -> void { +inline auto HuC6280::push(n8 data) -> void { step(CS); write(MPR[1], 0x0100 | S--, data); } -inline auto HuC6280::pull() -> uint8 { +inline auto HuC6280::pull() -> n8 { step(CS); return read(MPR[1], 0x0100 | ++S); } diff --git a/ares/component/processor/m68k/algorithms.cpp b/ares/component/processor/m68k/algorithms.cpp index a699f1f1a6..ed14254467 100644 --- a/ares/component/processor/m68k/algorithms.cpp +++ b/ares/component/processor/m68k/algorithms.cpp @@ -1,5 +1,5 @@ -template auto M68K::ADD(uint32 source, uint32 target) -> uint32 { - auto result = (uint64)source + target; +template auto M68K::ADD(n32 source, n32 target) -> n32 { + auto result = (n64)source + target; if(extend) result += r.x; r.c = sign(result >> 1) < 0; @@ -11,8 +11,8 @@ template auto M68K::ADD(uint32 source, uint32 target) -> return clip(result); } -template auto M68K::AND(uint32 source, uint32 target) -> uint32 { - uint32 result = target & source; +template auto M68K::AND(n32 source, n32 target) -> n32 { + n32 result = target & source; r.c = 0; r.v = 0; @@ -22,12 +22,12 @@ template auto M68K::AND(uint32 source, uint32 target) -> uint32 { return clip(result); } -template auto M68K::ASL(uint32 result, uint shift) -> uint32 { +template auto M68K::ASL(n32 result, u32 shift) -> n32 { bool carry = false; - uint32 overflow = 0; + n32 overflow = 0; for(auto _ : range(shift)) { carry = result & msb(); - uint32 before = result; + n32 before = result; result <<= 1; overflow |= before ^ result; } @@ -41,12 +41,12 @@ template auto M68K::ASL(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::ASR(uint32 result, uint shift) -> uint32 { +template auto M68K::ASR(n32 result, u32 shift) -> n32 { bool carry = false; - uint32 overflow = 0; + n32 overflow = 0; for(auto _ : range(shift)) { carry = result & lsb(); - uint32 before = result; + n32 before = result; result = sign(result) >> 1; overflow |= before ^ result; } @@ -60,8 +60,8 @@ template auto M68K::ASR(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::CMP(uint32 source, uint32 target) -> uint32 { - auto result = (uint64)target - source; +template auto M68K::CMP(n32 source, n32 target) -> n32 { + auto result = (n64)target - source; r.c = sign(result >> 1) < 0; r.v = sign((target ^ source) & (target ^ result)) < 0; @@ -71,8 +71,8 @@ template auto M68K::CMP(uint32 source, uint32 target) -> uint32 { return clip(result); } -template auto M68K::EOR(uint32 source, uint32 target) -> uint32 { - uint32 result = target ^ source; +template auto M68K::EOR(n32 source, n32 target) -> n32 { + n32 result = target ^ source; r.c = 0; r.v = 0; @@ -82,7 +82,7 @@ template auto M68K::EOR(uint32 source, uint32 target) -> uint32 { return clip(result); } -template auto M68K::LSL(uint32 result, uint shift) -> uint32 { +template auto M68K::LSL(n32 result, u32 shift) -> n32 { bool carry = false; for(auto _ : range(shift)) { carry = result & msb(); @@ -98,7 +98,7 @@ template auto M68K::LSL(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::LSR(uint32 result, uint shift) -> uint32 { +template auto M68K::LSR(n32 result, u32 shift) -> n32 { bool carry = false; for(auto _ : range(shift)) { carry = result & lsb(); @@ -114,7 +114,7 @@ template auto M68K::LSR(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::OR(uint32 source, uint32 target) -> uint32 { +template auto M68K::OR(n32 source, n32 target) -> n32 { auto result = target | source; r.c = 0; @@ -125,7 +125,7 @@ template auto M68K::OR(uint32 source, uint32 target) -> uint32 { return clip(result); } -template auto M68K::ROL(uint32 result, uint shift) -> uint32 { +template auto M68K::ROL(n32 result, u32 shift) -> n32 { bool carry = false; for(auto _ : range(shift)) { carry = result & msb(); @@ -140,7 +140,7 @@ template auto M68K::ROL(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::ROR(uint32 result, uint shift) -> uint32 { +template auto M68K::ROR(n32 result, u32 shift) -> n32 { bool carry = false; for(auto _ : range(shift)) { carry = result & lsb(); @@ -156,7 +156,7 @@ template auto M68K::ROR(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::ROXL(uint32 result, uint shift) -> uint32 { +template auto M68K::ROXL(n32 result, u32 shift) -> n32 { bool carry = r.x; for(auto _ : range(shift)) { bool extend = carry; @@ -173,7 +173,7 @@ template auto M68K::ROXL(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::ROXR(uint32 result, uint shift) -> uint32 { +template auto M68K::ROXR(n32 result, u32 shift) -> n32 { bool carry = r.x; for(auto _ : range(shift)) { bool extend = carry; @@ -191,8 +191,8 @@ template auto M68K::ROXR(uint32 result, uint shift) -> uint32 { return clip(result); } -template auto M68K::SUB(uint32 source, uint32 target) -> uint32 { - auto result = (uint64)target - source; +template auto M68K::SUB(n32 source, n32 target) -> n32 { + auto result = (n64)target - source; if(extend) result -= r.x; r.c = sign(result >> 1) < 0; diff --git a/ares/component/processor/m68k/conditions.cpp b/ares/component/processor/m68k/conditions.cpp index b6649a4f84..44a58a26d7 100644 --- a/ares/component/processor/m68k/conditions.cpp +++ b/ares/component/processor/m68k/conditions.cpp @@ -1,4 +1,4 @@ -auto M68K::condition(uint4 condition) -> bool { +auto M68K::condition(n4 condition) -> bool { switch(condition) { case 0: return true; //T case 1: return false; //F diff --git a/ares/component/processor/m68k/disassembler.cpp b/ares/component/processor/m68k/disassembler.cpp index ee53e31ddf..91a8029346 100644 --- a/ares/component/processor/m68k/disassembler.cpp +++ b/ares/component/processor/m68k/disassembler.cpp @@ -1,4 +1,4 @@ -template<> auto M68K::_read(uint32 address) -> uint32 { +template<> auto M68K::_read(n32 address) -> n32 { if(address & 1) { return read(0, 1, address & ~1).byte(0); } else { @@ -6,32 +6,32 @@ template<> auto M68K::_read(uint32 address) -> uint32 { } } -template<> auto M68K::_read(uint32 address) -> uint32 { +template<> auto M68K::_read(n32 address) -> n32 { return read(1, 1, address & ~1); } -template<> auto M68K::_read(uint32 address) -> uint32 { - uint32 data = _read(address + 0) << 16; +template<> auto M68K::_read(n32 address) -> n32 { + n32 data = _read(address + 0) << 16; return data | _read(address + 2) << 0; } -template auto M68K::_readPC() -> uint32 { +template auto M68K::_readPC() -> n32 { auto data = _read(_pc); _pc += Size == Long ? 4 : 2; return clip(data); } -auto M68K::_readDisplacement(uint32 base) -> uint32 { - return base + (int16)_readPC(); +auto M68K::_readDisplacement(n32 base) -> n32 { + return base + (i16)_readPC(); } -auto M68K::_readIndex(uint32 base) -> uint32 { +auto M68K::_readIndex(n32 base) -> n32 { auto extension = _readPC(); auto index = extension & 0x8000 ? read(AddressRegister{extension >> 12}) : read(DataRegister{extension >> 12}); - if(!(extension & 0x800)) index = (int16)index; - return base + index + (int8)extension; + if(!(extension & 0x800)) index = (i16)index; + return base + index + (i8)extension; } auto M68K::_dataRegister(DataRegister dr) -> string { @@ -42,22 +42,22 @@ auto M68K::_addressRegister(AddressRegister ar) -> string { return {"a", ar.number}; } -template auto M68K::_immediate() -> string { +template auto M68K::_immediate() -> string { return {"#$", hex(_readPC(), 2 << Size)}; } -template auto M68K::_address(EffectiveAddress& ea) -> string { +template auto M68K::_address(EffectiveAddress& ea) -> string { if(ea.mode == 2) return {_addressRegister(AddressRegister{ea.reg})}; if(ea.mode == 5) return {"$", hex(_readDisplacement(read(AddressRegister{ea.reg})), 6L)}; if(ea.mode == 6) return {"$", hex(_readIndex(read(AddressRegister{ea.reg})), 6L)}; - if(ea.mode == 7) return {"$", hex((int16)_readPC(), 6L)}; + if(ea.mode == 7) return {"$", hex((i16)_readPC(), 6L)}; if(ea.mode == 8) return {"$", hex(_readPC(), 6L)}; - if(ea.mode == 9) return {"$", hex(_pc + (int16)_readPC(), 6L)}; + if(ea.mode == 9) return {"$", hex(_pc + (i16)_readPC(), 6L)}; if(ea.mode == 10) return {"$", hex(_readIndex(_pc), 6L)}; return "???"; //should never occur (modes 0, 1, 3, 4, 11 are not valid for LEA) } -template auto M68K::_effectiveAddress(EffectiveAddress& ea) -> string { +template auto M68K::_effectiveAddress(EffectiveAddress& ea) -> string { if(ea.mode == 0) return {_dataRegister(DataRegister{ea.reg})}; if(ea.mode == 1) return {_addressRegister(AddressRegister{ea.reg})}; if(ea.mode == 2) return {"(", _addressRegister(AddressRegister{ea.reg}), ")"}; @@ -65,7 +65,7 @@ template auto M68K::_effectiveAddress(EffectiveAddress& ea) -> string if(ea.mode == 4) return {"-(", _addressRegister(AddressRegister{ea.reg}), ")"}; if(ea.mode == 5) return {"($", hex(_readDisplacement(read(AddressRegister{ea.reg})), 6L), ")"}; if(ea.mode == 6) return {"($", hex(_readIndex(read(AddressRegister{ea.reg})), 6L), ")"}; - if(ea.mode == 7) return {"($", hex((int16)_readPC(), 6L), ")"}; + if(ea.mode == 7) return {"($", hex((i16)_readPC(), 6L), ")"}; if(ea.mode == 8) return {"($", hex(_readPC(), 6L), ")"}; if(ea.mode == 9) return {"($", hex(_readDisplacement(_pc), 6L), ")"}; if(ea.mode == 10) return {"($", hex(_readIndex(_pc), 6L), ")"}; @@ -73,18 +73,18 @@ template auto M68K::_effectiveAddress(EffectiveAddress& ea) -> string return "???"; //should never occur } -auto M68K::_branch(uint8 displacement) -> string { - uint16 extension = _readPC(); +auto M68K::_branch(n8 displacement) -> string { + n16 extension = _readPC(); _pc -= 2; - int32 offset = displacement ? sign(displacement) : sign(extension); + i32 offset = displacement ? sign(displacement) : sign(extension); return {"$", hex(_pc + offset, 6L)}; } -template auto M68K::_suffix() -> string { +template auto M68K::_suffix() -> string { return Size == Byte ? ".b" : Size == Word ? ".w" : ".l"; } -auto M68K::_condition(uint4 condition) -> string { +auto M68K::_condition(n4 condition) -> string { static const string conditions[16] = { "t ", "f ", "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi", "ge", "lt", "gt", "le", @@ -92,7 +92,7 @@ auto M68K::_condition(uint4 condition) -> string { return conditions[condition]; } -auto M68K::disassembleInstruction(uint32 pc) -> string { +auto M68K::disassembleInstruction(n32 pc) -> string { _pc = pc; return pad(disassembleTable[_readPC()](), -60); //todo: exact maximum length unknown (and sub-optimal) } @@ -118,7 +118,7 @@ auto M68K::disassembleContext() -> string { "sp:", hex(r.sp, 8L), " ", r.t ? "T" : "t", r.s ? "S" : "s", - (uint)r.i, + (u32)r.i, r.c ? "C" : "c", r.v ? "V" : "v", r.z ? "Z" : "z", @@ -133,43 +133,43 @@ auto M68K::disassembleABCD(EffectiveAddress from, EffectiveAddress with) -> stri return {"abcd ", _effectiveAddress(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleADD(EffectiveAddress from, DataRegister with) -> string { +template auto M68K::disassembleADD(EffectiveAddress from, DataRegister with) -> string { return {"add", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleADD(DataRegister from, EffectiveAddress with) -> string { +template auto M68K::disassembleADD(DataRegister from, EffectiveAddress with) -> string { return {"add", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleADDA(EffectiveAddress from, AddressRegister with) -> string { +template auto M68K::disassembleADDA(EffectiveAddress from, AddressRegister with) -> string { return {"adda", _suffix(), " ", _effectiveAddress(from), ",", _addressRegister(with)}; } -template auto M68K::disassembleADDI(EffectiveAddress with) -> string { +template auto M68K::disassembleADDI(EffectiveAddress with) -> string { return {"addi", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleADDQ(uint4 immediate, EffectiveAddress with) -> string { +template auto M68K::disassembleADDQ(n4 immediate, EffectiveAddress with) -> string { return {"addq", _suffix(), " #", immediate, ",", _effectiveAddress(with)}; } -template auto M68K::disassembleADDQ(uint4 immediate, AddressRegister with) -> string { +template auto M68K::disassembleADDQ(n4 immediate, AddressRegister with) -> string { return {"addq", _suffix(), " #", immediate, ",", _addressRegister(with)}; } -template auto M68K::disassembleADDX(EffectiveAddress from, EffectiveAddress with) -> string { +template auto M68K::disassembleADDX(EffectiveAddress from, EffectiveAddress with) -> string { return {"addx", _suffix(), " ", _effectiveAddress(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleAND(EffectiveAddress from, DataRegister with) -> string { +template auto M68K::disassembleAND(EffectiveAddress from, DataRegister with) -> string { return {"and", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleAND(DataRegister from, EffectiveAddress with) -> string { +template auto M68K::disassembleAND(DataRegister from, EffectiveAddress with) -> string { return {"and", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleANDI(EffectiveAddress ea) -> string { +template auto M68K::disassembleANDI(EffectiveAddress ea) -> string { return {"andi", _suffix(), " ", _immediate(), ",", _effectiveAddress(ea)}; } @@ -181,11 +181,11 @@ auto M68K::disassembleANDI_TO_SR() -> string { return {"andi ", _immediate(), ",sr"}; } -template auto M68K::disassembleASL(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleASL(n4 count, DataRegister with) -> string { return {"asl", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleASL(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleASL(DataRegister from, DataRegister with) -> string { return {"asl", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -193,11 +193,11 @@ auto M68K::disassembleASL(EffectiveAddress with) -> string { return {"asl", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleASR(uint4 count, DataRegister modify) -> string { +template auto M68K::disassembleASR(n4 count, DataRegister modify) -> string { return {"asr", _suffix(), " #", count, ",", _dataRegister(modify)}; } -template auto M68K::disassembleASR(DataRegister from, DataRegister modify) -> string { +template auto M68K::disassembleASR(DataRegister from, DataRegister modify) -> string { return {"asr", _suffix(), " ", _dataRegister(from), ",", _dataRegister(modify)}; } @@ -205,48 +205,48 @@ auto M68K::disassembleASR(EffectiveAddress with) -> string { return {"asr", _suffix(), " ", _effectiveAddress(with)}; } -auto M68K::disassembleBCC(uint4 test, uint8 displacement) -> string { +auto M68K::disassembleBCC(n4 test, n8 displacement) -> string { auto cc = _condition(test); return {"b", cc, " ", _branch(displacement)}; } -template auto M68K::disassembleBCHG(DataRegister bit, EffectiveAddress with) -> string { +template auto M68K::disassembleBCHG(DataRegister bit, EffectiveAddress with) -> string { return {"bchg", _suffix(), " ", _dataRegister(bit), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleBCHG(EffectiveAddress with) -> string { +template auto M68K::disassembleBCHG(EffectiveAddress with) -> string { return {"bchg", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleBCLR(DataRegister bit, EffectiveAddress with) -> string { +template auto M68K::disassembleBCLR(DataRegister bit, EffectiveAddress with) -> string { return {"bclr", _suffix(), " ", _dataRegister(bit), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleBCLR(EffectiveAddress with) -> string { +template auto M68K::disassembleBCLR(EffectiveAddress with) -> string { return {"bclr", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -auto M68K::disassembleBRA(uint8 displacement) -> string { +auto M68K::disassembleBRA(n8 displacement) -> string { return {"bra ", _branch(displacement)}; } -template auto M68K::disassembleBSET(DataRegister bit, EffectiveAddress with) -> string { +template auto M68K::disassembleBSET(DataRegister bit, EffectiveAddress with) -> string { return {"bset", _suffix(), " ", _dataRegister(bit), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleBSET(EffectiveAddress with) -> string { +template auto M68K::disassembleBSET(EffectiveAddress with) -> string { return {"bset", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -auto M68K::disassembleBSR(uint8 displacement) -> string { +auto M68K::disassembleBSR(n8 displacement) -> string { return {"bsr ", _branch(displacement)}; } -template auto M68K::disassembleBTST(DataRegister bit, EffectiveAddress with) -> string { +template auto M68K::disassembleBTST(DataRegister bit, EffectiveAddress with) -> string { return {"btst", _suffix(), " ", _dataRegister(bit), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleBTST(EffectiveAddress with) -> string { +template auto M68K::disassembleBTST(EffectiveAddress with) -> string { return {"btst", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } @@ -254,29 +254,29 @@ auto M68K::disassembleCHK(DataRegister compare, EffectiveAddress maximum) -> str return {"chk", _suffix(), " ", _effectiveAddress(maximum), ",", _dataRegister(compare)}; } -template auto M68K::disassembleCLR(EffectiveAddress ea) -> string { +template auto M68K::disassembleCLR(EffectiveAddress ea) -> string { return {"clr", _suffix(), " ", _effectiveAddress(ea)}; } -template auto M68K::disassembleCMP(EffectiveAddress from, DataRegister with) -> string { +template auto M68K::disassembleCMP(EffectiveAddress from, DataRegister with) -> string { return {"cmp", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleCMPA(EffectiveAddress from, AddressRegister with) -> string { +template auto M68K::disassembleCMPA(EffectiveAddress from, AddressRegister with) -> string { return {"cmpa", _suffix(), " ", _effectiveAddress(from), ",", _addressRegister(with)}; } -template auto M68K::disassembleCMPI(EffectiveAddress with) -> string { +template auto M68K::disassembleCMPI(EffectiveAddress with) -> string { return {"cmpi", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleCMPM(EffectiveAddress from, EffectiveAddress with) -> string { +template auto M68K::disassembleCMPM(EffectiveAddress from, EffectiveAddress with) -> string { return {"cmpm", _suffix(), " ", _effectiveAddress(from), ",", _effectiveAddress(with)}; } -auto M68K::disassembleDBCC(uint4 condition, DataRegister with) -> string { +auto M68K::disassembleDBCC(n4 condition, DataRegister with) -> string { auto base = _pc; - auto displacement = (int16)_readPC(); + auto displacement = (i16)_readPC(); return {"db", _condition(condition), " ", _dataRegister(with), ",$", hex(base + displacement, 6L)}; } @@ -288,11 +288,11 @@ auto M68K::disassembleDIVU(EffectiveAddress from, DataRegister with) -> string { return {"divu", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleEOR(DataRegister from, EffectiveAddress with) -> string { +template auto M68K::disassembleEOR(DataRegister from, EffectiveAddress with) -> string { return {"eor", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleEORI(EffectiveAddress with) -> string { +template auto M68K::disassembleEORI(EffectiveAddress with) -> string { return {"eori", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } @@ -316,11 +316,11 @@ auto M68K::disassembleEXG(DataRegister x, AddressRegister y) -> string { return {"exg ", _dataRegister(x), ",", _addressRegister(y)}; } -template auto M68K::disassembleEXT(DataRegister with) -> string { +template auto M68K::disassembleEXT(DataRegister with) -> string { return {"ext", _suffix(), " ", _dataRegister(with)}; } -auto M68K::disassembleILLEGAL(uint16 code) -> string { +auto M68K::disassembleILLEGAL(n16 code) -> string { if(code.bit(12,15) == 0xa) return {"linea $", hex(code.bit(0,11), 3L)}; if(code.bit(12,15) == 0xf) return {"linef $", hex(code.bit(0,11), 3L)}; return {"illegal "}; @@ -342,11 +342,11 @@ auto M68K::disassembleLINK(AddressRegister with) -> string { return {"link ", _addressRegister(with), ",", _immediate()}; } -template auto M68K::disassembleLSL(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleLSL(n4 count, DataRegister with) -> string { return {"lsl", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleLSL(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleLSL(DataRegister from, DataRegister with) -> string { return {"lsl", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -354,11 +354,11 @@ auto M68K::disassembleLSL(EffectiveAddress with) -> string { return {"lsl", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleLSR(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleLSR(n4 count, DataRegister with) -> string { return {"lsr", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleLSR(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleLSR(DataRegister from, DataRegister with) -> string { return {"lsr", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -366,51 +366,51 @@ auto M68K::disassembleLSR(EffectiveAddress with) -> string { return {"lsr", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleMOVE(EffectiveAddress from, EffectiveAddress to) -> string { +template auto M68K::disassembleMOVE(EffectiveAddress from, EffectiveAddress to) -> string { return {"move", _suffix(), " ", _effectiveAddress(from), ",", _effectiveAddress(to)}; } -template auto M68K::disassembleMOVEA(EffectiveAddress from, AddressRegister to) -> string { +template auto M68K::disassembleMOVEA(EffectiveAddress from, AddressRegister to) -> string { return {"movea ", _effectiveAddress(from), ",", _addressRegister(to)}; } -template auto M68K::disassembleMOVEM_TO_MEM(EffectiveAddress to) -> string { +template auto M68K::disassembleMOVEM_TO_MEM(EffectiveAddress to) -> string { string op{"movem", _suffix(), " "}; - uint16 list = _readPC(); + n16 list = _readPC(); string regs; - for(uint n : range(8)) if(list.bit(0 + n)) regs.append(_dataRegister(DataRegister{n}), ","); + for(u32 n : range(8)) if(list.bit(0 + n)) regs.append(_dataRegister(DataRegister{n}), ","); regs.trimRight(","); if(regs && list >> 8) regs.append("/"); - for(uint n : range(8)) if(list.bit(8 + n)) regs.append(_addressRegister(AddressRegister{n}), ","); + for(u32 n : range(8)) if(list.bit(8 + n)) regs.append(_addressRegister(AddressRegister{n}), ","); regs.trimRight(","); return {op, regs, ",", _effectiveAddress(to)}; } -template auto M68K::disassembleMOVEM_TO_REG(EffectiveAddress from) -> string { +template auto M68K::disassembleMOVEM_TO_REG(EffectiveAddress from) -> string { string op{"movem", _suffix(), " "}; - uint16 list = _readPC(); + n16 list = _readPC(); string regs; - for(uint n : range(8)) if(list.bit(0 + n)) regs.append(_dataRegister(DataRegister{n}), ","); + for(u32 n : range(8)) if(list.bit(0 + n)) regs.append(_dataRegister(DataRegister{n}), ","); regs.trimRight(","); if(regs && list >> 8) regs.append("/"); - for(uint n : range(8)) if(list.bit(8 + n)) regs.append(_addressRegister(AddressRegister{n}), ","); + for(u32 n : range(8)) if(list.bit(8 + n)) regs.append(_addressRegister(AddressRegister{n}), ","); regs.trimRight(","); return {op, _effectiveAddress(from), ",", regs}; } -template auto M68K::disassembleMOVEP(DataRegister from, EffectiveAddress to) -> string { +template auto M68K::disassembleMOVEP(DataRegister from, EffectiveAddress to) -> string { return {"movep", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(to)}; } -template auto M68K::disassembleMOVEP(EffectiveAddress from, DataRegister to) -> string { +template auto M68K::disassembleMOVEP(EffectiveAddress from, DataRegister to) -> string { return {"movep", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(to)}; } -auto M68K::disassembleMOVEQ(uint8 immediate, DataRegister to) -> string { +auto M68K::disassembleMOVEQ(n8 immediate, DataRegister to) -> string { return {"moveq #$", hex(immediate, 2L), ",", _dataRegister(to)}; } @@ -446,11 +446,11 @@ auto M68K::disassembleNBCD(EffectiveAddress with) -> string { return {"nbcd ", _effectiveAddress(with)}; } -template auto M68K::disassembleNEG(EffectiveAddress with) -> string { +template auto M68K::disassembleNEG(EffectiveAddress with) -> string { return {"neg", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleNEGX(EffectiveAddress with) -> string { +template auto M68K::disassembleNEGX(EffectiveAddress with) -> string { return {"negx", _suffix(), " ", _effectiveAddress(with)}; } @@ -458,19 +458,19 @@ auto M68K::disassembleNOP() -> string { return {"nop "}; } -template auto M68K::disassembleNOT(EffectiveAddress with) -> string { +template auto M68K::disassembleNOT(EffectiveAddress with) -> string { return {"not", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleOR(EffectiveAddress from, DataRegister with) -> string { +template auto M68K::disassembleOR(EffectiveAddress from, DataRegister with) -> string { return {"or", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleOR(DataRegister from, EffectiveAddress with) -> string { +template auto M68K::disassembleOR(DataRegister from, EffectiveAddress with) -> string { return {"or", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleORI(EffectiveAddress with) -> string { +template auto M68K::disassembleORI(EffectiveAddress with) -> string { return {"ori", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } @@ -490,11 +490,11 @@ auto M68K::disassembleRESET() -> string { return {"reset "}; } -template auto M68K::disassembleROL(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleROL(n4 count, DataRegister with) -> string { return {"rol", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleROL(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleROL(DataRegister from, DataRegister with) -> string { return {"rol", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -502,11 +502,11 @@ auto M68K::disassembleROL(EffectiveAddress with) -> string { return {"rol", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleROR(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleROR(n4 count, DataRegister with) -> string { return {"ror", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleROR(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleROR(DataRegister from, DataRegister with) -> string { return {"ror", _suffix(), " ", _dataRegister(from) ,",", _dataRegister(with)}; } @@ -514,11 +514,11 @@ auto M68K::disassembleROR(EffectiveAddress with) -> string { return {"ror", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleROXL(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleROXL(n4 count, DataRegister with) -> string { return {"roxl", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleROXL(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleROXL(DataRegister from, DataRegister with) -> string { return {"roxl", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -526,11 +526,11 @@ auto M68K::disassembleROXL(EffectiveAddress with) -> string { return {"roxl", _suffix(), " ", _effectiveAddress(with)}; } -template auto M68K::disassembleROXR(uint4 count, DataRegister with) -> string { +template auto M68K::disassembleROXR(n4 count, DataRegister with) -> string { return {"roxr", _suffix(), " #", count, ",", _dataRegister(with)}; } -template auto M68K::disassembleROXR(DataRegister from, DataRegister with) -> string { +template auto M68K::disassembleROXR(DataRegister from, DataRegister with) -> string { return {"roxr", _suffix(), " ", _dataRegister(from), ",", _dataRegister(with)}; } @@ -554,7 +554,7 @@ auto M68K::disassembleSBCD(EffectiveAddress from, EffectiveAddress with) -> stri return {"sbcd ", _effectiveAddress(from), ",", _effectiveAddress(with)}; } -auto M68K::disassembleSCC(uint4 test, EffectiveAddress to) -> string { +auto M68K::disassembleSCC(n4 test, EffectiveAddress to) -> string { return {"s", _condition(test), " ", _effectiveAddress(to)}; } @@ -562,31 +562,31 @@ auto M68K::disassembleSTOP() -> string { return {"stop ", _immediate()}; } -template auto M68K::disassembleSUB(EffectiveAddress from, DataRegister with) -> string { +template auto M68K::disassembleSUB(EffectiveAddress from, DataRegister with) -> string { return {"sub", _suffix(), " ", _effectiveAddress(from), ",", _dataRegister(with)}; } -template auto M68K::disassembleSUB(DataRegister from, EffectiveAddress with) -> string { +template auto M68K::disassembleSUB(DataRegister from, EffectiveAddress with) -> string { return {"sub", _suffix(), " ", _dataRegister(from), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleSUBA(EffectiveAddress from, AddressRegister with) -> string { +template auto M68K::disassembleSUBA(EffectiveAddress from, AddressRegister with) -> string { return {"suba", _suffix(), " ", _effectiveAddress(from), ",", _addressRegister(with)}; } -template auto M68K::disassembleSUBI(EffectiveAddress with) -> string { +template auto M68K::disassembleSUBI(EffectiveAddress with) -> string { return {"subi", _suffix(), " ", _immediate(), ",", _effectiveAddress(with)}; } -template auto M68K::disassembleSUBQ(uint4 immediate, EffectiveAddress with) -> string { +template auto M68K::disassembleSUBQ(n4 immediate, EffectiveAddress with) -> string { return {"subq", _suffix(), " #", immediate, ",", _effectiveAddress(with)}; } -template auto M68K::disassembleSUBQ(uint4 immediate, AddressRegister with) -> string { +template auto M68K::disassembleSUBQ(n4 immediate, AddressRegister with) -> string { return {"subq", _suffix(), " #", immediate, ",", _addressRegister(with)}; } -template auto M68K::disassembleSUBX(EffectiveAddress from, EffectiveAddress with) -> string { +template auto M68K::disassembleSUBX(EffectiveAddress from, EffectiveAddress with) -> string { return {"subx", _suffix(), " ", _effectiveAddress(from), ",", _effectiveAddress(with)}; } @@ -598,7 +598,7 @@ auto M68K::disassembleTAS(EffectiveAddress with) -> string { return {"tas ", _effectiveAddress(with)}; } -auto M68K::disassembleTRAP(uint4 vector) -> string { +auto M68K::disassembleTRAP(n4 vector) -> string { return {"trap #", vector}; } @@ -606,7 +606,7 @@ auto M68K::disassembleTRAPV() -> string { return {"trapv "}; } -template auto M68K::disassembleTST(EffectiveAddress from) -> string { +template auto M68K::disassembleTST(EffectiveAddress from) -> string { return {"tst", _suffix(), " ", _effectiveAddress(from)}; } diff --git a/ares/component/processor/m68k/effective-address.cpp b/ares/component/processor/m68k/effective-address.cpp index 7b75afcde2..02256510fd 100644 --- a/ares/component/processor/m68k/effective-address.cpp +++ b/ares/component/processor/m68k/effective-address.cpp @@ -1,5 +1,5 @@ //used by JMP and JSR: as PC is guaranteed to change, avoid performing any unnecessary prefetches -auto M68K::prefetched(EffectiveAddress& ea) -> uint32 { +auto M68K::prefetched(EffectiveAddress& ea) -> n32 { if(ea.valid) return ea.address; ea.valid = true; @@ -11,20 +11,20 @@ auto M68K::prefetched(EffectiveAddress& ea) -> uint32 { case AddressRegisterIndirectWithDisplacement: { idle(2); - return ea.address = r.a[ea.reg] + (int16)prefetched(); + return ea.address = r.a[ea.reg] + (i16)prefetched(); } case AddressRegisterIndirectWithIndex: { idle(6); auto extension = prefetched(); auto index = extension & 0x8000 ? r.a[extension >> 12 & 7] : r.d[extension >> 12 & 7]; - if(!(extension & 0x800)) index = (int16)index; - return ea.address = r.a[ea.reg] + index + (int8)extension; + if(!(extension & 0x800)) index = (i16)index; + return ea.address = r.a[ea.reg] + index + (i8)extension; } case AbsoluteShortIndirect: { idle(2); - return ea.address = (int16)prefetched(); + return ea.address = (i16)prefetched(); } case AbsoluteLongIndirect: { @@ -36,7 +36,7 @@ auto M68K::prefetched(EffectiveAddress& ea) -> uint32 { case ProgramCounterIndirectWithDisplacement: { idle(2); auto base = r.pc - 2; - return ea.address = base + (int16)prefetched(); + return ea.address = base + (i16)prefetched(); } case ProgramCounterIndirectWithIndex: { @@ -44,8 +44,8 @@ auto M68K::prefetched(EffectiveAddress& ea) -> uint32 { auto base = r.pc - 2; auto extension = prefetched(); auto index = extension & 0x8000 ? r.a[extension >> 12 & 7] : r.d[extension >> 12 & 7]; - if(!(extension & 0x800)) index = (int16)index; - return ea.address = base + index + (int8)extension; + if(!(extension & 0x800)) index = (i16)index; + return ea.address = base + index + (i8)extension; } } @@ -53,7 +53,7 @@ auto M68K::prefetched(EffectiveAddress& ea) -> uint32 { return ea.address = 0; //should never occur } -template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { +template auto M68K::fetch(EffectiveAddress& ea) -> n32 { if(ea.valid) return ea.address; ea.valid = true; @@ -80,7 +80,7 @@ template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { } case AddressRegisterIndirectWithDisplacement: { - return ea.address = read(AddressRegister{ea.reg}) + (int16)extension(); + return ea.address = read(AddressRegister{ea.reg}) + (i16)extension(); } case AddressRegisterIndirectWithIndex: { @@ -89,12 +89,12 @@ template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { auto index = data & 0x8000 ? read(AddressRegister{data >> 12}) : read(DataRegister{data >> 12}); - if(!(data & 0x800)) index = (int16)index; - return ea.address = read(AddressRegister{ea.reg}) + index + (int8)data; + if(!(data & 0x800)) index = (i16)index; + return ea.address = read(AddressRegister{ea.reg}) + index + (i8)data; } case AbsoluteShortIndirect: { - return ea.address = (int16)extension(); + return ea.address = (i16)extension(); } case AbsoluteLongIndirect: { @@ -103,7 +103,7 @@ template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { case ProgramCounterIndirectWithDisplacement: { auto base = r.pc - 2; - return ea.address = base + (int16)extension(); + return ea.address = base + (i16)extension(); } case ProgramCounterIndirectWithIndex: { @@ -113,8 +113,8 @@ template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { auto index = data & 0x8000 ? read(AddressRegister{data >> 12}) : read(DataRegister{data >> 12}); - if(!(data & 0x800)) index = (int16)index; - return ea.address = base + index + (int8)data; + if(!(data & 0x800)) index = (i16)index; + return ea.address = base + index + (i8)data; } case Immediate: { @@ -126,7 +126,7 @@ template auto M68K::fetch(EffectiveAddress& ea) -> uint32 { return ea.address = 0; //should never occur } -template auto M68K::read(EffectiveAddress& ea) -> uint32 { +template auto M68K::read(EffectiveAddress& ea) -> n32 { fetch(ea); switch(ea.mode) { @@ -191,7 +191,7 @@ template auto M68K::read(EffectiveAddress& ea) return 0; } -template auto M68K::write(EffectiveAddress& ea, uint32 data) -> void { +template auto M68K::write(EffectiveAddress& ea, n32 data) -> void { fetch(ea); switch(ea.mode) { diff --git a/ares/component/processor/m68k/instruction.cpp b/ares/component/processor/m68k/instruction.cpp index 1487b9d3b3..63f81882ad 100644 --- a/ares/component/processor/m68k/instruction.cpp +++ b/ares/component/processor/m68k/instruction.cpp @@ -16,11 +16,11 @@ M68K::M68K() { } #define pattern(s) \ - std::integral_constant::value + std::integral_constant::value //ABCD - for(uint3 treg : range(8)) - for(uint3 sreg : range(8)) { + for(n3 treg : range(8)) + for(n3 sreg : range(8)) { auto opcode = pattern("1100 ---1 0000 ----") | treg << 9 | sreg << 0; EffectiveAddress dataWith{DataRegisterDirect, treg}; @@ -33,9 +33,9 @@ M68K::M68K() { } //ADD - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1101 ---0 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -49,9 +49,9 @@ M68K::M68K() { } //ADD - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1101 ---1 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -63,9 +63,9 @@ M68K::M68K() { } //ADDA - for(uint3 areg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 areg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1101 ---+ 11-- ----") | areg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -76,8 +76,8 @@ M68K::M68K() { } //ADDI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 0110 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -88,13 +88,13 @@ M68K::M68K() { } //ADDQ - for(uint3 data : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 data : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0101 ---0 ++-- ----") | data << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 2) continue; - uint4 immediate = data ? (uint4)data : (uint4)8; + n4 immediate = data ? (n4)data : (n4)8; if(mode != 1) { EffectiveAddress with{mode, reg}; bind(opcode | 0 << 6, ADDQ, immediate, with); @@ -108,8 +108,8 @@ M68K::M68K() { } //ADDX - for(uint3 xreg : range(8)) - for(uint3 yreg : range(8)) { + for(n3 xreg : range(8)) + for(n3 yreg : range(8)) { auto opcode = pattern("1101 ---1 ++00 ----") | xreg << 9 | yreg << 0; EffectiveAddress dataWith{DataRegisterDirect, xreg}; @@ -126,9 +126,9 @@ M68K::M68K() { } //AND - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1100 ---0 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -140,9 +140,9 @@ M68K::M68K() { } //AND - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1100 ---1 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -154,8 +154,8 @@ M68K::M68K() { } //ANDI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 0010 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -178,11 +178,11 @@ M68K::M68K() { } //ASL (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++00 0---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ASL, count, with); bind(opcode | 1 << 6, ASL, count, with); @@ -190,8 +190,8 @@ M68K::M68K() { } //ASL (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++10 0---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -202,8 +202,8 @@ M68K::M68K() { } //ASL (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0001 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -212,11 +212,11 @@ M68K::M68K() { } //ASR (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++00 0---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ASR, count, with); bind(opcode | 1 << 6, ASR, count, with); @@ -224,8 +224,8 @@ M68K::M68K() { } //ASR (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++10 0---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -236,8 +236,8 @@ M68K::M68K() { } //ASR (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0000 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -246,8 +246,8 @@ M68K::M68K() { } //BCC - for(uint4 test : range( 16)) - for(uint8 displacement : range(256)) { + for(n4 test : range( 16)) + for(n8 displacement : range(256)) { if(test <= 1) continue; auto opcode = pattern("0110 ---- ---- ----") | test << 8 | displacement << 0; @@ -256,9 +256,9 @@ M68K::M68K() { } //BCHG (register) - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 ---1 01-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -269,8 +269,8 @@ M68K::M68K() { } //BCHG (immediate) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1000 01-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -280,9 +280,9 @@ M68K::M68K() { } //BCLR (register) - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 ---1 10-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -293,8 +293,8 @@ M68K::M68K() { } //BCLR (immediate) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1000 10-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -304,16 +304,16 @@ M68K::M68K() { } //BRA - for(uint8 displacement : range(256)) { + for(n8 displacement : range(256)) { auto opcode = pattern("0110 0000 ---- ----") | displacement << 0; bind(opcode, BRA, displacement); } //BSET (register) - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 ---1 11-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -324,8 +324,8 @@ M68K::M68K() { } //BSET (immediate) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1000 11-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -335,16 +335,16 @@ M68K::M68K() { } //BSR - for(uint8 displacement : range(256)) { + for(n8 displacement : range(256)) { auto opcode = pattern("0110 0001 ---- ----") | displacement << 0; bind(opcode, BSR, displacement); } //BTST (register) - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 ---1 00-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -355,8 +355,8 @@ M68K::M68K() { } //BTST (immediate) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1000 00-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 4)) continue; @@ -366,9 +366,9 @@ M68K::M68K() { } //CHK - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 ---1 10-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -378,8 +378,8 @@ M68K::M68K() { } //CLR - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0010 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -390,9 +390,9 @@ M68K::M68K() { } //CMP - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1011 ---0 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -406,9 +406,9 @@ M68K::M68K() { } //CMPA - for(uint3 areg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 areg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1011 ---+ 11-- ----") | areg << 9 | mode << 3 | reg << 0; AddressRegister with{areg}; @@ -418,8 +418,8 @@ M68K::M68K() { } //CMPI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1100 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -430,8 +430,8 @@ M68K::M68K() { } //CMPM - for(uint3 xreg : range(8)) - for(uint3 yreg : range(8)) { + for(n3 xreg : range(8)) + for(n3 yreg : range(8)) { auto opcode = pattern("1011 ---1 ++00 1---") | xreg << 9 | yreg << 0; EffectiveAddress with{AddressRegisterIndirectWithPostIncrement, xreg}; @@ -442,8 +442,8 @@ M68K::M68K() { } //DBCC - for(uint4 condition : range(16)) - for(uint3 dreg : range( 8)) { + for(n4 condition : range(16)) + for(n3 dreg : range( 8)) { auto opcode = pattern("0101 ---- 1100 1---") | condition << 8 | dreg << 0; DataRegister with{dreg}; @@ -451,9 +451,9 @@ M68K::M68K() { } //DIVS - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1000 ---1 11-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -463,9 +463,9 @@ M68K::M68K() { } //DIVU - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1000 ---0 11-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -475,9 +475,9 @@ M68K::M68K() { } //EOR - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1011 ---1 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -489,8 +489,8 @@ M68K::M68K() { } //EORI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 1010 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -513,8 +513,8 @@ M68K::M68K() { } //EXG - for(uint3 xreg : range(8)) - for(uint3 yreg : range(8)) { + for(n3 xreg : range(8)) + for(n3 yreg : range(8)) { auto opcode = pattern("1100 ---1 0100 0---") | xreg << 9 | yreg << 0; DataRegister x{xreg}; @@ -523,8 +523,8 @@ M68K::M68K() { } //EXG - for(uint3 xreg : range(8)) - for(uint3 yreg : range(8)) { + for(n3 xreg : range(8)) + for(n3 yreg : range(8)) { auto opcode = pattern("1100 ---1 0100 1---") | xreg << 9 | yreg << 0; AddressRegister x{xreg}; @@ -533,8 +533,8 @@ M68K::M68K() { } //EXG - for(uint3 xreg : range(8)) - for(uint3 yreg : range(8)) { + for(n3 xreg : range(8)) + for(n3 yreg : range(8)) { auto opcode = pattern("1100 ---1 1000 1---") | xreg << 9 | yreg << 0; DataRegister x{xreg}; @@ -543,7 +543,7 @@ M68K::M68K() { } //EXT - for(uint3 dreg : range(8)) { + for(n3 dreg : range(8)) { auto opcode = pattern("0100 1000 1+00 0---") | dreg << 0; DataRegister with{dreg}; @@ -558,8 +558,8 @@ M68K::M68K() { } //JMP - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1110 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || mode == 3 || mode == 4 || (mode == 7 && reg >= 4)) continue; @@ -568,8 +568,8 @@ M68K::M68K() { } //JSR - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1110 10-- ----") | mode << 3 | reg << 0; if(mode <= 1 || mode == 3 || mode == 4 || (mode == 7 && reg >= 4)) continue; @@ -578,9 +578,9 @@ M68K::M68K() { } //LEA - for(uint3 areg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 areg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 ---1 11-- ----") | areg << 9 | mode << 3 | reg << 0; if(mode <= 1 || mode == 3 || mode == 4 || (mode == 7 && reg >= 4)) continue; @@ -590,7 +590,7 @@ M68K::M68K() { } //LINK - for(uint3 areg : range(8)) { + for(n3 areg : range(8)) { auto opcode = pattern("0100 1110 0101 0---") | areg << 0; AddressRegister with{areg}; @@ -598,11 +598,11 @@ M68K::M68K() { } //LSL (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++00 1---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, LSL, count, with); bind(opcode | 1 << 6, LSL, count, with); @@ -610,8 +610,8 @@ M68K::M68K() { } //LSL (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++10 1---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -622,8 +622,8 @@ M68K::M68K() { } //LSL (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0011 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -632,11 +632,11 @@ M68K::M68K() { } //LSR (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++00 1---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, LSR, count, with); bind(opcode | 1 << 6, LSR, count, with); @@ -644,8 +644,8 @@ M68K::M68K() { } //LSR (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++10 1---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -656,8 +656,8 @@ M68K::M68K() { } //LSR (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0010 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -666,10 +666,10 @@ M68K::M68K() { } //MOVE - for(uint3 toReg : range(8)) - for(uint3 toMode : range(8)) - for(uint3 fromMode : range(8)) - for(uint3 fromReg : range(8)) { + for(n3 toReg : range(8)) + for(n3 toMode : range(8)) + for(n3 fromMode : range(8)) + for(n3 fromReg : range(8)) { auto opcode = pattern("00++ ---- ---- ----") | toReg << 9 | toMode << 6 | fromMode << 3 | fromReg << 0; if(toMode == 1 || (toMode == 7 && toReg >= 2)) continue; if(fromMode == 7 && fromReg >= 5) continue; @@ -684,9 +684,9 @@ M68K::M68K() { } //MOVEA - for(uint3 areg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 areg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("00++ ---0 01-- ----") | areg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -697,8 +697,8 @@ M68K::M68K() { } //MOVEM - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1000 1+-- ----") | mode << 3 | reg << 0; if(mode <= 1 || mode == 3 || (mode == 7 && reg >= 2)) continue; @@ -708,8 +708,8 @@ M68K::M68K() { } //MOVEM - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1100 1+-- ----") | mode << 3 | reg << 0; if(mode <= 1 || mode == 4 || (mode == 7 && reg >= 4)) continue; @@ -719,8 +719,8 @@ M68K::M68K() { } //MOVEP - for(uint3 dreg : range(8)) - for(uint3 areg : range(8)) { + for(n3 dreg : range(8)) + for(n3 areg : range(8)) { auto opcode = pattern("0000 ---1 1+00 1---") | dreg << 9 | areg << 0; DataRegister from{dreg}; @@ -730,8 +730,8 @@ M68K::M68K() { } //MOVEP - for(uint3 dreg : range(8)) - for(uint3 areg : range(8)) { + for(n3 dreg : range(8)) + for(n3 areg : range(8)) { auto opcode = pattern("0000 ---1 0+00 1---") | dreg << 9 | areg << 0; DataRegister to{dreg}; @@ -741,8 +741,8 @@ M68K::M68K() { } //MOVEQ - for(uint3 dreg : range( 8)) - for(uint8 immediate : range(256)) { + for(n3 dreg : range( 8)) + for(n8 immediate : range(256)) { auto opcode = pattern("0111 ---0 ---- ----") | dreg << 9 | immediate << 0; DataRegister to{dreg}; @@ -750,8 +750,8 @@ M68K::M68K() { } //MOVE_FROM_SR - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0000 11-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -760,8 +760,8 @@ M68K::M68K() { } //MOVE_TO_CCR - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0100 11-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -770,8 +770,8 @@ M68K::M68K() { } //MOVE_TO_SR - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0110 11-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -780,7 +780,7 @@ M68K::M68K() { } //MOVE_FROM_USP - for(uint3 areg : range(8)) { + for(n3 areg : range(8)) { auto opcode = pattern("0100 1110 0110 1---") | areg << 0; AddressRegister to{areg}; @@ -788,7 +788,7 @@ M68K::M68K() { } //MOVE_TO_USP - for(uint3 areg : range(8)) { + for(n3 areg : range(8)) { auto opcode = pattern("0100 1110 0110 0---") | areg << 0; AddressRegister from{areg}; @@ -796,9 +796,9 @@ M68K::M68K() { } //MULS - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1100 ---1 11-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -808,9 +808,9 @@ M68K::M68K() { } //MULU - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1100 ---0 11-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -820,8 +820,8 @@ M68K::M68K() { } //NBCD - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1000 00-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -830,8 +830,8 @@ M68K::M68K() { } //NEG - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0100 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -842,8 +842,8 @@ M68K::M68K() { } //NEGX - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0000 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -860,8 +860,8 @@ M68K::M68K() { } //NOT - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 0110 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -872,9 +872,9 @@ M68K::M68K() { } //OR - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1000 ---0 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 5)) continue; @@ -886,9 +886,9 @@ M68K::M68K() { } //OR - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1000 ---1 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -900,8 +900,8 @@ M68K::M68K() { } //ORI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 0000 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -924,8 +924,8 @@ M68K::M68K() { } //PEA - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1000 01-- ----") | mode << 3 | reg << 0; if(mode <= 1 || mode == 3 || mode == 4 || (mode == 7 && reg >= 4)) continue; @@ -940,11 +940,11 @@ M68K::M68K() { } //ROL (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++01 1---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ROL, count, with); bind(opcode | 1 << 6, ROL, count, with); @@ -952,8 +952,8 @@ M68K::M68K() { } //ROL (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++11 1---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -964,8 +964,8 @@ M68K::M68K() { } //ROL (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0111 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -974,11 +974,11 @@ M68K::M68K() { } //ROR (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++01 1---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ROR, count, with); bind(opcode | 1 << 6, ROR, count, with); @@ -986,8 +986,8 @@ M68K::M68K() { } //ROR (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++11 1---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -998,8 +998,8 @@ M68K::M68K() { } //ROR (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0110 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -1008,11 +1008,11 @@ M68K::M68K() { } //ROXL (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++01 0---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ROXL, count, with); bind(opcode | 1 << 6, ROXL, count, with); @@ -1020,8 +1020,8 @@ M68K::M68K() { } //ROXL (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---1 ++11 0---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -1032,8 +1032,8 @@ M68K::M68K() { } //ROXL (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0101 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -1042,11 +1042,11 @@ M68K::M68K() { } //ROXR (immediate) - for(uint3 immediate : range(8)) - for(uint3 dreg : range(8)) { + for(n3 immediate : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++01 0---") | immediate << 9 | dreg << 0; - auto count = immediate ? (uint4)immediate : (uint4)8; + auto count = immediate ? (n4)immediate : (n4)8; DataRegister with{dreg}; bind(opcode | 0 << 6, ROXR, count, with); bind(opcode | 1 << 6, ROXR, count, with); @@ -1054,8 +1054,8 @@ M68K::M68K() { } //ROXR (register) - for(uint3 sreg : range(8)) - for(uint3 dreg : range(8)) { + for(n3 sreg : range(8)) + for(n3 dreg : range(8)) { auto opcode = pattern("1110 ---0 ++11 0---") | sreg << 9 | dreg << 0; DataRegister from{sreg}; @@ -1066,8 +1066,8 @@ M68K::M68K() { } //ROXR (effective address) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1110 0100 11-- ----") | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -1094,8 +1094,8 @@ M68K::M68K() { } //SBCD - for(uint3 treg : range(8)) - for(uint3 sreg : range(8)) { + for(n3 treg : range(8)) + for(n3 sreg : range(8)) { auto opcode = pattern("1000 ---1 0000 ----") | treg << 9 | sreg << 0; EffectiveAddress dataWith{DataRegisterDirect, treg}; @@ -1108,9 +1108,9 @@ M68K::M68K() { } //SCC - for(uint4 test : range(16)) - for(uint3 mode : range( 8)) - for(uint3 reg : range( 8)) { + for(n4 test : range(16)) + for(n3 mode : range( 8)) + for(n3 reg : range( 8)) { auto opcode = pattern("0101 ---- 11-- ----") | test << 8 | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -1125,9 +1125,9 @@ M68K::M68K() { } //SUB - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1001 ---0 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -1141,9 +1141,9 @@ M68K::M68K() { } //SUB - for(uint3 dreg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 dreg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1001 ---1 ++-- ----") | dreg << 9 | mode << 3 | reg << 0; if(mode <= 1 || (mode == 7 && reg >= 2)) continue; @@ -1155,9 +1155,9 @@ M68K::M68K() { } //SUBA - for(uint3 areg : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 areg : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("1001 ---+ 11-- ----") | areg << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 5) continue; @@ -1168,8 +1168,8 @@ M68K::M68K() { } //SUBI - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0000 0100 ++-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -1180,13 +1180,13 @@ M68K::M68K() { } //SUBQ - for(uint3 data : range(8)) - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 data : range(8)) + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0101 ---1 ++-- ----") | data << 9 | mode << 3 | reg << 0; if(mode == 7 && reg >= 2) continue; - auto immediate = data ? (uint4)data : (uint4)8; + auto immediate = data ? (n4)data : (n4)8; if(mode != 1) { EffectiveAddress with{mode, reg}; bind(opcode | 0 << 6, SUBQ, immediate, with); @@ -1200,8 +1200,8 @@ M68K::M68K() { } //SUBX - for(uint3 treg : range(8)) - for(uint3 sreg : range(8)) { + for(n3 treg : range(8)) + for(n3 sreg : range(8)) { auto opcode = pattern("1001 ---1 ++00 ----") | treg << 9 | sreg << 0; EffectiveAddress dataWith{DataRegisterDirect, treg}; @@ -1218,7 +1218,7 @@ M68K::M68K() { } //SWAP - for(uint3 dreg : range(8)) { + for(n3 dreg : range(8)) { auto opcode = pattern("0100 1000 0100 0---") | dreg << 0; DataRegister with{dreg}; @@ -1226,8 +1226,8 @@ M68K::M68K() { } //TAS - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1010 11-- ----") | mode << 3 | reg << 0; if(mode == 1 || (mode == 7 && reg >= 2)) continue; @@ -1236,7 +1236,7 @@ M68K::M68K() { } //TRAP - for(uint4 vector : range(16)) { + for(n4 vector : range(16)) { auto opcode = pattern("0100 1110 0100 ----") | vector << 0; bind(opcode, TRAP, vector); @@ -1249,8 +1249,8 @@ M68K::M68K() { } //TST - for(uint3 mode : range(8)) - for(uint3 reg : range(8)) { + for(n3 mode : range(8)) + for(n3 reg : range(8)) { auto opcode = pattern("0100 1010 ++-- ----") | mode << 3 | reg << 0; if(mode == 7 && reg >= 2) continue; @@ -1263,7 +1263,7 @@ M68K::M68K() { } //UNLK - for(uint3 areg : range(8)) { + for(n3 areg : range(8)) { auto opcode = pattern("0100 1110 0101 1---") | areg << 0; AddressRegister with{areg}; @@ -1271,7 +1271,7 @@ M68K::M68K() { } //ILLEGAL - for(uint16 opcode : range(65536)) { + for(n16 opcode : range(65536)) { if(instructionTable[opcode]) continue; bind(opcode, ILLEGAL, opcode); } diff --git a/ares/component/processor/m68k/instructions.cpp b/ares/component/processor/m68k/instructions.cpp index 638acefff1..3ab3b3b7f1 100644 --- a/ares/component/processor/m68k/instructions.cpp +++ b/ares/component/processor/m68k/instructions.cpp @@ -29,7 +29,7 @@ auto M68K::instructionABCD(EffectiveAddress from, EffectiveAddress with) -> void r.x = r.c; } -template auto M68K::instructionADD(EffectiveAddress from, DataRegister with) -> void { +template auto M68K::instructionADD(EffectiveAddress from, DataRegister with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect || from.mode == AddressRegisterDirect || from.mode == Immediate) { idle(4); @@ -44,7 +44,7 @@ template auto M68K::instructionADD(EffectiveAddress from, DataRegiste write(with, result); } -template auto M68K::instructionADD(DataRegister from, EffectiveAddress with) -> void { +template auto M68K::instructionADD(DataRegister from, EffectiveAddress with) -> void { auto source = read(from); auto target = read(with); auto result = ADD(source, target); @@ -52,7 +52,7 @@ template auto M68K::instructionADD(DataRegister from, EffectiveAddres write(with, result); } -template auto M68K::instructionADDA(EffectiveAddress from, AddressRegister with) -> void { +template auto M68K::instructionADDA(EffectiveAddress from, AddressRegister with) -> void { if(Size != Long || from.mode == DataRegisterDirect || from.mode == AddressRegisterDirect || from.mode == Immediate) { idle(4); } else { @@ -64,7 +64,7 @@ template auto M68K::instructionADDA(EffectiveAddress from, AddressReg write(with, source + target); } -template auto M68K::instructionADDI(EffectiveAddress with) -> void { +template auto M68K::instructionADDI(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -75,7 +75,7 @@ template auto M68K::instructionADDI(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionADDQ(uint4 immediate, EffectiveAddress with) -> void { +template auto M68K::instructionADDQ(n4 immediate, EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -87,14 +87,14 @@ template auto M68K::instructionADDQ(uint4 immediate, EffectiveAddress } //Size is ignored: always uses Long -template auto M68K::instructionADDQ(uint4 immediate, AddressRegister with) -> void { +template auto M68K::instructionADDQ(n4 immediate, AddressRegister with) -> void { idle(4); auto result = read(with) + immediate; prefetch(); write(with, result); } -template auto M68K::instructionADDX(EffectiveAddress from, EffectiveAddress with) -> void { +template auto M68K::instructionADDX(EffectiveAddress from, EffectiveAddress with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect) idle(4); } @@ -105,7 +105,7 @@ template auto M68K::instructionADDX(EffectiveAddress from, EffectiveA write(with, result); } -template auto M68K::instructionAND(EffectiveAddress from, DataRegister with) -> void { +template auto M68K::instructionAND(EffectiveAddress from, DataRegister with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect || from.mode == Immediate) { idle(4); @@ -120,7 +120,7 @@ template auto M68K::instructionAND(EffectiveAddress from, DataRegiste write(with, result); } -template auto M68K::instructionAND(DataRegister from, EffectiveAddress with) -> void { +template auto M68K::instructionAND(DataRegister from, EffectiveAddress with) -> void { auto source = read(from); auto target = read(with); auto result = AND(source, target); @@ -128,7 +128,7 @@ template auto M68K::instructionAND(DataRegister from, EffectiveAddres write(with, result); } -template auto M68K::instructionANDI(EffectiveAddress with) -> void { +template auto M68K::instructionANDI(EffectiveAddress with) -> void { if constexpr(Size == Long) { //note: m68000um.pdf erroneously lists ANDI.L #,Dn as 14(3/0), but is in fact 16(3/0) if(with.mode == DataRegisterDirect) idle(4); @@ -158,14 +158,14 @@ auto M68K::instructionANDI_TO_SR() -> void { prefetch(); } -template auto M68K::instructionASL(uint4 count, DataRegister with) -> void { +template auto M68K::instructionASL(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ASL(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionASL(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionASL(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ASL(read(with), count); @@ -179,14 +179,14 @@ auto M68K::instructionASL(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionASR(uint4 count, DataRegister with) -> void { +template auto M68K::instructionASR(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ASR(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionASR(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionASR(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ASR(read(with), count); @@ -200,13 +200,13 @@ auto M68K::instructionASR(EffectiveAddress with) -> void { write(with, result); } -auto M68K::instructionBCC(uint4 test, uint8 displacement) -> void { +auto M68K::instructionBCC(n4 test, n8 displacement) -> void { if(!condition(test)) { idle(4); if(!displacement) prefetch(); } else { idle(2); - auto offset = displacement ? (int8_t)displacement : (int16_t)prefetched() - 2; + auto offset = displacement ? (s8)displacement : (s16)prefetched() - 2; r.pc -= 2; r.pc += offset; prefetch(); @@ -214,7 +214,7 @@ auto M68K::instructionBCC(uint4 test, uint8 displacement) -> void { prefetch(); } -template auto M68K::instructionBCHG(DataRegister bit, EffectiveAddress with) -> void { +template auto M68K::instructionBCHG(DataRegister bit, EffectiveAddress with) -> void { auto index = read(bit) & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 2 : 4); @@ -226,7 +226,7 @@ template auto M68K::instructionBCHG(DataRegister bit, EffectiveAddres write(with, test); } -template auto M68K::instructionBCHG(EffectiveAddress with) -> void { +template auto M68K::instructionBCHG(EffectiveAddress with) -> void { auto index = extension() & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 2 : 4); @@ -238,7 +238,7 @@ template auto M68K::instructionBCHG(EffectiveAddress with) -> void { write(with, test); } -template auto M68K::instructionBCLR(DataRegister bit, EffectiveAddress with) -> void { +template auto M68K::instructionBCLR(DataRegister bit, EffectiveAddress with) -> void { auto index = read(bit) & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 4 : 6); @@ -250,7 +250,7 @@ template auto M68K::instructionBCLR(DataRegister bit, EffectiveAddres write(with, test); } -template auto M68K::instructionBCLR(EffectiveAddress with) -> void { +template auto M68K::instructionBCLR(EffectiveAddress with) -> void { auto index = extension() & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 4 : 6); @@ -262,16 +262,16 @@ template auto M68K::instructionBCLR(EffectiveAddress with) -> void { write(with, test); } -auto M68K::instructionBRA(uint8 displacement) -> void { +auto M68K::instructionBRA(n8 displacement) -> void { idle(2); - auto offset = displacement ? (int8_t)displacement : (int16_t)prefetched() - 2; + auto offset = displacement ? (s8)displacement : (s16)prefetched() - 2; r.pc -= 2; r.pc += offset; prefetch(); prefetch(); } -template auto M68K::instructionBSET(DataRegister bit, EffectiveAddress with) -> void { +template auto M68K::instructionBSET(DataRegister bit, EffectiveAddress with) -> void { auto index = read(bit) & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 2 : 4); @@ -283,7 +283,7 @@ template auto M68K::instructionBSET(DataRegister bit, EffectiveAddres write(with, test); } -template auto M68K::instructionBSET(EffectiveAddress with) -> void { +template auto M68K::instructionBSET(EffectiveAddress with) -> void { auto index = extension() & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(index < 16 ? 2 : 4); @@ -295,9 +295,9 @@ template auto M68K::instructionBSET(EffectiveAddress with) -> void { write(with, test); } -auto M68K::instructionBSR(uint8 displacement) -> void { +auto M68K::instructionBSR(n8 displacement) -> void { idle(2); - auto offset = displacement ? (int8_t)displacement : (int16_t)prefetched() - 2; + auto offset = displacement ? (s8)displacement : (s16)prefetched() - 2; r.pc -= 2; push(r.pc); r.pc += offset; @@ -305,7 +305,7 @@ auto M68K::instructionBSR(uint8 displacement) -> void { prefetch(); } -template auto M68K::instructionBTST(DataRegister bit, EffectiveAddress with) -> void { +template auto M68K::instructionBTST(DataRegister bit, EffectiveAddress with) -> void { auto index = read(bit) & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(2); @@ -315,7 +315,7 @@ template auto M68K::instructionBTST(DataRegister bit, EffectiveAddres prefetch(); } -template auto M68K::instructionBTST(EffectiveAddress with) -> void { +template auto M68K::instructionBTST(EffectiveAddress with) -> void { auto index = extension() & bits() - 1; if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(2); @@ -334,7 +334,7 @@ auto M68K::instructionCHK(DataRegister compare, EffectiveAddress maximum) -> voi r.n = sign(target) < 0; if(r.n) return exception(Exception::BoundsCheck, Vector::BoundsCheck); - auto result = (uint64)target - source; + auto result = (n64)target - source; r.c = sign(result >> 1) < 0; r.v = sign((target ^ source) & (target ^ result)) < 0; r.z = clip(result) == 0; @@ -343,7 +343,7 @@ auto M68K::instructionCHK(DataRegister compare, EffectiveAddress maximum) -> voi prefetch(); } -template auto M68K::instructionCLR(EffectiveAddress with) -> void { +template auto M68K::instructionCLR(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect || with.mode == AddressRegisterDirect) idle(2); } @@ -356,7 +356,7 @@ template auto M68K::instructionCLR(EffectiveAddress with) -> void { r.n = 0; } -template auto M68K::instructionCMP(EffectiveAddress from, DataRegister with) -> void { +template auto M68K::instructionCMP(EffectiveAddress from, DataRegister with) -> void { if constexpr(Size == Long) idle(2); auto source = read(from); auto target = read(with); @@ -364,7 +364,7 @@ template auto M68K::instructionCMP(EffectiveAddress from, DataRegiste prefetch(); } -template auto M68K::instructionCMPA(EffectiveAddress from, AddressRegister with) -> void { +template auto M68K::instructionCMPA(EffectiveAddress from, AddressRegister with) -> void { idle(2); auto source = sign(read(from)); auto target = read(with); @@ -372,7 +372,7 @@ template auto M68K::instructionCMPA(EffectiveAddress from, AddressReg prefetch(); } -template auto M68K::instructionCMPI(EffectiveAddress with) -> void { +template auto M68K::instructionCMPI(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(2); } @@ -382,19 +382,19 @@ template auto M68K::instructionCMPI(EffectiveAddress with) -> void { prefetch(); } -template auto M68K::instructionCMPM(EffectiveAddress from, EffectiveAddress with) -> void { +template auto M68K::instructionCMPM(EffectiveAddress from, EffectiveAddress with) -> void { auto source = read(from); auto target = read(with); CMP(source, target); prefetch(); } -auto M68K::instructionDBCC(uint4 test, DataRegister with) -> void { +auto M68K::instructionDBCC(n4 test, DataRegister with) -> void { auto displacement = extension(); if(condition(test)) { idle(4); } else { - uint16 result = read(with); + n16 result = read(with); write(with, result - 1); if(result) { idle(2); @@ -409,8 +409,8 @@ auto M68K::instructionDBCC(uint4 test, DataRegister with) -> void { } auto M68K::instructionDIVS(EffectiveAddress from, DataRegister with) -> void { - uint32 dividend = read(with), odividend = dividend; - uint32 divisor = read(from) << 16, odivisor = divisor; + n32 dividend = read(with), odividend = dividend; + n32 divisor = read(from) << 16, odivisor = divisor; if(divisor == 0) { return exception(Exception::DivisionByZero, Vector::DivisionByZero); @@ -434,10 +434,10 @@ auto M68K::instructionDIVS(EffectiveAddress from, DataRegister with) -> void { return; } - uint16 quotient = 0; + n16 quotient = 0; bool carry = 0; - uint ticks = 12; - for(uint index : range(15)) { + u32 ticks = 12; + for(u32 index : range(15)) { dividend = dividend << 1; quotient = quotient << 1 | carry; if(carry = dividend >= divisor) dividend -= divisor; @@ -485,8 +485,8 @@ auto M68K::instructionDIVS(EffectiveAddress from, DataRegister with) -> void { } auto M68K::instructionDIVU(EffectiveAddress from, DataRegister with) -> void { - uint32 dividend = read(with); - uint32 divisor = read(from) << 16; + n32 dividend = read(with); + n32 divisor = read(from) << 16; if(divisor == 0) { return exception(Exception::DivisionByZero, Vector::DivisionByZero); @@ -501,11 +501,11 @@ auto M68K::instructionDIVU(EffectiveAddress from, DataRegister with) -> void { return; } - uint16 quotient = 0; + n16 quotient = 0; bool force = 0; bool carry = 0; - uint ticks = 6; - for(uint index : range(16)) { + u32 ticks = 6; + for(u32 index : range(16)) { force = dividend >> 31; dividend = dividend << 1; quotient = quotient << 1 | carry; @@ -523,7 +523,7 @@ auto M68K::instructionDIVU(EffectiveAddress from, DataRegister with) -> void { prefetch(); } -template auto M68K::instructionEOR(DataRegister from, EffectiveAddress with) -> void { +template auto M68K::instructionEOR(DataRegister from, EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -534,7 +534,7 @@ template auto M68K::instructionEOR(DataRegister from, EffectiveAddres write(with, result); } -template auto M68K::instructionEORI(EffectiveAddress with) -> void { +template auto M68K::instructionEORI(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -588,7 +588,7 @@ auto M68K::instructionEXG(DataRegister x, AddressRegister y) -> void { } template<> auto M68K::instructionEXT(DataRegister with) -> void { - auto result = (int8)read(with); + auto result = (i8)read(with); write(with, result); r.c = 0; @@ -599,7 +599,7 @@ template<> auto M68K::instructionEXT(DataRegister with) -> void { } template<> auto M68K::instructionEXT(DataRegister with) -> void { - auto result = (int16)read(with); + auto result = (i16)read(with); write(with, result); r.c = 0; @@ -609,7 +609,7 @@ template<> auto M68K::instructionEXT(DataRegister with) -> void { prefetch(); } -auto M68K::instructionILLEGAL(uint16 code) -> void { +auto M68K::instructionILLEGAL(n16 code) -> void { idle(6); r.pc -= 2; if(code.bit(12,15) == 0xa) return exception(Exception::Illegal, Vector::IllegalLineA); @@ -639,7 +639,7 @@ auto M68K::instructionLEA(EffectiveAddress from, AddressRegister to) -> void { } auto M68K::instructionLINK(AddressRegister with) -> void { - auto displacement = (int16)extension(); + auto displacement = (i16)extension(); auto sp = AddressRegister{7}; push(read(with)); write(with, read(sp)); @@ -647,14 +647,14 @@ auto M68K::instructionLINK(AddressRegister with) -> void { prefetch(); } -template auto M68K::instructionLSL(uint4 count, DataRegister with) -> void { +template auto M68K::instructionLSL(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = LSL(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionLSL(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionLSL(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = LSL(read(with), count); @@ -668,14 +668,14 @@ auto M68K::instructionLSL(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionLSR(uint4 count, DataRegister with) -> void { +template auto M68K::instructionLSR(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = LSR(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionLSR(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionLSR(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = LSR(read(with), count); @@ -690,7 +690,7 @@ auto M68K::instructionLSR(EffectiveAddress with) -> void { } //todo: move memory,(xxx).l should interleave extension fetches with writes -template auto M68K::instructionMOVE(EffectiveAddress from, EffectiveAddress to) -> void { +template auto M68K::instructionMOVE(EffectiveAddress from, EffectiveAddress to) -> void { auto data = read(from); r.c = 0; r.v = 0; @@ -706,20 +706,20 @@ template auto M68K::instructionMOVE(EffectiveAddress from, EffectiveA } } -template auto M68K::instructionMOVEA(EffectiveAddress from, AddressRegister to) -> void { +template auto M68K::instructionMOVEA(EffectiveAddress from, AddressRegister to) -> void { auto data = sign(read(from)); write(to, data); prefetch(); } -template auto M68K::instructionMOVEM_TO_MEM(EffectiveAddress to) -> void { +template auto M68K::instructionMOVEM_TO_MEM(EffectiveAddress to) -> void { auto list = extension(); auto addr = fetch(to); - for(uint n : range(16)) { + for(u32 n : range(16)) { if(!list.bit(n)) continue; //pre-decrement mode traverses registers in reverse order {A7-A0, D7-D0} - uint index = to.mode == AddressRegisterIndirectWithPreDecrement ? 15 - n : n; + u32 index = to.mode == AddressRegisterIndirectWithPreDecrement ? 15 - n : n; if(to.mode == AddressRegisterIndirectWithPreDecrement) addr -= bytes(); auto data = index < 8 ? read(DataRegister{index}) : read(AddressRegister{index}); @@ -733,13 +733,13 @@ template auto M68K::instructionMOVEM_TO_MEM(EffectiveAddress to) -> v prefetch(); } -template auto M68K::instructionMOVEM_TO_REG(EffectiveAddress from) -> void { +template auto M68K::instructionMOVEM_TO_REG(EffectiveAddress from) -> void { auto list = extension(); auto addr = fetch(from); - for(uint n : range(16)) { + for(u32 n : range(16)) { if(!list.bit(n)) continue; - uint index = from.mode == AddressRegisterIndirectWithPreDecrement ? 15 - n : n; + u32 index = from.mode == AddressRegisterIndirectWithPreDecrement ? 15 - n : n; if(from.mode == AddressRegisterIndirectWithPreDecrement) addr -= bytes(); auto data = read(addr); @@ -758,10 +758,10 @@ template auto M68K::instructionMOVEM_TO_REG(EffectiveAddress from) -> prefetch(); } -template auto M68K::instructionMOVEP(DataRegister from, EffectiveAddress to) -> void { +template auto M68K::instructionMOVEP(DataRegister from, EffectiveAddress to) -> void { auto address = fetch(to); auto data = read(from); - uint shift = bits(); + u32 shift = bits(); for(auto _ : range(bytes())) { shift -= 8; write(address, data >> shift); @@ -770,10 +770,10 @@ template auto M68K::instructionMOVEP(DataRegister from, EffectiveAddr prefetch(); } -template auto M68K::instructionMOVEP(EffectiveAddress from, DataRegister to) -> void { +template auto M68K::instructionMOVEP(EffectiveAddress from, DataRegister to) -> void { auto address = fetch(from); auto data = read(to); - uint shift = bits(); + u32 shift = bits(); for(auto _ : range(bytes())) { shift -= 8; data &= ~(0xff << shift); @@ -784,7 +784,7 @@ template auto M68K::instructionMOVEP(EffectiveAddress from, DataRegis prefetch(); } -auto M68K::instructionMOVEQ(uint8 immediate, DataRegister to) -> void { +auto M68K::instructionMOVEQ(n8 immediate, DataRegister to) -> void { write(to, sign(immediate)); r.c = 0; @@ -837,9 +837,9 @@ auto M68K::instructionMOVE_TO_USP(AddressRegister from) -> void { auto M68K::instructionMULS(EffectiveAddress from, DataRegister with) -> void { auto source = read(from); auto target = read(with); - auto result = (int16)source * (int16)target; + auto result = (i16)source * (i16)target; //+2 cycles per 0<>1 bit transition - auto cycles = bit::count(uint16(source << 1) ^ source); + auto cycles = bit::count(n16(source << 1) ^ source); idle(34 + cycles * 2); write(with, result); @@ -901,7 +901,7 @@ auto M68K::instructionNBCD(EffectiveAddress with) -> void { prefetch(); } -template auto M68K::instructionNEG(EffectiveAddress with) -> void { +template auto M68K::instructionNEG(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect || with.mode == AddressRegisterDirect) idle(2); } @@ -910,7 +910,7 @@ template auto M68K::instructionNEG(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionNEGX(EffectiveAddress with) -> void { +template auto M68K::instructionNEGX(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect || with.mode == AddressRegisterDirect) idle(2); } @@ -923,7 +923,7 @@ auto M68K::instructionNOP() -> void { prefetch(); } -template auto M68K::instructionNOT(EffectiveAddress with) -> void { +template auto M68K::instructionNOT(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect || with.mode == AddressRegisterDirect) idle(2); } @@ -937,7 +937,7 @@ template auto M68K::instructionNOT(EffectiveAddress with) -> void { r.n = sign(result) < 0; } -template auto M68K::instructionOR(EffectiveAddress from, DataRegister with) -> void { +template auto M68K::instructionOR(EffectiveAddress from, DataRegister with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect || from.mode == Immediate) { idle(4); @@ -952,7 +952,7 @@ template auto M68K::instructionOR(EffectiveAddress from, DataRegister write(with, result); } -template auto M68K::instructionOR(DataRegister from, EffectiveAddress with) -> void { +template auto M68K::instructionOR(DataRegister from, EffectiveAddress with) -> void { auto source = read(from); auto target = read(with); auto result = OR(source, target); @@ -960,7 +960,7 @@ template auto M68K::instructionOR(DataRegister from, EffectiveAddress write(with, result); } -template auto M68K::instructionORI(EffectiveAddress with) -> void { +template auto M68K::instructionORI(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -1010,14 +1010,14 @@ auto M68K::instructionRESET() -> void { prefetch(); } -template auto M68K::instructionROL(uint4 count, DataRegister with) -> void { +template auto M68K::instructionROL(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ROL(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionROL(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionROL(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ROL(read(with), count); @@ -1031,14 +1031,14 @@ auto M68K::instructionROL(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionROR(uint4 count, DataRegister with) -> void { +template auto M68K::instructionROR(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ROR(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionROR(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionROR(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ROR(read(with), count); @@ -1052,14 +1052,14 @@ auto M68K::instructionROR(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionROXL(uint4 count, DataRegister with) -> void { +template auto M68K::instructionROXL(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ROXL(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionROXL(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionROXL(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ROXL(read(with), count); @@ -1073,14 +1073,14 @@ auto M68K::instructionROXL(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionROXR(uint4 count, DataRegister with) -> void { +template auto M68K::instructionROXR(n4 count, DataRegister with) -> void { idle((Size != Long ? 2 : 4) + count * 2); auto result = ROXR(read(with), count); prefetch(); write(with, result); } -template auto M68K::instructionROXR(DataRegister from, DataRegister with) -> void { +template auto M68K::instructionROXR(DataRegister from, DataRegister with) -> void { auto count = read(from) & 63; idle((Size != Long ? 2 : 4) + count * 2); auto result = ROXR(read(with), count); @@ -1152,7 +1152,7 @@ auto M68K::instructionSBCD(EffectiveAddress from, EffectiveAddress with) -> void r.x = r.c; } -auto M68K::instructionSCC(uint4 test, EffectiveAddress to) -> void { +auto M68K::instructionSCC(n4 test, EffectiveAddress to) -> void { fetch(to); prefetch(); if(!condition(test)) { @@ -1172,7 +1172,7 @@ auto M68K::instructionSTOP() -> void { prefetch(); } -template auto M68K::instructionSUB(EffectiveAddress from, DataRegister with) -> void { +template auto M68K::instructionSUB(EffectiveAddress from, DataRegister with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect || from.mode == AddressRegisterDirect || from.mode == Immediate) { idle(4); @@ -1187,7 +1187,7 @@ template auto M68K::instructionSUB(EffectiveAddress from, DataRegiste write(with, result); } -template auto M68K::instructionSUB(DataRegister from, EffectiveAddress with) -> void { +template auto M68K::instructionSUB(DataRegister from, EffectiveAddress with) -> void { auto source = read(from); auto target = read(with); auto result = SUB(source, target); @@ -1195,7 +1195,7 @@ template auto M68K::instructionSUB(DataRegister from, EffectiveAddres write(with, result); } -template auto M68K::instructionSUBA(EffectiveAddress from, AddressRegister to) -> void { +template auto M68K::instructionSUBA(EffectiveAddress from, AddressRegister to) -> void { if(Size != Long || from.mode == DataRegisterDirect || from.mode == AddressRegisterDirect || from.mode == Immediate) { idle(4); } else { @@ -1207,7 +1207,7 @@ template auto M68K::instructionSUBA(EffectiveAddress from, AddressReg write(to, target - source); } -template auto M68K::instructionSUBI(EffectiveAddress with) -> void { +template auto M68K::instructionSUBI(EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -1218,7 +1218,7 @@ template auto M68K::instructionSUBI(EffectiveAddress with) -> void { write(with, result); } -template auto M68K::instructionSUBQ(uint4 immediate, EffectiveAddress with) -> void { +template auto M68K::instructionSUBQ(n4 immediate, EffectiveAddress with) -> void { if constexpr(Size == Long) { if(with.mode == DataRegisterDirect) idle(4); } @@ -1230,14 +1230,14 @@ template auto M68K::instructionSUBQ(uint4 immediate, EffectiveAddress } //Size is ignored: always uses Long -template auto M68K::instructionSUBQ(uint4 immediate, AddressRegister with) -> void { +template auto M68K::instructionSUBQ(n4 immediate, AddressRegister with) -> void { idle(4); auto result = read(with) - immediate; prefetch(); write(with, result); } -template auto M68K::instructionSUBX(EffectiveAddress from, EffectiveAddress with) -> void { +template auto M68K::instructionSUBX(EffectiveAddress from, EffectiveAddress with) -> void { if constexpr(Size == Long) { if(from.mode == DataRegisterDirect) idle(4); } @@ -1261,7 +1261,7 @@ auto M68K::instructionSWAP(DataRegister with) -> void { } auto M68K::instructionTAS(EffectiveAddress with) -> void { - uint32 data; + n32 data; if(with.mode == DataRegisterDirect) { data = read(with); @@ -1281,7 +1281,7 @@ auto M68K::instructionTAS(EffectiveAddress with) -> void { r.n = sign(data) < 0; } -auto M68K::instructionTRAP(uint4 vector) -> void { +auto M68K::instructionTRAP(n4 vector) -> void { idle(6); prefetched(); return exception(Exception::Trap, 32 + vector, r.i); @@ -1296,7 +1296,7 @@ auto M68K::instructionTRAPV() -> void { prefetch(); } -template auto M68K::instructionTST(EffectiveAddress from) -> void { +template auto M68K::instructionTST(EffectiveAddress from) -> void { auto data = read(from); r.c = 0; r.v = 0; diff --git a/ares/component/processor/m68k/m68k.cpp b/ares/component/processor/m68k/m68k.cpp index 3ab7fff3d5..3e9cf12f52 100644 --- a/ares/component/processor/m68k/m68k.cpp +++ b/ares/component/processor/m68k/m68k.cpp @@ -3,7 +3,7 @@ namespace ares { -enum : uint { Byte, Word, Long }; +enum : u32 { Byte, Word, Long }; enum : bool { Reverse = 1 }; #include "registers.cpp" @@ -48,7 +48,7 @@ auto M68K::supervisor() -> bool { return false; } -auto M68K::exception(uint exception, uint vector, uint priority) -> void { +auto M68K::exception(u32 exception, u32 vector, u32 priority) -> void { idle(10); //todo: not accurate auto pc = r.pc; @@ -69,7 +69,7 @@ auto M68K::exception(uint exception, uint vector, uint priority) -> void { prefetch(); } -auto M68K::interrupt(uint vector, uint priority) -> void { +auto M68K::interrupt(u32 vector, u32 priority) -> void { return exception(Exception::Interrupt, vector, priority); } diff --git a/ares/component/processor/m68k/m68k.hpp b/ares/component/processor/m68k/m68k.hpp index d56e8b9589..9992783d2e 100644 --- a/ares/component/processor/m68k/m68k.hpp +++ b/ares/component/processor/m68k/m68k.hpp @@ -5,18 +5,18 @@ namespace ares { struct M68K { - virtual auto idle(uint clocks) -> void = 0; - virtual auto wait(uint clocks) -> void = 0; - virtual auto read(uint1 upper, uint1 lower, uint24 address, uint16 data = 0) -> uint16 = 0; - virtual auto write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void = 0; + virtual auto idle(u32 clocks) -> void = 0; + virtual auto wait(u32 clocks) -> void = 0; + virtual auto read(n1 upper, n1 lower, n24 address, n16 data = 0) -> n16 = 0; + virtual auto write(n1 upper, n1 lower, n24 address, n16 data) -> void = 0; - auto ird() const -> uint16 { return r.ird; } + auto ird() const -> n16 { return r.ird; } enum : bool { User, Supervisor }; - enum : uint { Byte, Word, Long }; + enum : u32 { Byte, Word, Long }; enum : bool { Reverse = 1, Extend = 1, Hold = 1, Fast = 1 }; - enum : uint { + enum : u32 { /* 0,n */ DataRegisterDirect, /* 1,n */ AddressRegisterDirect, /* 2,n */ AddressRegisterIndirect, @@ -31,7 +31,7 @@ struct M68K { /* 7,4 */ Immediate, }; - struct Exception { enum : uint { + struct Exception { enum : u32 { Illegal, DivisionByZero, BoundsCheck, @@ -42,7 +42,7 @@ struct M68K { Interrupt, };}; - struct Vector { enum : uint { + struct Vector { enum : u32 { Reset = 1, BusError = 2, AddressError = 3, @@ -66,229 +66,229 @@ struct M68K { M68K(); auto power() -> void; auto supervisor() -> bool; - auto exception(uint exception, uint vector, uint priority = 7) -> void; - auto interrupt(uint vector, uint priority = 7) -> void; + auto exception(u32 exception, u32 vector, u32 priority = 7) -> void; + auto interrupt(u32 vector, u32 priority = 7) -> void; //registers.cpp struct DataRegister { - explicit DataRegister(uint64 number_) : number(number_) {} - uint3 number; + explicit DataRegister(n64 number_) : number(number_) {} + n3 number; }; - template auto read(DataRegister reg) -> uint32; - template auto write(DataRegister reg, uint32 data) -> void; + template auto read(DataRegister reg) -> n32; + template auto write(DataRegister reg, n32 data) -> void; struct AddressRegister { - explicit AddressRegister(uint64 number_) : number(number_) {} - uint3 number; + explicit AddressRegister(n64 number_) : number(number_) {} + n3 number; }; - template auto read(AddressRegister reg) -> uint32; - template auto write(AddressRegister reg, uint32 data) -> void; + template auto read(AddressRegister reg) -> n32; + template auto write(AddressRegister reg, n32 data) -> void; - auto readCCR() -> uint8; - auto readSR() -> uint16; - auto writeCCR(uint8 ccr) -> void; - auto writeSR(uint16 sr) -> void; + auto readCCR() -> n8; + auto readSR() -> n16; + auto writeCCR(n8 ccr) -> void; + auto writeSR(n16 sr) -> void; //memory.cpp - template auto read(uint32 addr) -> uint32; - template auto write(uint32 addr, uint32 data) -> void; - template auto extension() -> uint32; - auto prefetch() -> uint16; - auto prefetched() -> uint16; - template auto pop() -> uint32; - template auto push(uint32 data) -> void; + template auto read(n32 addr) -> n32; + template auto write(n32 addr, n32 data) -> void; + template auto extension() -> n32; + auto prefetch() -> n16; + auto prefetched() -> n16; + template auto pop() -> n32; + template auto push(n32 data) -> void; //effective-address.cpp struct EffectiveAddress { - explicit EffectiveAddress(uint4 mode_, uint3 reg_) : mode(mode_), reg(reg_) { + explicit EffectiveAddress(n4 mode_, n3 reg_) : mode(mode_), reg(reg_) { if(mode == 7) mode += reg; //optimization: convert modes {7; 0-4} to {7-11} } - uint4 mode; - uint3 reg; + n4 mode; + n3 reg; - boolean valid; - uint32 address; + b1 valid; + n32 address; }; - auto prefetched(EffectiveAddress& ea) -> uint32; - template auto fetch(EffectiveAddress& ea) -> uint32; - template auto read(EffectiveAddress& ea) -> uint32; - template auto write(EffectiveAddress& ea, uint32 data) -> void; + auto prefetched(EffectiveAddress& ea) -> n32; + template auto fetch(EffectiveAddress& ea) -> n32; + template auto read(EffectiveAddress& ea) -> n32; + template auto write(EffectiveAddress& ea, n32 data) -> void; //instruction.cpp auto instruction() -> void; //traits.cpp - template auto bytes() -> uint; - template auto bits() -> uint; - template auto lsb() -> uint32; - template auto msb() -> uint32; - template auto mask() -> uint32; - template auto clip(uint32 data) -> uint32; - template auto sign(uint32 data) -> int32; + template auto bytes() -> u32; + template auto bits() -> u32; + template auto lsb() -> n32; + template auto msb() -> n32; + template auto mask() -> n32; + template auto clip(n32 data) -> n32; + template auto sign(n32 data) -> i32; //conditions.cpp - auto condition(uint4 condition) -> bool; + auto condition(n4 condition) -> bool; //algorithms.cpp - template auto ADD(uint32 source, uint32 target) -> uint32; - template auto AND(uint32 source, uint32 target) -> uint32; - template auto ASL(uint32 result, uint shift) -> uint32; - template auto ASR(uint32 result, uint shift) -> uint32; - template auto CMP(uint32 source, uint32 target) -> uint32; - template auto EOR(uint32 source, uint32 target) -> uint32; - template auto LSL(uint32 result, uint shift) -> uint32; - template auto LSR(uint32 result, uint shift) -> uint32; - template auto OR(uint32 source, uint32 target) -> uint32; - template auto ROL(uint32 result, uint shift) -> uint32; - template auto ROR(uint32 result, uint shift) -> uint32; - template auto ROXL(uint32 result, uint shift) -> uint32; - template auto ROXR(uint32 result, uint shift) -> uint32; - template auto SUB(uint32 source, uint32 target) -> uint32; + template auto ADD(n32 source, n32 target) -> n32; + template auto AND(n32 source, n32 target) -> n32; + template auto ASL(n32 result, u32 shift) -> n32; + template auto ASR(n32 result, u32 shift) -> n32; + template auto CMP(n32 source, n32 target) -> n32; + template auto EOR(n32 source, n32 target) -> n32; + template auto LSL(n32 result, u32 shift) -> n32; + template auto LSR(n32 result, u32 shift) -> n32; + template auto OR(n32 source, n32 target) -> n32; + template auto ROL(n32 result, u32 shift) -> n32; + template auto ROR(n32 result, u32 shift) -> n32; + template auto ROXL(n32 result, u32 shift) -> n32; + template auto ROXR(n32 result, u32 shift) -> n32; + template auto SUB(n32 source, n32 target) -> n32; //instructions.cpp - auto instructionABCD(EffectiveAddress from, EffectiveAddress with) -> void; - template auto instructionADD(EffectiveAddress from, DataRegister with) -> void; - template auto instructionADD(DataRegister from, EffectiveAddress with) -> void; - template auto instructionADDA(EffectiveAddress from, AddressRegister with) -> void; - template auto instructionADDI(EffectiveAddress with) -> void; - template auto instructionADDQ(uint4 immediate, EffectiveAddress with) -> void; - template auto instructionADDQ(uint4 immediate, AddressRegister with) -> void; - template auto instructionADDX(EffectiveAddress with, EffectiveAddress from) -> void; - template auto instructionAND(EffectiveAddress from, DataRegister with) -> void; - template auto instructionAND(DataRegister from, EffectiveAddress with) -> void; - template auto instructionANDI(EffectiveAddress with) -> void; - auto instructionANDI_TO_CCR() -> void; - auto instructionANDI_TO_SR() -> void; - template auto instructionASL(uint4 count, DataRegister modify) -> void; - template auto instructionASL(DataRegister from, DataRegister modify) -> void; - auto instructionASL(EffectiveAddress modify) -> void; - template auto instructionASR(uint4 count, DataRegister modify) -> void; - template auto instructionASR(DataRegister from, DataRegister modify) -> void; - auto instructionASR(EffectiveAddress modify) -> void; - auto instructionBCC(uint4 test, uint8 displacement) -> void; - template auto instructionBCHG(DataRegister bit, EffectiveAddress with) -> void; - template auto instructionBCHG(EffectiveAddress with) -> void; - template auto instructionBCLR(DataRegister bit, EffectiveAddress with) -> void; - template auto instructionBCLR(EffectiveAddress with) -> void; - auto instructionBRA(uint8 displacement) -> void; - template auto instructionBSET(DataRegister bit, EffectiveAddress with) -> void; - template auto instructionBSET(EffectiveAddress with) -> void; - auto instructionBSR(uint8 displacement) -> void; - template auto instructionBTST(DataRegister bit, EffectiveAddress with) -> void; - template auto instructionBTST(EffectiveAddress with) -> void; - auto instructionCHK(DataRegister compare, EffectiveAddress maximum) -> void; - template auto instructionCLR(EffectiveAddress with) -> void; - template auto instructionCMP(EffectiveAddress from, DataRegister with) -> void; - template auto instructionCMPA(EffectiveAddress from, AddressRegister with) -> void; - template auto instructionCMPI(EffectiveAddress with) -> void; - template auto instructionCMPM(EffectiveAddress from, EffectiveAddress with) -> void; - auto instructionDBCC(uint4 condition, DataRegister with) -> void; - auto instructionDIVS(EffectiveAddress from, DataRegister with) -> void; - auto instructionDIVU(EffectiveAddress from, DataRegister with) -> void; - template auto instructionEOR(DataRegister from, EffectiveAddress with) -> void; - template auto instructionEORI(EffectiveAddress with) -> void; - auto instructionEORI_TO_CCR() -> void; - auto instructionEORI_TO_SR() -> void; - auto instructionEXG(DataRegister x, DataRegister y) -> void; - auto instructionEXG(AddressRegister x, AddressRegister y) -> void; - auto instructionEXG(DataRegister x, AddressRegister y) -> void; - template auto instructionEXT(DataRegister with) -> void; - auto instructionILLEGAL(uint16 code) -> void; - auto instructionJMP(EffectiveAddress from) -> void; - auto instructionJSR(EffectiveAddress from) -> void; - auto instructionLEA(EffectiveAddress from, AddressRegister to) -> void; - auto instructionLINK(AddressRegister with) -> void; - template auto instructionLSL(uint4 count, DataRegister with) -> void; - template auto instructionLSL(DataRegister from, DataRegister with) -> void; - auto instructionLSL(EffectiveAddress with) -> void; - template auto instructionLSR(uint4 count, DataRegister with) -> void; - template auto instructionLSR(DataRegister from, DataRegister with) -> void; - auto instructionLSR(EffectiveAddress with) -> void; - template auto instructionMOVE(EffectiveAddress from, EffectiveAddress to) -> void; - template auto instructionMOVEA(EffectiveAddress from, AddressRegister to) -> void; - template auto instructionMOVEM_TO_MEM(EffectiveAddress to) -> void; - template auto instructionMOVEM_TO_REG(EffectiveAddress from) -> void; - template auto instructionMOVEP(DataRegister from, EffectiveAddress to) -> void; - template auto instructionMOVEP(EffectiveAddress from, DataRegister to) -> void; - auto instructionMOVEQ(uint8 immediate, DataRegister to) -> void; - auto instructionMOVE_FROM_SR(EffectiveAddress to) -> void; - auto instructionMOVE_TO_CCR(EffectiveAddress from) -> void; - auto instructionMOVE_TO_SR(EffectiveAddress from) -> void; - auto instructionMOVE_FROM_USP(AddressRegister to) -> void; - auto instructionMOVE_TO_USP(AddressRegister from) -> void; - auto instructionMULS(EffectiveAddress from, DataRegister with) -> void; - auto instructionMULU(EffectiveAddress from, DataRegister with) -> void; - auto instructionNBCD(EffectiveAddress with) -> void; - template auto instructionNEG(EffectiveAddress with) -> void; - template auto instructionNEGX(EffectiveAddress with) -> void; - auto instructionNOP() -> void; - template auto instructionNOT(EffectiveAddress with) -> void; - template auto instructionOR(EffectiveAddress from, DataRegister with) -> void; - template auto instructionOR(DataRegister from, EffectiveAddress with) -> void; - template auto instructionORI(EffectiveAddress with) -> void; - auto instructionORI_TO_CCR() -> void; - auto instructionORI_TO_SR() -> void; - auto instructionPEA(EffectiveAddress from) -> void; - auto instructionRESET() -> void; - template auto instructionROL(uint4 count, DataRegister with) -> void; - template auto instructionROL(DataRegister from, DataRegister with) -> void; - auto instructionROL(EffectiveAddress with) -> void; - template auto instructionROR(uint4 count, DataRegister with) -> void; - template auto instructionROR(DataRegister from, DataRegister with) -> void; - auto instructionROR(EffectiveAddress with) -> void; - template auto instructionROXL(uint4 count, DataRegister with) -> void; - template auto instructionROXL(DataRegister from, DataRegister with) -> void; - auto instructionROXL(EffectiveAddress with) -> void; - template auto instructionROXR(uint4 count, DataRegister with) -> void; - template auto instructionROXR(DataRegister from, DataRegister with) -> void; - auto instructionROXR(EffectiveAddress with) -> void; - auto instructionRTE() -> void; - auto instructionRTR() -> void; - auto instructionRTS() -> void; - auto instructionSBCD(EffectiveAddress with, EffectiveAddress from) -> void; - auto instructionSCC(uint4 test, EffectiveAddress to) -> void; - auto instructionSTOP() -> void; - template auto instructionSUB(EffectiveAddress from, DataRegister with) -> void; - template auto instructionSUB(DataRegister from, EffectiveAddress with) -> void; - template auto instructionSUBA(EffectiveAddress from, AddressRegister with) -> void; - template auto instructionSUBI(EffectiveAddress with) -> void; - template auto instructionSUBQ(uint4 immediate, EffectiveAddress with) -> void; - template auto instructionSUBQ(uint4 immediate, AddressRegister with) -> void; - template auto instructionSUBX(EffectiveAddress from, EffectiveAddress with) -> void; - auto instructionSWAP(DataRegister with) -> void; - auto instructionTAS(EffectiveAddress with) -> void; - auto instructionTRAP(uint4 vector) -> void; - auto instructionTRAPV() -> void; - template auto instructionTST(EffectiveAddress from) -> void; - auto instructionUNLK(AddressRegister with) -> void; + auto instructionABCD(EffectiveAddress from, EffectiveAddress with) -> void; + template auto instructionADD(EffectiveAddress from, DataRegister with) -> void; + template auto instructionADD(DataRegister from, EffectiveAddress with) -> void; + template auto instructionADDA(EffectiveAddress from, AddressRegister with) -> void; + template auto instructionADDI(EffectiveAddress with) -> void; + template auto instructionADDQ(n4 immediate, EffectiveAddress with) -> void; + template auto instructionADDQ(n4 immediate, AddressRegister with) -> void; + template auto instructionADDX(EffectiveAddress with, EffectiveAddress from) -> void; + template auto instructionAND(EffectiveAddress from, DataRegister with) -> void; + template auto instructionAND(DataRegister from, EffectiveAddress with) -> void; + template auto instructionANDI(EffectiveAddress with) -> void; + auto instructionANDI_TO_CCR() -> void; + auto instructionANDI_TO_SR() -> void; + template auto instructionASL(n4 count, DataRegister modify) -> void; + template auto instructionASL(DataRegister from, DataRegister modify) -> void; + auto instructionASL(EffectiveAddress modify) -> void; + template auto instructionASR(n4 count, DataRegister modify) -> void; + template auto instructionASR(DataRegister from, DataRegister modify) -> void; + auto instructionASR(EffectiveAddress modify) -> void; + auto instructionBCC(n4 test, n8 displacement) -> void; + template auto instructionBCHG(DataRegister bit, EffectiveAddress with) -> void; + template auto instructionBCHG(EffectiveAddress with) -> void; + template auto instructionBCLR(DataRegister bit, EffectiveAddress with) -> void; + template auto instructionBCLR(EffectiveAddress with) -> void; + auto instructionBRA(n8 displacement) -> void; + template auto instructionBSET(DataRegister bit, EffectiveAddress with) -> void; + template auto instructionBSET(EffectiveAddress with) -> void; + auto instructionBSR(n8 displacement) -> void; + template auto instructionBTST(DataRegister bit, EffectiveAddress with) -> void; + template auto instructionBTST(EffectiveAddress with) -> void; + auto instructionCHK(DataRegister compare, EffectiveAddress maximum) -> void; + template auto instructionCLR(EffectiveAddress with) -> void; + template auto instructionCMP(EffectiveAddress from, DataRegister with) -> void; + template auto instructionCMPA(EffectiveAddress from, AddressRegister with) -> void; + template auto instructionCMPI(EffectiveAddress with) -> void; + template auto instructionCMPM(EffectiveAddress from, EffectiveAddress with) -> void; + auto instructionDBCC(n4 condition, DataRegister with) -> void; + auto instructionDIVS(EffectiveAddress from, DataRegister with) -> void; + auto instructionDIVU(EffectiveAddress from, DataRegister with) -> void; + template auto instructionEOR(DataRegister from, EffectiveAddress with) -> void; + template auto instructionEORI(EffectiveAddress with) -> void; + auto instructionEORI_TO_CCR() -> void; + auto instructionEORI_TO_SR() -> void; + auto instructionEXG(DataRegister x, DataRegister y) -> void; + auto instructionEXG(AddressRegister x, AddressRegister y) -> void; + auto instructionEXG(DataRegister x, AddressRegister y) -> void; + template auto instructionEXT(DataRegister with) -> void; + auto instructionILLEGAL(n16 code) -> void; + auto instructionJMP(EffectiveAddress from) -> void; + auto instructionJSR(EffectiveAddress from) -> void; + auto instructionLEA(EffectiveAddress from, AddressRegister to) -> void; + auto instructionLINK(AddressRegister with) -> void; + template auto instructionLSL(n4 count, DataRegister with) -> void; + template auto instructionLSL(DataRegister from, DataRegister with) -> void; + auto instructionLSL(EffectiveAddress with) -> void; + template auto instructionLSR(n4 count, DataRegister with) -> void; + template auto instructionLSR(DataRegister from, DataRegister with) -> void; + auto instructionLSR(EffectiveAddress with) -> void; + template auto instructionMOVE(EffectiveAddress from, EffectiveAddress to) -> void; + template auto instructionMOVEA(EffectiveAddress from, AddressRegister to) -> void; + template auto instructionMOVEM_TO_MEM(EffectiveAddress to) -> void; + template auto instructionMOVEM_TO_REG(EffectiveAddress from) -> void; + template auto instructionMOVEP(DataRegister from, EffectiveAddress to) -> void; + template auto instructionMOVEP(EffectiveAddress from, DataRegister to) -> void; + auto instructionMOVEQ(n8 immediate, DataRegister to) -> void; + auto instructionMOVE_FROM_SR(EffectiveAddress to) -> void; + auto instructionMOVE_TO_CCR(EffectiveAddress from) -> void; + auto instructionMOVE_TO_SR(EffectiveAddress from) -> void; + auto instructionMOVE_FROM_USP(AddressRegister to) -> void; + auto instructionMOVE_TO_USP(AddressRegister from) -> void; + auto instructionMULS(EffectiveAddress from, DataRegister with) -> void; + auto instructionMULU(EffectiveAddress from, DataRegister with) -> void; + auto instructionNBCD(EffectiveAddress with) -> void; + template auto instructionNEG(EffectiveAddress with) -> void; + template auto instructionNEGX(EffectiveAddress with) -> void; + auto instructionNOP() -> void; + template auto instructionNOT(EffectiveAddress with) -> void; + template auto instructionOR(EffectiveAddress from, DataRegister with) -> void; + template auto instructionOR(DataRegister from, EffectiveAddress with) -> void; + template auto instructionORI(EffectiveAddress with) -> void; + auto instructionORI_TO_CCR() -> void; + auto instructionORI_TO_SR() -> void; + auto instructionPEA(EffectiveAddress from) -> void; + auto instructionRESET() -> void; + template auto instructionROL(n4 count, DataRegister with) -> void; + template auto instructionROL(DataRegister from, DataRegister with) -> void; + auto instructionROL(EffectiveAddress with) -> void; + template auto instructionROR(n4 count, DataRegister with) -> void; + template auto instructionROR(DataRegister from, DataRegister with) -> void; + auto instructionROR(EffectiveAddress with) -> void; + template auto instructionROXL(n4 count, DataRegister with) -> void; + template auto instructionROXL(DataRegister from, DataRegister with) -> void; + auto instructionROXL(EffectiveAddress with) -> void; + template auto instructionROXR(n4 count, DataRegister with) -> void; + template auto instructionROXR(DataRegister from, DataRegister with) -> void; + auto instructionROXR(EffectiveAddress with) -> void; + auto instructionRTE() -> void; + auto instructionRTR() -> void; + auto instructionRTS() -> void; + auto instructionSBCD(EffectiveAddress with, EffectiveAddress from) -> void; + auto instructionSCC(n4 test, EffectiveAddress to) -> void; + auto instructionSTOP() -> void; + template auto instructionSUB(EffectiveAddress from, DataRegister with) -> void; + template auto instructionSUB(DataRegister from, EffectiveAddress with) -> void; + template auto instructionSUBA(EffectiveAddress from, AddressRegister with) -> void; + template auto instructionSUBI(EffectiveAddress with) -> void; + template auto instructionSUBQ(n4 immediate, EffectiveAddress with) -> void; + template auto instructionSUBQ(n4 immediate, AddressRegister with) -> void; + template auto instructionSUBX(EffectiveAddress from, EffectiveAddress with) -> void; + auto instructionSWAP(DataRegister with) -> void; + auto instructionTAS(EffectiveAddress with) -> void; + auto instructionTRAP(n4 vector) -> void; + auto instructionTRAPV() -> void; + template auto instructionTST(EffectiveAddress from) -> void; + auto instructionUNLK(AddressRegister with) -> void; //serialization.cpp auto serialize(serializer&) -> void; //disassembler.cpp - auto disassembleInstruction(uint32 pc) -> string; + auto disassembleInstruction(n32 pc) -> string; auto disassembleContext() -> string; struct Registers { - uint32 d[8]; //data registers - uint32 a[8]; //address registers (a7 = s ? ssp : usp) - uint32 sp; //inactive stack pointer (s ? usp : ssp) - uint32 pc; //program counter - - bool c; //carry - bool v; //overflow - bool z; //zero - bool n; //negative - bool x; //extend - uint3 i; //interrupt mask - bool s; //supervisor mode - bool t; //trace mode - - uint16 irc; //instruction prefetched from external memory - uint16 ir; //instruction currently being decoded - uint16 ird; //instruction currently being executed + n32 d[8]; //data registers + n32 a[8]; //address registers (a7 = s ? ssp : usp) + n32 sp; //inactive stack pointer (s ? usp : ssp) + n32 pc; //program counter + + bool c; //carry + bool v; //overflow + bool z; //zero + bool n; //negative + bool x; //extend + n3 i; //interrupt mask + bool s; //supervisor mode + bool t; //trace mode + + n16 irc; //instruction prefetched from external memory + n16 ir; //instruction currently being decoded + n16 ird; //instruction currently being executed bool stop; bool reset; @@ -298,136 +298,136 @@ struct M68K { private: //disassembler.cpp - auto disassembleABCD(EffectiveAddress from, EffectiveAddress with) -> string; - template auto disassembleADD(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleADD(DataRegister from, EffectiveAddress with) -> string; - template auto disassembleADDA(EffectiveAddress from, AddressRegister with) -> string; - template auto disassembleADDI(EffectiveAddress with) -> string; - template auto disassembleADDQ(uint4 immediate, EffectiveAddress with) -> string; - template auto disassembleADDQ(uint4 immediate, AddressRegister with) -> string; - template auto disassembleADDX(EffectiveAddress from, EffectiveAddress with) -> string; - template auto disassembleAND(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleAND(DataRegister from, EffectiveAddress with) -> string; - template auto disassembleANDI(EffectiveAddress with) -> string; - auto disassembleANDI_TO_CCR() -> string; - auto disassembleANDI_TO_SR() -> string; - template auto disassembleASL(uint4 count, DataRegister with) -> string; - template auto disassembleASL(DataRegister from, DataRegister with) -> string; - auto disassembleASL(EffectiveAddress with) -> string; - template auto disassembleASR(uint4 count, DataRegister with) -> string; - template auto disassembleASR(DataRegister from, DataRegister with) -> string; - auto disassembleASR(EffectiveAddress with) -> string; - auto disassembleBCC(uint4 condition, uint8 displacement) -> string; - template auto disassembleBCHG(DataRegister bit, EffectiveAddress with) -> string; - template auto disassembleBCHG(EffectiveAddress with) -> string; - template auto disassembleBCLR(DataRegister bit, EffectiveAddress with) -> string; - template auto disassembleBCLR(EffectiveAddress with) -> string; - auto disassembleBRA(uint8 displacement) -> string; - template auto disassembleBSET(DataRegister bit, EffectiveAddress with) -> string; - template auto disassembleBSET(EffectiveAddress with) -> string; - auto disassembleBSR(uint8 displacement) -> string; - template auto disassembleBTST(DataRegister bit, EffectiveAddress with) -> string; - template auto disassembleBTST(EffectiveAddress with) -> string; - auto disassembleCHK(DataRegister compare, EffectiveAddress maximum) -> string; - template auto disassembleCLR(EffectiveAddress with) -> string; - template auto disassembleCMP(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleCMPA(EffectiveAddress from, AddressRegister with) -> string; - template auto disassembleCMPI(EffectiveAddress with) -> string; - template auto disassembleCMPM(EffectiveAddress from, EffectiveAddress with) -> string; - auto disassembleDBCC(uint4 test, DataRegister with) -> string; - auto disassembleDIVS(EffectiveAddress from, DataRegister with) -> string; - auto disassembleDIVU(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleEOR(DataRegister from, EffectiveAddress with) -> string; - template auto disassembleEORI(EffectiveAddress with) -> string; - auto disassembleEORI_TO_CCR() -> string; - auto disassembleEORI_TO_SR() -> string; - auto disassembleEXG(DataRegister x, DataRegister y) -> string; - auto disassembleEXG(AddressRegister x, AddressRegister y) -> string; - auto disassembleEXG(DataRegister x, AddressRegister y) -> string; - template auto disassembleEXT(DataRegister with) -> string; - auto disassembleILLEGAL(uint16 code) -> string; - auto disassembleJMP(EffectiveAddress from) -> string; - auto disassembleJSR(EffectiveAddress from) -> string; - auto disassembleLEA(EffectiveAddress from, AddressRegister to) -> string; - auto disassembleLINK(AddressRegister with) -> string; - template auto disassembleLSL(uint4 count, DataRegister with) -> string; - template auto disassembleLSL(DataRegister from, DataRegister with) -> string; - auto disassembleLSL(EffectiveAddress with) -> string; - template auto disassembleLSR(uint4 count, DataRegister with) -> string; - template auto disassembleLSR(DataRegister from, DataRegister with) -> string; - auto disassembleLSR(EffectiveAddress with) -> string; - template auto disassembleMOVE(EffectiveAddress from, EffectiveAddress to) -> string; - template auto disassembleMOVEA(EffectiveAddress from, AddressRegister to) -> string; - template auto disassembleMOVEM_TO_MEM(EffectiveAddress to) -> string; - template auto disassembleMOVEM_TO_REG(EffectiveAddress from) -> string; - template auto disassembleMOVEP(DataRegister from, EffectiveAddress to) -> string; - template auto disassembleMOVEP(EffectiveAddress from, DataRegister to) -> string; - auto disassembleMOVEQ(uint8 immediate, DataRegister to) -> string; - auto disassembleMOVE_FROM_SR(EffectiveAddress to) -> string; - auto disassembleMOVE_TO_CCR(EffectiveAddress from) -> string; - auto disassembleMOVE_TO_SR(EffectiveAddress from) -> string; - auto disassembleMOVE_FROM_USP(AddressRegister to) -> string; - auto disassembleMOVE_TO_USP(AddressRegister from) -> string; - auto disassembleMULS(EffectiveAddress from, DataRegister with) -> string; - auto disassembleMULU(EffectiveAddress from, DataRegister with) -> string; - auto disassembleNBCD(EffectiveAddress with) -> string; - template auto disassembleNEG(EffectiveAddress with) -> string; - template auto disassembleNEGX(EffectiveAddress with) -> string; - auto disassembleNOP() -> string; - template auto disassembleNOT(EffectiveAddress with) -> string; - template auto disassembleOR(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleOR(DataRegister from, EffectiveAddress with) -> string; - template auto disassembleORI(EffectiveAddress with) -> string; - auto disassembleORI_TO_CCR() -> string; - auto disassembleORI_TO_SR() -> string; - auto disassemblePEA(EffectiveAddress from) -> string; - auto disassembleRESET() -> string; - template auto disassembleROL(uint4 count, DataRegister with) -> string; - template auto disassembleROL(DataRegister from, DataRegister with) -> string; - auto disassembleROL(EffectiveAddress with) -> string; - template auto disassembleROR(uint4 count, DataRegister with) -> string; - template auto disassembleROR(DataRegister from, DataRegister with) -> string; - auto disassembleROR(EffectiveAddress with) -> string; - template auto disassembleROXL(uint4 count, DataRegister with) -> string; - template auto disassembleROXL(DataRegister from, DataRegister with) -> string; - auto disassembleROXL(EffectiveAddress with) -> string; - template auto disassembleROXR(uint4 count, DataRegister with) -> string; - template auto disassembleROXR(DataRegister from, DataRegister with) -> string; - auto disassembleROXR(EffectiveAddress with) -> string; - auto disassembleRTE() -> string; - auto disassembleRTR() -> string; - auto disassembleRTS() -> string; - auto disassembleSBCD(EffectiveAddress with, EffectiveAddress from) -> string; - auto disassembleSCC(uint4 test, EffectiveAddress to) -> string; - auto disassembleSTOP() -> string; - template auto disassembleSUB(EffectiveAddress from, DataRegister with) -> string; - template auto disassembleSUB(DataRegister from, EffectiveAddress with) -> string; - template auto disassembleSUBA(EffectiveAddress from, AddressRegister with) -> string; - template auto disassembleSUBI(EffectiveAddress with) -> string; - template auto disassembleSUBQ(uint4 immediate, EffectiveAddress with) -> string; - template auto disassembleSUBQ(uint4 immediate, AddressRegister with) -> string; - template auto disassembleSUBX(EffectiveAddress from, EffectiveAddress with) -> string; - auto disassembleSWAP(DataRegister with) -> string; - auto disassembleTAS(EffectiveAddress with) -> string; - auto disassembleTRAP(uint4 vector) -> string; - auto disassembleTRAPV() -> string; - template auto disassembleTST(EffectiveAddress from) -> string; - auto disassembleUNLK(AddressRegister with) -> string; - - template auto _read(uint32 addr) -> uint32; - template auto _readPC() -> uint32; - auto _readDisplacement(uint32 base) -> uint32; - auto _readIndex(uint32 base) -> uint32; + auto disassembleABCD(EffectiveAddress from, EffectiveAddress with) -> string; + template auto disassembleADD(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleADD(DataRegister from, EffectiveAddress with) -> string; + template auto disassembleADDA(EffectiveAddress from, AddressRegister with) -> string; + template auto disassembleADDI(EffectiveAddress with) -> string; + template auto disassembleADDQ(n4 immediate, EffectiveAddress with) -> string; + template auto disassembleADDQ(n4 immediate, AddressRegister with) -> string; + template auto disassembleADDX(EffectiveAddress from, EffectiveAddress with) -> string; + template auto disassembleAND(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleAND(DataRegister from, EffectiveAddress with) -> string; + template auto disassembleANDI(EffectiveAddress with) -> string; + auto disassembleANDI_TO_CCR() -> string; + auto disassembleANDI_TO_SR() -> string; + template auto disassembleASL(n4 count, DataRegister with) -> string; + template auto disassembleASL(DataRegister from, DataRegister with) -> string; + auto disassembleASL(EffectiveAddress with) -> string; + template auto disassembleASR(n4 count, DataRegister with) -> string; + template auto disassembleASR(DataRegister from, DataRegister with) -> string; + auto disassembleASR(EffectiveAddress with) -> string; + auto disassembleBCC(n4 condition, n8 displacement) -> string; + template auto disassembleBCHG(DataRegister bit, EffectiveAddress with) -> string; + template auto disassembleBCHG(EffectiveAddress with) -> string; + template auto disassembleBCLR(DataRegister bit, EffectiveAddress with) -> string; + template auto disassembleBCLR(EffectiveAddress with) -> string; + auto disassembleBRA(n8 displacement) -> string; + template auto disassembleBSET(DataRegister bit, EffectiveAddress with) -> string; + template auto disassembleBSET(EffectiveAddress with) -> string; + auto disassembleBSR(n8 displacement) -> string; + template auto disassembleBTST(DataRegister bit, EffectiveAddress with) -> string; + template auto disassembleBTST(EffectiveAddress with) -> string; + auto disassembleCHK(DataRegister compare, EffectiveAddress maximum) -> string; + template auto disassembleCLR(EffectiveAddress with) -> string; + template auto disassembleCMP(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleCMPA(EffectiveAddress from, AddressRegister with) -> string; + template auto disassembleCMPI(EffectiveAddress with) -> string; + template auto disassembleCMPM(EffectiveAddress from, EffectiveAddress with) -> string; + auto disassembleDBCC(n4 test, DataRegister with) -> string; + auto disassembleDIVS(EffectiveAddress from, DataRegister with) -> string; + auto disassembleDIVU(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleEOR(DataRegister from, EffectiveAddress with) -> string; + template auto disassembleEORI(EffectiveAddress with) -> string; + auto disassembleEORI_TO_CCR() -> string; + auto disassembleEORI_TO_SR() -> string; + auto disassembleEXG(DataRegister x, DataRegister y) -> string; + auto disassembleEXG(AddressRegister x, AddressRegister y) -> string; + auto disassembleEXG(DataRegister x, AddressRegister y) -> string; + template auto disassembleEXT(DataRegister with) -> string; + auto disassembleILLEGAL(n16 code) -> string; + auto disassembleJMP(EffectiveAddress from) -> string; + auto disassembleJSR(EffectiveAddress from) -> string; + auto disassembleLEA(EffectiveAddress from, AddressRegister to) -> string; + auto disassembleLINK(AddressRegister with) -> string; + template auto disassembleLSL(n4 count, DataRegister with) -> string; + template auto disassembleLSL(DataRegister from, DataRegister with) -> string; + auto disassembleLSL(EffectiveAddress with) -> string; + template auto disassembleLSR(n4 count, DataRegister with) -> string; + template auto disassembleLSR(DataRegister from, DataRegister with) -> string; + auto disassembleLSR(EffectiveAddress with) -> string; + template auto disassembleMOVE(EffectiveAddress from, EffectiveAddress to) -> string; + template auto disassembleMOVEA(EffectiveAddress from, AddressRegister to) -> string; + template auto disassembleMOVEM_TO_MEM(EffectiveAddress to) -> string; + template auto disassembleMOVEM_TO_REG(EffectiveAddress from) -> string; + template auto disassembleMOVEP(DataRegister from, EffectiveAddress to) -> string; + template auto disassembleMOVEP(EffectiveAddress from, DataRegister to) -> string; + auto disassembleMOVEQ(n8 immediate, DataRegister to) -> string; + auto disassembleMOVE_FROM_SR(EffectiveAddress to) -> string; + auto disassembleMOVE_TO_CCR(EffectiveAddress from) -> string; + auto disassembleMOVE_TO_SR(EffectiveAddress from) -> string; + auto disassembleMOVE_FROM_USP(AddressRegister to) -> string; + auto disassembleMOVE_TO_USP(AddressRegister from) -> string; + auto disassembleMULS(EffectiveAddress from, DataRegister with) -> string; + auto disassembleMULU(EffectiveAddress from, DataRegister with) -> string; + auto disassembleNBCD(EffectiveAddress with) -> string; + template auto disassembleNEG(EffectiveAddress with) -> string; + template auto disassembleNEGX(EffectiveAddress with) -> string; + auto disassembleNOP() -> string; + template auto disassembleNOT(EffectiveAddress with) -> string; + template auto disassembleOR(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleOR(DataRegister from, EffectiveAddress with) -> string; + template auto disassembleORI(EffectiveAddress with) -> string; + auto disassembleORI_TO_CCR() -> string; + auto disassembleORI_TO_SR() -> string; + auto disassemblePEA(EffectiveAddress from) -> string; + auto disassembleRESET() -> string; + template auto disassembleROL(n4 count, DataRegister with) -> string; + template auto disassembleROL(DataRegister from, DataRegister with) -> string; + auto disassembleROL(EffectiveAddress with) -> string; + template auto disassembleROR(n4 count, DataRegister with) -> string; + template auto disassembleROR(DataRegister from, DataRegister with) -> string; + auto disassembleROR(EffectiveAddress with) -> string; + template auto disassembleROXL(n4 count, DataRegister with) -> string; + template auto disassembleROXL(DataRegister from, DataRegister with) -> string; + auto disassembleROXL(EffectiveAddress with) -> string; + template auto disassembleROXR(n4 count, DataRegister with) -> string; + template auto disassembleROXR(DataRegister from, DataRegister with) -> string; + auto disassembleROXR(EffectiveAddress with) -> string; + auto disassembleRTE() -> string; + auto disassembleRTR() -> string; + auto disassembleRTS() -> string; + auto disassembleSBCD(EffectiveAddress with, EffectiveAddress from) -> string; + auto disassembleSCC(n4 test, EffectiveAddress to) -> string; + auto disassembleSTOP() -> string; + template auto disassembleSUB(EffectiveAddress from, DataRegister with) -> string; + template auto disassembleSUB(DataRegister from, EffectiveAddress with) -> string; + template auto disassembleSUBA(EffectiveAddress from, AddressRegister with) -> string; + template auto disassembleSUBI(EffectiveAddress with) -> string; + template auto disassembleSUBQ(n4 immediate, EffectiveAddress with) -> string; + template auto disassembleSUBQ(n4 immediate, AddressRegister with) -> string; + template auto disassembleSUBX(EffectiveAddress from, EffectiveAddress with) -> string; + auto disassembleSWAP(DataRegister with) -> string; + auto disassembleTAS(EffectiveAddress with) -> string; + auto disassembleTRAP(n4 vector) -> string; + auto disassembleTRAPV() -> string; + template auto disassembleTST(EffectiveAddress from) -> string; + auto disassembleUNLK(AddressRegister with) -> string; + + template auto _read(n32 addr) -> n32; + template auto _readPC() -> n32; + auto _readDisplacement(n32 base) -> n32; + auto _readIndex(n32 base) -> n32; auto _dataRegister(DataRegister dr) -> string; auto _addressRegister(AddressRegister ar) -> string; - template auto _immediate() -> string; - template auto _address(EffectiveAddress& ea) -> string; - template auto _effectiveAddress(EffectiveAddress& ea) -> string; - auto _branch(uint8 displacement) -> string; - template auto _suffix() -> string; - auto _condition(uint4 condition) -> string; - - uint32 _pc; + template auto _immediate() -> string; + template auto _address(EffectiveAddress& ea) -> string; + template auto _effectiveAddress(EffectiveAddress& ea) -> string; + auto _branch(n8 displacement) -> string; + template auto _suffix() -> string; + auto _condition(n4 condition) -> string; + + n32 _pc; function disassembleTable[65536]; }; diff --git a/ares/component/processor/m68k/memory.cpp b/ares/component/processor/m68k/memory.cpp index 3a89d2f54b..f19a703e23 100644 --- a/ares/component/processor/m68k/memory.cpp +++ b/ares/component/processor/m68k/memory.cpp @@ -7,7 +7,7 @@ //* /UDS is where A0=0 and maps to D8-D15 //* /LDS is where A0=1 and maps to D0-D7 -template<> auto M68K::read(uint32 address) -> uint32 { +template<> auto M68K::read(n32 address) -> n32 { wait(4); if(address & 1) { return read(0, 1, address & ~1).byte(0); /* /LDS */ @@ -16,35 +16,35 @@ template<> auto M68K::read(uint32 address) -> uint32 { } } -template<> auto M68K::read(uint32 address) -> uint32 { +template<> auto M68K::read(n32 address) -> n32 { wait(4); return read(1, 1, address & ~1); } -template<> auto M68K::read(uint32 address) -> uint32 { +template<> auto M68K::read(n32 address) -> n32 { wait(4); - uint32 data = read(1, 1, address + 0 & ~1) << 16; + n32 data = read(1, 1, address + 0 & ~1) << 16; wait(4); return data | read(1, 1, address + 2 & ~1) << 0; } // -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); if(address & 1) { - return write(0, 1, address & ~1, data << 8 | (uint8)data << 0); /* /LDS */ + return write(0, 1, address & ~1, data << 8 | (n8)data << 0); /* /LDS */ } else { - return write(1, 0, address & ~1, data << 8 | (uint8)data << 0); /* /UDS */ + return write(1, 0, address & ~1, data << 8 | (n8)data << 0); /* /UDS */ } } -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); return write(1, 1, address & ~1, data); } -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); write(1, 1, address + 0 & ~1, data >> 16); wait(4); @@ -53,21 +53,21 @@ template<> auto M68K::write(uint32 address, uint32 data) -> void { // -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); if(address & 1) { - return write(0, 1, address & ~1, data << 8 | (uint8)data << 0); /* /LDS */ + return write(0, 1, address & ~1, data << 8 | (n8)data << 0); /* /LDS */ } else { - return write(1, 0, address & ~1, data << 8 | (uint8)data << 0); /* /UDS */ + return write(1, 0, address & ~1, data << 8 | (n8)data << 0); /* /UDS */ } } -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); return write(1, 1, address & ~1, data); } -template<> auto M68K::write(uint32 address, uint32 data) -> void { +template<> auto M68K::write(n32 address, n32 data) -> void { wait(4); write(1, 1, address + 2 & ~1, data >> 0); wait(4); @@ -76,15 +76,15 @@ template<> auto M68K::write(uint32 address, uint32 data) -> void // -template<> auto M68K::extension() -> uint32 { +template<> auto M68K::extension() -> n32 { wait(4); r.ir = r.irc; r.irc = read(1, 1, r.pc & ~1); r.pc += 2; - return (uint8)r.ir; + return (n8)r.ir; } -template<> auto M68K::extension() -> uint32 { +template<> auto M68K::extension() -> n32 { wait(4); r.ir = r.irc; r.irc = read(1, 1, r.pc & ~1); @@ -92,7 +92,7 @@ template<> auto M68K::extension() -> uint32 { return r.ir; } -template<> auto M68K::extension() -> uint32 { +template<> auto M68K::extension() -> n32 { auto hi = extension(); auto lo = extension(); return hi << 16 | lo << 0; @@ -100,7 +100,7 @@ template<> auto M68K::extension() -> uint32 { // -auto M68K::prefetch() -> uint16 { +auto M68K::prefetch() -> n16 { wait(4); r.ir = r.irc; r.irc = read(1, 1, r.pc & ~1); @@ -111,7 +111,7 @@ auto M68K::prefetch() -> uint16 { //take the prefetched value without reloading the prefetch. //this is used by instructions such as JMP and JSR. -auto M68K::prefetched() -> uint16 { +auto M68K::prefetched() -> n16 { r.ir = r.irc; r.irc = 0x0000; r.pc += 2; @@ -120,15 +120,15 @@ auto M68K::prefetched() -> uint16 { // -template auto M68K::pop() -> uint32 { - auto data = read((uint32)r.a[7]); +template auto M68K::pop() -> n32 { + auto data = read((n32)r.a[7]); r.a[7] += bytes(); return data; } // -template auto M68K::push(uint32 data) -> void { +template auto M68K::push(n32 data) -> void { r.a[7] -= bytes(); - return write((uint32)r.a[7], data); + return write((n32)r.a[7], data); } diff --git a/ares/component/processor/m68k/registers.cpp b/ares/component/processor/m68k/registers.cpp index d25c40bc11..ac5e851cc8 100644 --- a/ares/component/processor/m68k/registers.cpp +++ b/ares/component/processor/m68k/registers.cpp @@ -1,18 +1,18 @@ -template auto M68K::read(DataRegister reg) -> uint32 { +template auto M68K::read(DataRegister reg) -> n32 { return clip(r.d[reg.number]); } -template auto M68K::write(DataRegister reg, uint32 data) -> void { +template auto M68K::write(DataRegister reg, n32 data) -> void { r.d[reg.number] = (r.d[reg.number] & ~mask()) | (data & mask()); } // -template auto M68K::read(AddressRegister reg) -> uint32 { +template auto M68K::read(AddressRegister reg) -> n32 { return sign(r.a[reg.number]); } -template auto M68K::write(AddressRegister reg, uint32 data) -> void { +template auto M68K::write(AddressRegister reg, n32 data) -> void { r.a[reg.number] = sign(data); } @@ -20,15 +20,15 @@ template auto M68K::write(AddressRegister reg, uint32 data) -> void { //CCR,SR unused bits cannot be set; always read out as 0 -auto M68K::readCCR() -> uint8 { +auto M68K::readCCR() -> n8 { return r.c << 0 | r.v << 1 | r.z << 2 | r.n << 3 | r.x << 4; } -auto M68K::readSR() -> uint16 { +auto M68K::readSR() -> n16 { return readCCR() << 0 | r.i << 8 | r.s << 13 | r.t << 15; } -auto M68K::writeCCR(uint8 ccr) -> void { +auto M68K::writeCCR(n8 ccr) -> void { r.c = ccr.bit(0); r.v = ccr.bit(1); r.z = ccr.bit(2); @@ -36,7 +36,7 @@ auto M68K::writeCCR(uint8 ccr) -> void { r.x = ccr.bit(4); } -auto M68K::writeSR(uint16 sr) -> void { +auto M68K::writeSR(n16 sr) -> void { writeCCR(sr); //when entering or exiting supervisor mode; swap SSP and USP into A7 diff --git a/ares/component/processor/m68k/traits.cpp b/ares/component/processor/m68k/traits.cpp index 5d821d8f2f..d93bf356b5 100644 --- a/ares/component/processor/m68k/traits.cpp +++ b/ares/component/processor/m68k/traits.cpp @@ -1,27 +1,27 @@ -template<> auto M68K::bytes() -> uint { return 1; } -template<> auto M68K::bytes() -> uint { return 2; } -template<> auto M68K::bytes() -> uint { return 4; } +template<> auto M68K::bytes() -> u32 { return 1; } +template<> auto M68K::bytes() -> u32 { return 2; } +template<> auto M68K::bytes() -> u32 { return 4; } -template<> auto M68K::bits() -> uint { return 8; } -template<> auto M68K::bits() -> uint { return 16; } -template<> auto M68K::bits() -> uint { return 32; } +template<> auto M68K::bits() -> u32 { return 8; } +template<> auto M68K::bits() -> u32 { return 16; } +template<> auto M68K::bits() -> u32 { return 32; } -template<> auto M68K::lsb() -> uint32 { return 1; } -template<> auto M68K::lsb() -> uint32 { return 1; } -template<> auto M68K::lsb() -> uint32 { return 1; } +template<> auto M68K::lsb() -> n32 { return 1; } +template<> auto M68K::lsb() -> n32 { return 1; } +template<> auto M68K::lsb() -> n32 { return 1; } -template<> auto M68K::msb() -> uint32 { return 0x80; } -template<> auto M68K::msb() -> uint32 { return 0x8000; } -template<> auto M68K::msb() -> uint32 { return 0x80000000; } +template<> auto M68K::msb() -> n32 { return 0x80; } +template<> auto M68K::msb() -> n32 { return 0x8000; } +template<> auto M68K::msb() -> n32 { return 0x80000000; } -template<> auto M68K::mask() -> uint32 { return 0xff; } -template<> auto M68K::mask() -> uint32 { return 0xffff; } -template<> auto M68K::mask() -> uint32 { return 0xffffffff; } +template<> auto M68K::mask() -> n32 { return 0xff; } +template<> auto M68K::mask() -> n32 { return 0xffff; } +template<> auto M68K::mask() -> n32 { return 0xffffffff; } -template<> auto M68K::clip(uint32 data) -> uint32 { return (uint8)data; } -template<> auto M68K::clip(uint32 data) -> uint32 { return (uint16)data; } -template<> auto M68K::clip(uint32 data) -> uint32 { return (uint32)data; } +template<> auto M68K::clip(n32 data) -> n32 { return (n8 )data; } +template<> auto M68K::clip(n32 data) -> n32 { return (n16)data; } +template<> auto M68K::clip(n32 data) -> n32 { return (n32)data; } -template<> auto M68K::sign(uint32 data) -> int32 { return (int8)data; } -template<> auto M68K::sign(uint32 data) -> int32 { return (int16)data; } -template<> auto M68K::sign(uint32 data) -> int32 { return (int32)data; } +template<> auto M68K::sign(n32 data) -> i32 { return (i8 )data; } +template<> auto M68K::sign(n32 data) -> i32 { return (i16)data; } +template<> auto M68K::sign(n32 data) -> i32 { return (i32)data; } diff --git a/ares/component/processor/sm83/algorithms.cpp b/ares/component/processor/sm83/algorithms.cpp index d14acd219b..da081dd9b3 100644 --- a/ares/component/processor/sm83/algorithms.cpp +++ b/ares/component/processor/sm83/algorithms.cpp @@ -1,14 +1,14 @@ -auto SM83::ADD(uint8 target, uint8 source, bool carry) -> uint8 { - uint16 x = target + source + carry; - uint16 y = (uint4)target + (uint4)source + carry; +auto SM83::ADD(n8 target, n8 source, bool carry) -> n8 { + n16 x = target + source + carry; + n16 y = (n4)target + (n4)source + carry; CF = x > 0xff; HF = y > 0x0f; NF = 0; - ZF = (uint8)x == 0; + ZF = (n8)x == 0; return x; } -auto SM83::AND(uint8 target, uint8 source) -> uint8 { +auto SM83::AND(n8 target, n8 source) -> n8 { target &= source; CF = 0; HF = 1; @@ -17,45 +17,45 @@ auto SM83::AND(uint8 target, uint8 source) -> uint8 { return target; } -auto SM83::BIT(uint3 index, uint8 target) -> void { +auto SM83::BIT(n3 index, n8 target) -> void { HF = 1; NF = 0; ZF = target.bit(index) == 0; } -auto SM83::CP(uint8 target, uint8 source) -> void { - uint16 x = target - source; - uint16 y = (uint4)target - (uint4)source; +auto SM83::CP(n8 target, n8 source) -> void { + n16 x = target - source; + n16 y = (n4)target - (n4)source; CF = x > 0xff; HF = y > 0x0f; NF = 1; - ZF = (uint8)x == 0; + ZF = (n8)x == 0; } -auto SM83::DEC(uint8 target) -> uint8 { +auto SM83::DEC(n8 target) -> n8 { target--; - HF = (uint4)target == 0x0f; + HF = (n4)target == 0x0f; NF = 1; ZF = target == 0; return target; } -auto SM83::INC(uint8 target) -> uint8 { +auto SM83::INC(n8 target) -> n8 { target++; - HF = (uint4)target == 0x00; + HF = (n4)target == 0x00; NF = 0; ZF = target == 0; return target; } -auto SM83::OR(uint8 target, uint8 source) -> uint8 { +auto SM83::OR(n8 target, n8 source) -> n8 { target |= source; CF = HF = NF = 0; ZF = target == 0; return target; } -auto SM83::RL(uint8 target) -> uint8 { +auto SM83::RL(n8 target) -> n8 { bool carry = target.bit(7); target = target << 1 | CF; CF = carry; @@ -64,7 +64,7 @@ auto SM83::RL(uint8 target) -> uint8 { return target; } -auto SM83::RLC(uint8 target) -> uint8 { +auto SM83::RLC(n8 target) -> n8 { target = target << 1 | target >> 7; CF = target.bit(0); HF = NF = 0; @@ -72,7 +72,7 @@ auto SM83::RLC(uint8 target) -> uint8 { return target; } -auto SM83::RR(uint8 target) -> uint8 { +auto SM83::RR(n8 target) -> n8 { bool carry = target.bit(0); target = CF << 7 | target >> 1; CF = carry; @@ -81,7 +81,7 @@ auto SM83::RR(uint8 target) -> uint8 { return target; } -auto SM83::RRC(uint8 target) -> uint8 { +auto SM83::RRC(n8 target) -> n8 { target = target << 7 | target >> 1; CF = target.bit(7); HF = NF = 0; @@ -89,7 +89,7 @@ auto SM83::RRC(uint8 target) -> uint8 { return target; } -auto SM83::SLA(uint8 target) -> uint8 { +auto SM83::SLA(n8 target) -> n8 { bool carry = target.bit(7); target <<= 1; CF = carry; @@ -98,16 +98,16 @@ auto SM83::SLA(uint8 target) -> uint8 { return target; } -auto SM83::SRA(uint8 target) -> uint8 { +auto SM83::SRA(n8 target) -> n8 { bool carry = target.bit(0); - target = (int8)target >> 1; + target = (i8)target >> 1; CF = carry; HF = NF = 0; ZF = target == 0; return target; } -auto SM83::SRL(uint8 target) -> uint8 { +auto SM83::SRL(n8 target) -> n8 { bool carry = target.bit(0); target >>= 1; CF = carry; @@ -116,24 +116,24 @@ auto SM83::SRL(uint8 target) -> uint8 { return target; } -auto SM83::SUB(uint8 target, uint8 source, bool carry) -> uint8 { - uint16 x = target - source - carry; - uint16 y = (uint4)target - (uint4)source - carry; +auto SM83::SUB(n8 target, n8 source, bool carry) -> n8 { + n16 x = target - source - carry; + n16 y = (n4)target - (n4)source - carry; CF = x > 0xff; HF = y > 0x0f; NF = 1; - ZF = (uint8)x == 0; + ZF = (n8)x == 0; return x; } -auto SM83::SWAP(uint8 target) -> uint8 { +auto SM83::SWAP(n8 target) -> n8 { target = target << 4 | target >> 4; CF = HF = NF = 0; ZF = target == 0; return target; } -auto SM83::XOR(uint8 target, uint8 source) -> uint8 { +auto SM83::XOR(n8 target, n8 source) -> n8 { target ^= source; CF = HF = NF = 0; ZF = target == 0; diff --git a/ares/component/processor/sm83/disassembler.cpp b/ares/component/processor/sm83/disassembler.cpp index e968a27998..cfd4ba972e 100644 --- a/ares/component/processor/sm83/disassembler.cpp +++ b/ares/component/processor/sm83/disassembler.cpp @@ -1,4 +1,4 @@ -auto SM83::disassembleInstruction(maybe _pc) -> string { +auto SM83::disassembleInstruction(maybe _pc) -> string { auto pc = _pc ? *_pc : PC; return pad(disassembleOpcode(pc), -16, ' '); } @@ -13,7 +13,7 @@ auto SM83::disassembleContext() -> string { }; } -auto SM83::disassembleOpcode(uint16 pc) -> string { +auto SM83::disassembleOpcode(n16 pc) -> string { auto opcode = readDebugger(pc); auto lo = readDebugger(pc + 1); auto hi = readDebugger(pc + 2); @@ -44,7 +44,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0x15: return {"dec d"}; case 0x16: return {"ld d,$", hex(lo, 2L)}; case 0x17: return {"rla"}; - case 0x18: return {"jr $", hex(pc + 2 + (int8)lo, 4L)}; + case 0x18: return {"jr $", hex(pc + 2 + (i8)lo, 4L)}; case 0x19: return {"add hl,de"}; case 0x1a: return {"ld a,(de)"}; case 0x1b: return {"dec de"}; @@ -52,7 +52,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0x1d: return {"dec e"}; case 0x1e: return {"ld e,$", hex(lo, 2L)}; case 0x1f: return {"rra"}; - case 0x20: return {"jr nz,$", hex(pc + 2 + (int8)lo, 4L)}; + case 0x20: return {"jr nz,$", hex(pc + 2 + (i8)lo, 4L)}; case 0x21: return {"ld hl,$", hex(word, 4L)}; case 0x22: return {"ldi (hl),a"}; case 0x23: return {"inc hl"}; @@ -60,7 +60,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0x25: return {"dec h"}; case 0x26: return {"ld h,$", hex(lo, 2L)}; case 0x27: return {"daa"}; - case 0x28: return {"jr z,$", hex(pc + 2 + (int8)lo, 4L)}; + case 0x28: return {"jr z,$", hex(pc + 2 + (i8)lo, 4L)}; case 0x29: return {"add hl,hl"}; case 0x2a: return {"ldi a,(hl)"}; case 0x2b: return {"dec hl"}; @@ -68,7 +68,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0x2d: return {"dec l"}; case 0x2e: return {"ld l,$", hex(lo, 2L)}; case 0x2f: return {"cpl"}; - case 0x30: return {"jr nc,$", hex(pc + 2 + (int8)lo, 4L)}; + case 0x30: return {"jr nc,$", hex(pc + 2 + (i8)lo, 4L)}; case 0x31: return {"ld sp,$", hex(word, 4L)}; case 0x32: return {"ldd (hl),a"}; case 0x33: return {"inc sp"}; @@ -76,7 +76,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0x35: return {"dec (hl)"}; case 0x36: return {"ld (hl),$", hex(lo, 2L)}; case 0x37: return {"scf"}; - case 0x38: return {"jr c,$", hex(pc + 2 + (int8)lo, 4L)}; + case 0x38: return {"jr c,$", hex(pc + 2 + (i8)lo, 4L)}; case 0x39: return {"add hl,sp"}; case 0x3a: return {"ldd a,(hl)"}; case 0x3b: return {"dec sp"}; @@ -247,7 +247,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0xe5: return {"push hl"}; case 0xe6: return {"and a,$", hex(lo, 2L)}; case 0xe7: return {"rst $0020"}; - case 0xe8: return {"add sp,$", hex((int8)lo, 4L)}; + case 0xe8: return {"add sp,$", hex((i8)lo, 4L)}; case 0xe9: return {"jp hl"}; case 0xea: return {"ld ($", hex(word, 4L), "),a"}; case 0xee: return {"xor a,$", hex(lo, 2L)}; @@ -259,7 +259,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { case 0xf5: return {"push af"}; case 0xf6: return {"or a,$", hex(lo, 2L)}; case 0xf7: return {"rst $0030"}; - case 0xf8: return {"ld hl,sp+$", hex((int8)lo, 4L)}; + case 0xf8: return {"ld hl,sp+$", hex((i8)lo, 4L)}; case 0xf9: return {"ld sp,hl"}; case 0xfa: return {"ld a,($", hex(word, 4L), ")"}; case 0xfb: return {"ei"}; @@ -270,7 +270,7 @@ auto SM83::disassembleOpcode(uint16 pc) -> string { return {"xx"}; } -auto SM83::disassembleOpcodeCB(uint16 pc) -> string { +auto SM83::disassembleOpcodeCB(n16 pc) -> string { auto opcode = readDebugger(pc); switch(opcode) { diff --git a/ares/component/processor/sm83/instruction.cpp b/ares/component/processor/sm83/instruction.cpp index 93e8457ba1..64e5ff208c 100644 --- a/ares/component/processor/sm83/instruction.cpp +++ b/ares/component/processor/sm83/instruction.cpp @@ -323,7 +323,7 @@ auto SM83::instructionCB() -> void { } //opcodes 0x40-0xff [op(0x00 - 0x07) declared above] - uint3 bit = opcode.bit(3,5); + n3 bit = opcode.bit(3,5); switch(opcode.bit(6,7) << 3 | opcode.bit(0,2)) { op(0x08, BIT_Index_Direct, bit, B) op(0x09, BIT_Index_Direct, bit, C) diff --git a/ares/component/processor/sm83/instructions.cpp b/ares/component/processor/sm83/instructions.cpp index a6de8445c2..9538bbf912 100644 --- a/ares/component/processor/sm83/instructions.cpp +++ b/ares/component/processor/sm83/instructions.cpp @@ -1,64 +1,64 @@ -auto SM83::instructionADC_Direct_Data(uint8& target) -> void { +auto SM83::instructionADC_Direct_Data(n8& target) -> void { target = ADD(target, operand(), CF); } -auto SM83::instructionADC_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionADC_Direct_Direct(n8& target, n8& source) -> void { target = ADD(target, source, CF); } -auto SM83::instructionADC_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionADC_Direct_Indirect(n8& target, n16& source) -> void { target = ADD(target, read(source), CF); } -auto SM83::instructionADD_Direct_Data(uint8& target) -> void { +auto SM83::instructionADD_Direct_Data(n8& target) -> void { target = ADD(target, operand()); } -auto SM83::instructionADD_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionADD_Direct_Direct(n8& target, n8& source) -> void { target = ADD(target, source); } -auto SM83::instructionADD_Direct_Direct(uint16& target, uint16& source) -> void { +auto SM83::instructionADD_Direct_Direct(n16& target, n16& source) -> void { idle(); - uint32 x = target + source; - uint32 y = (uint12)target + (uint12)source; + n32 x = target + source; + n32 y = (n12)target + (n12)source; target = x; CF = x > 0xffff; HF = y > 0x0fff; NF = 0; } -auto SM83::instructionADD_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionADD_Direct_Indirect(n8& target, n16& source) -> void { target = ADD(target, read(source)); } -auto SM83::instructionADD_Direct_Relative(uint16& target) -> void { +auto SM83::instructionADD_Direct_Relative(n16& target) -> void { auto data = operand(); idle(); idle(); - CF = (uint8)target + (uint8)data > 0xff; - HF = (uint4)target + (uint4)data > 0x0f; + CF = (n8)target + (n8)data > 0xff; + HF = (n4)target + (n4)data > 0x0f; NF = ZF = 0; - target += (int8)data; + target += (i8)data; } -auto SM83::instructionAND_Direct_Data(uint8& target) -> void { +auto SM83::instructionAND_Direct_Data(n8& target) -> void { target = AND(target, operand()); } -auto SM83::instructionAND_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionAND_Direct_Direct(n8& target, n8& source) -> void { target = AND(target, source); } -auto SM83::instructionAND_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionAND_Direct_Indirect(n8& target, n16& source) -> void { target = AND(target, read(source)); } -auto SM83::instructionBIT_Index_Direct(uint3 index, uint8& data) -> void { +auto SM83::instructionBIT_Index_Direct(n3 index, n8& data) -> void { BIT(index, data); } -auto SM83::instructionBIT_Index_Indirect(uint3 index, uint16& address) -> void { +auto SM83::instructionBIT_Index_Indirect(n3 index, n16& address) -> void { auto data = read(address); BIT(index, data); } @@ -76,15 +76,15 @@ auto SM83::instructionCCF() -> void { HF = NF = 0; } -auto SM83::instructionCP_Direct_Data(uint8& target) -> void { +auto SM83::instructionCP_Direct_Data(n8& target) -> void { CP(target, operand()); } -auto SM83::instructionCP_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionCP_Direct_Direct(n8& target, n8& source) -> void { CP(target, source); } -auto SM83::instructionCP_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionCP_Direct_Indirect(n8& target, n16& source) -> void { CP(target, read(source)); } @@ -94,10 +94,10 @@ auto SM83::instructionCPL() -> void { } auto SM83::instructionDAA() -> void { - uint16 a = A; + n16 a = A; if(!NF) { - if(HF || (uint4)a > 0x09) a += 0x06; - if(CF || (uint8)a > 0x9f) a += 0x60; + if(HF || (n4)a > 0x09) a += 0x06; + if(CF || (n8)a > 0x9f) a += 0x60; } else { if(HF) { a -= 0x06; @@ -111,16 +111,16 @@ auto SM83::instructionDAA() -> void { ZF = A == 0; } -auto SM83::instructionDEC_Direct(uint8& data) -> void { +auto SM83::instructionDEC_Direct(n8& data) -> void { data = DEC(data); } -auto SM83::instructionDEC_Direct(uint16& data) -> void { +auto SM83::instructionDEC_Direct(n16& data) -> void { idle(); data--; } -auto SM83::instructionDEC_Indirect(uint16& address) -> void { +auto SM83::instructionDEC_Indirect(n16& address) -> void { auto data = read(address); write(address, DEC(data)); } @@ -138,16 +138,16 @@ auto SM83::instructionHALT() -> void { while(r.halt) halt(); } -auto SM83::instructionINC_Direct(uint8& data) -> void { +auto SM83::instructionINC_Direct(n8& data) -> void { data = INC(data); } -auto SM83::instructionINC_Direct(uint16& data) -> void { +auto SM83::instructionINC_Direct(n16& data) -> void { idle(); data++; } -auto SM83::instructionINC_Indirect(uint16& address) -> void { +auto SM83::instructionINC_Indirect(n16& address) -> void { auto data = read(address); write(address, INC(data)); } @@ -159,7 +159,7 @@ auto SM83::instructionJP_Condition_Address(bool take) -> void { PC = address; } -auto SM83::instructionJP_Direct(uint16& data) -> void { +auto SM83::instructionJP_Direct(n16& data) -> void { PC = data; } @@ -167,124 +167,124 @@ auto SM83::instructionJR_Condition_Relative(bool take) -> void { auto data = operand(); if(!take) return; idle(); - PC += (int8)data; + PC += (i8)data; } -auto SM83::instructionLD_Address_Direct(uint8& data) -> void { +auto SM83::instructionLD_Address_Direct(n8& data) -> void { write(operands(), data); } -auto SM83::instructionLD_Address_Direct(uint16& data) -> void { +auto SM83::instructionLD_Address_Direct(n16& data) -> void { store(operands(), data); } -auto SM83::instructionLD_Direct_Address(uint8& data) -> void { +auto SM83::instructionLD_Direct_Address(n8& data) -> void { data = read(operands()); } -auto SM83::instructionLD_Direct_Data(uint8& target) -> void { +auto SM83::instructionLD_Direct_Data(n8& target) -> void { target = operand(); } -auto SM83::instructionLD_Direct_Data(uint16& target) -> void { +auto SM83::instructionLD_Direct_Data(n16& target) -> void { target = operands(); } -auto SM83::instructionLD_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionLD_Direct_Direct(n8& target, n8& source) -> void { target = source; } -auto SM83::instructionLD_Direct_Direct(uint16& target, uint16& source) -> void { +auto SM83::instructionLD_Direct_Direct(n16& target, n16& source) -> void { idle(); target = source; } -auto SM83::instructionLD_Direct_DirectRelative(uint16& target, uint16& source) -> void { +auto SM83::instructionLD_Direct_DirectRelative(n16& target, n16& source) -> void { auto data = operand(); idle(); - CF = (uint8)source + (uint8)data > 0xff; - HF = (uint4)source + (uint4)data > 0x0f; + CF = (n8)source + (n8)data > 0xff; + HF = (n4)source + (n4)data > 0x0f; NF = ZF = 0; - target = source + (int8)data; + target = source + (i8)data; } -auto SM83::instructionLD_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionLD_Direct_Indirect(n8& target, n16& source) -> void { target = read(source); } -auto SM83::instructionLD_Direct_IndirectDecrement(uint8& target, uint16& source) -> void { +auto SM83::instructionLD_Direct_IndirectDecrement(n8& target, n16& source) -> void { target = read(source--); } -auto SM83::instructionLD_Direct_IndirectIncrement(uint8& target, uint16& source) -> void { +auto SM83::instructionLD_Direct_IndirectIncrement(n8& target, n16& source) -> void { target = read(source++); } -auto SM83::instructionLD_Indirect_Data(uint16& target) -> void { +auto SM83::instructionLD_Indirect_Data(n16& target) -> void { write(target, operand()); } -auto SM83::instructionLD_Indirect_Direct(uint16& target, uint8& source) -> void { +auto SM83::instructionLD_Indirect_Direct(n16& target, n8& source) -> void { write(target, source); } -auto SM83::instructionLD_IndirectDecrement_Direct(uint16& target, uint8& source) -> void { +auto SM83::instructionLD_IndirectDecrement_Direct(n16& target, n8& source) -> void { write(target--, source); } -auto SM83::instructionLD_IndirectIncrement_Direct(uint16& target, uint8& source) -> void { +auto SM83::instructionLD_IndirectIncrement_Direct(n16& target, n8& source) -> void { write(target++, source); } -auto SM83::instructionLDH_Address_Direct(uint8& data) -> void { +auto SM83::instructionLDH_Address_Direct(n8& data) -> void { write(0xff00 | operand(), data); } -auto SM83::instructionLDH_Direct_Address(uint8& data) -> void { +auto SM83::instructionLDH_Direct_Address(n8& data) -> void { data = read(0xff00 | operand()); } -auto SM83::instructionLDH_Direct_Indirect(uint8& target, uint8& source) -> void { +auto SM83::instructionLDH_Direct_Indirect(n8& target, n8& source) -> void { target = read(0xff00 | source); } -auto SM83::instructionLDH_Indirect_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionLDH_Indirect_Direct(n8& target, n8& source) -> void { write(0xff00 | target, source); } auto SM83::instructionNOP() -> void { } -auto SM83::instructionOR_Direct_Data(uint8& target) -> void { +auto SM83::instructionOR_Direct_Data(n8& target) -> void { target = OR(target, operand()); } -auto SM83::instructionOR_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionOR_Direct_Direct(n8& target, n8& source) -> void { target = OR(target, source); } -auto SM83::instructionOR_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionOR_Direct_Indirect(n8& target, n16& source) -> void { target = OR(target, read(source)); } -auto SM83::instructionPOP_Direct(uint16& data) -> void { +auto SM83::instructionPOP_Direct(n16& data) -> void { data = pop(); } -auto SM83::instructionPOP_Direct_AF(uint16& data) -> void { +auto SM83::instructionPOP_Direct_AF(n16& data) -> void { data = pop() & ~15; //flag bits 0-3 are forced to zero } -auto SM83::instructionPUSH_Direct(uint16& data) -> void { +auto SM83::instructionPUSH_Direct(n16& data) -> void { idle(); push(data); } -auto SM83::instructionRES_Index_Direct(uint3 index, uint8& data) -> void { +auto SM83::instructionRES_Index_Direct(n3 index, n8& data) -> void { data.bit(index) = 0; } -auto SM83::instructionRES_Index_Indirect(uint3 index, uint16& address) -> void { +auto SM83::instructionRES_Index_Indirect(n3 index, n16& address) -> void { auto data = read(address); data.bit(index) = 0; write(address, data); @@ -310,11 +310,11 @@ auto SM83::instructionRETI() -> void { r.ime = 1; } -auto SM83::instructionRL_Direct(uint8& data) -> void { +auto SM83::instructionRL_Direct(n8& data) -> void { data = RL(data); } -auto SM83::instructionRL_Indirect(uint16& address) -> void { +auto SM83::instructionRL_Indirect(n16& address) -> void { auto data = read(address); write(address, RL(data)); } @@ -324,11 +324,11 @@ auto SM83::instructionRLA() -> void { ZF = 0; } -auto SM83::instructionRLC_Direct(uint8& data) -> void { +auto SM83::instructionRLC_Direct(n8& data) -> void { data = RLC(data); } -auto SM83::instructionRLC_Indirect(uint16& address) -> void { +auto SM83::instructionRLC_Indirect(n16& address) -> void { auto data = read(address); write(address, RLC(data)); } @@ -338,11 +338,11 @@ auto SM83::instructionRLCA() -> void { ZF = 0; } -auto SM83::instructionRR_Direct(uint8& data) -> void { +auto SM83::instructionRR_Direct(n8& data) -> void { data = RR(data); } -auto SM83::instructionRR_Indirect(uint16& address) -> void { +auto SM83::instructionRR_Indirect(n16& address) -> void { auto data = read(address); write(address, RR(data)); } @@ -352,11 +352,11 @@ auto SM83::instructionRRA() -> void { ZF = 0; } -auto SM83::instructionRRC_Direct(uint8& data) -> void { +auto SM83::instructionRRC_Direct(n8& data) -> void { data = RRC(data); } -auto SM83::instructionRRC_Indirect(uint16& address) -> void { +auto SM83::instructionRRC_Indirect(n16& address) -> void { auto data = read(address); write(address, RRC(data)); } @@ -366,21 +366,21 @@ auto SM83::instructionRRCA() -> void { ZF = 0; } -auto SM83::instructionRST_Implied(uint8 vector) -> void { +auto SM83::instructionRST_Implied(n8 vector) -> void { idle(); push(PC); PC = vector; } -auto SM83::instructionSBC_Direct_Data(uint8& target) -> void { +auto SM83::instructionSBC_Direct_Data(n8& target) -> void { target = SUB(target, operand(), CF); } -auto SM83::instructionSBC_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionSBC_Direct_Direct(n8& target, n8& source) -> void { target = SUB(target, source, CF); } -auto SM83::instructionSBC_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionSBC_Direct_Indirect(n8& target, n16& source) -> void { target = SUB(target, read(source), CF); } @@ -389,39 +389,39 @@ auto SM83::instructionSCF() -> void { HF = NF = 0; } -auto SM83::instructionSET_Index_Direct(uint3 index, uint8& data) -> void { +auto SM83::instructionSET_Index_Direct(n3 index, n8& data) -> void { data.bit(index) = 1; } -auto SM83::instructionSET_Index_Indirect(uint3 index, uint16& address) -> void { +auto SM83::instructionSET_Index_Indirect(n3 index, n16& address) -> void { auto data = read(address); data.bit(index) = 1; write(address, data); } -auto SM83::instructionSLA_Direct(uint8& data) -> void { +auto SM83::instructionSLA_Direct(n8& data) -> void { data = SLA(data); } -auto SM83::instructionSLA_Indirect(uint16& address) -> void { +auto SM83::instructionSLA_Indirect(n16& address) -> void { auto data = read(address); write(address, SLA(data)); } -auto SM83::instructionSRA_Direct(uint8& data) -> void { +auto SM83::instructionSRA_Direct(n8& data) -> void { data = SRA(data); } -auto SM83::instructionSRA_Indirect(uint16& address) -> void { +auto SM83::instructionSRA_Indirect(n16& address) -> void { auto data = read(address); write(address, SRA(data)); } -auto SM83::instructionSRL_Direct(uint8& data) -> void { +auto SM83::instructionSRL_Direct(n8& data) -> void { data = SRL(data); } -auto SM83::instructionSRL_Indirect(uint16& address) -> void { +auto SM83::instructionSRL_Indirect(n16& address) -> void { auto data = read(address); write(address, SRL(data)); } @@ -432,35 +432,35 @@ auto SM83::instructionSTOP() -> void { while(r.stop) stop(); } -auto SM83::instructionSUB_Direct_Data(uint8& target) -> void { +auto SM83::instructionSUB_Direct_Data(n8& target) -> void { target = SUB(target, operand()); } -auto SM83::instructionSUB_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionSUB_Direct_Direct(n8& target, n8& source) -> void { target = SUB(target, source); } -auto SM83::instructionSUB_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionSUB_Direct_Indirect(n8& target, n16& source) -> void { target = SUB(target, read(source)); } -auto SM83::instructionSWAP_Direct(uint8& data) -> void { +auto SM83::instructionSWAP_Direct(n8& data) -> void { data = SWAP(data); } -auto SM83::instructionSWAP_Indirect(uint16& address) -> void { +auto SM83::instructionSWAP_Indirect(n16& address) -> void { auto data = read(address); write(address, SWAP(data)); } -auto SM83::instructionXOR_Direct_Data(uint8& target) -> void { +auto SM83::instructionXOR_Direct_Data(n8& target) -> void { target = XOR(target, operand()); } -auto SM83::instructionXOR_Direct_Direct(uint8& target, uint8& source) -> void { +auto SM83::instructionXOR_Direct_Direct(n8& target, n8& source) -> void { target = XOR(target, source); } -auto SM83::instructionXOR_Direct_Indirect(uint8& target, uint16& source) -> void { +auto SM83::instructionXOR_Direct_Indirect(n8& target, n16& source) -> void { target = XOR(target, read(source)); } diff --git a/ares/component/processor/sm83/memory.cpp b/ares/component/processor/sm83/memory.cpp index 2833f4d065..1e3da4f363 100644 --- a/ares/component/processor/sm83/memory.cpp +++ b/ares/component/processor/sm83/memory.cpp @@ -1,28 +1,28 @@ -auto SM83::operand() -> uint8 { +auto SM83::operand() -> n8 { return read(PC++); } -auto SM83::operands() -> uint16 { - uint16 data = read(PC++) << 0; +auto SM83::operands() -> n16 { + n16 data = read(PC++) << 0; return data | read(PC++) << 8; } -auto SM83::load(uint16 address) -> uint16 { - uint16 data = read(address++) << 0; +auto SM83::load(n16 address) -> n16 { + n16 data = read(address++) << 0; return data | read(address++) << 8; } -auto SM83::store(uint16 address, uint16 data) -> void { +auto SM83::store(n16 address, n16 data) -> void { write(address++, data >> 0); write(address++, data >> 8); } -auto SM83::pop() -> uint16 { - uint16 data = read(SP++) << 0; +auto SM83::pop() -> n16 { + n16 data = read(SP++) << 0; return data | read(SP++) << 8; } -auto SM83::push(uint16 data) -> void { +auto SM83::push(n16 data) -> void { write(--SP, data >> 8); write(--SP, data >> 0); } diff --git a/ares/component/processor/sm83/sm83.hpp b/ares/component/processor/sm83/sm83.hpp index ca0b5d103a..8aef31f63f 100644 --- a/ares/component/processor/sm83/sm83.hpp +++ b/ares/component/processor/sm83/sm83.hpp @@ -13,8 +13,8 @@ struct SM83 { virtual auto stop() -> void = 0; virtual auto halt() -> void = 0; virtual auto idle() -> void = 0; - virtual auto read(uint16 address) -> uint8 = 0; - virtual auto write(uint16 address, uint8 data) -> void = 0; + virtual auto read(n16 address) -> n8 = 0; + virtual auto write(n16 address, n8 data) -> void = 0; //sm83.cpp auto power() -> void; @@ -27,141 +27,141 @@ struct SM83 { auto serialize(serializer&) -> void; //disassembler.cpp - virtual auto readDebugger(uint16 address) -> uint8 { return 0; } - noinline auto disassembleInstruction(maybe pc = {}) -> string; + virtual auto readDebugger(n16 address) -> n8 { return 0; } + noinline auto disassembleInstruction(maybe pc = {}) -> string; noinline auto disassembleContext() -> string; //memory.cpp - auto operand() -> uint8; - auto operands() -> uint16; - auto load(uint16 address) -> uint16; - auto store(uint16 address, uint16 data) -> void; - auto pop() -> uint16; - auto push(uint16 data) -> void; + auto operand() -> n8; + auto operands() -> n16; + auto load(n16 address) -> n16; + auto store(n16 address, n16 data) -> void; + auto pop() -> n16; + auto push(n16 data) -> void; //algorithms.cpp - auto ADD(uint8, uint8, bool = 0) -> uint8; - auto AND(uint8, uint8) -> uint8; - auto BIT(uint3, uint8) -> void; - auto CP(uint8, uint8) -> void; - auto DEC(uint8) -> uint8; - auto INC(uint8) -> uint8; - auto OR(uint8, uint8) -> uint8; - auto RL(uint8) -> uint8; - auto RLC(uint8) -> uint8; - auto RR(uint8) -> uint8; - auto RRC(uint8) -> uint8; - auto SLA(uint8) -> uint8; - auto SRA(uint8) -> uint8; - auto SRL(uint8) -> uint8; - auto SUB(uint8, uint8, bool = 0) -> uint8; - auto SWAP(uint8) -> uint8; - auto XOR(uint8, uint8) -> uint8; + auto ADD(n8, n8, bool = 0) -> n8; + auto AND(n8, n8) -> n8; + auto BIT(n3, n8) -> void; + auto CP(n8, n8) -> void; + auto DEC(n8) -> n8; + auto INC(n8) -> n8; + auto OR(n8, n8) -> n8; + auto RL(n8) -> n8; + auto RLC(n8) -> n8; + auto RR(n8) -> n8; + auto RRC(n8) -> n8; + auto SLA(n8) -> n8; + auto SRA(n8) -> n8; + auto SRL(n8) -> n8; + auto SUB(n8, n8, bool = 0) -> n8; + auto SWAP(n8) -> n8; + auto XOR(n8, n8) -> n8; //instructions.cpp - auto instructionADC_Direct_Data(uint8&) -> void; - auto instructionADC_Direct_Direct(uint8&, uint8&) -> void; - auto instructionADC_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionADD_Direct_Data(uint8&) -> void; - auto instructionADD_Direct_Direct(uint8&, uint8&) -> void; - auto instructionADD_Direct_Direct(uint16&, uint16&) -> void; - auto instructionADD_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionADD_Direct_Relative(uint16&) -> void; - auto instructionAND_Direct_Data(uint8&) -> void; - auto instructionAND_Direct_Direct(uint8&, uint8&) -> void; - auto instructionAND_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionBIT_Index_Direct(uint3, uint8&) -> void; - auto instructionBIT_Index_Indirect(uint3, uint16&) -> void; + auto instructionADC_Direct_Data(n8&) -> void; + auto instructionADC_Direct_Direct(n8&, n8&) -> void; + auto instructionADC_Direct_Indirect(n8&, n16&) -> void; + auto instructionADD_Direct_Data(n8&) -> void; + auto instructionADD_Direct_Direct(n8&, n8&) -> void; + auto instructionADD_Direct_Direct(n16&, n16&) -> void; + auto instructionADD_Direct_Indirect(n8&, n16&) -> void; + auto instructionADD_Direct_Relative(n16&) -> void; + auto instructionAND_Direct_Data(n8&) -> void; + auto instructionAND_Direct_Direct(n8&, n8&) -> void; + auto instructionAND_Direct_Indirect(n8&, n16&) -> void; + auto instructionBIT_Index_Direct(n3, n8&) -> void; + auto instructionBIT_Index_Indirect(n3, n16&) -> void; auto instructionCALL_Condition_Address(bool) -> void; auto instructionCCF() -> void; - auto instructionCP_Direct_Data(uint8&) -> void; - auto instructionCP_Direct_Direct(uint8&, uint8&) -> void; - auto instructionCP_Direct_Indirect(uint8&, uint16&) -> void; + auto instructionCP_Direct_Data(n8&) -> void; + auto instructionCP_Direct_Direct(n8&, n8&) -> void; + auto instructionCP_Direct_Indirect(n8&, n16&) -> void; auto instructionCPL() -> void; auto instructionDAA() -> void; - auto instructionDEC_Direct(uint8&) -> void; - auto instructionDEC_Direct(uint16&) -> void; - auto instructionDEC_Indirect(uint16&) -> void; + auto instructionDEC_Direct(n8&) -> void; + auto instructionDEC_Direct(n16&) -> void; + auto instructionDEC_Indirect(n16&) -> void; auto instructionDI() -> void; auto instructionEI() -> void; auto instructionHALT() -> void; - auto instructionINC_Direct(uint8&) -> void; - auto instructionINC_Direct(uint16&) -> void; - auto instructionINC_Indirect(uint16&) -> void; + auto instructionINC_Direct(n8&) -> void; + auto instructionINC_Direct(n16&) -> void; + auto instructionINC_Indirect(n16&) -> void; auto instructionJP_Condition_Address(bool) -> void; - auto instructionJP_Direct(uint16&) -> void; + auto instructionJP_Direct(n16&) -> void; auto instructionJR_Condition_Relative(bool) -> void; - auto instructionLD_Address_Direct(uint8&) -> void; - auto instructionLD_Address_Direct(uint16&) -> void; - auto instructionLD_Direct_Address(uint8&) -> void; - auto instructionLD_Direct_Data(uint8&) -> void; - auto instructionLD_Direct_Data(uint16&) -> void; - auto instructionLD_Direct_Direct(uint8&, uint8&) -> void; - auto instructionLD_Direct_Direct(uint16&, uint16&) -> void; - auto instructionLD_Direct_DirectRelative(uint16&, uint16&) -> void; - auto instructionLD_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionLD_Direct_IndirectDecrement(uint8&, uint16&) -> void; - auto instructionLD_Direct_IndirectIncrement(uint8&, uint16&) -> void; - auto instructionLD_Indirect_Data(uint16&) -> void; - auto instructionLD_Indirect_Direct(uint16&, uint8&) -> void; - auto instructionLD_IndirectDecrement_Direct(uint16&, uint8&) -> void; - auto instructionLD_IndirectIncrement_Direct(uint16&, uint8&) -> void; - auto instructionLDH_Address_Direct(uint8&) -> void; - auto instructionLDH_Direct_Address(uint8&) -> void; - auto instructionLDH_Direct_Indirect(uint8&, uint8&) -> void; - auto instructionLDH_Indirect_Direct(uint8&, uint8&) -> void; + auto instructionLD_Address_Direct(n8&) -> void; + auto instructionLD_Address_Direct(n16&) -> void; + auto instructionLD_Direct_Address(n8&) -> void; + auto instructionLD_Direct_Data(n8&) -> void; + auto instructionLD_Direct_Data(n16&) -> void; + auto instructionLD_Direct_Direct(n8&, n8&) -> void; + auto instructionLD_Direct_Direct(n16&, n16&) -> void; + auto instructionLD_Direct_DirectRelative(n16&, n16&) -> void; + auto instructionLD_Direct_Indirect(n8&, n16&) -> void; + auto instructionLD_Direct_IndirectDecrement(n8&, n16&) -> void; + auto instructionLD_Direct_IndirectIncrement(n8&, n16&) -> void; + auto instructionLD_Indirect_Data(n16&) -> void; + auto instructionLD_Indirect_Direct(n16&, n8&) -> void; + auto instructionLD_IndirectDecrement_Direct(n16&, n8&) -> void; + auto instructionLD_IndirectIncrement_Direct(n16&, n8&) -> void; + auto instructionLDH_Address_Direct(n8&) -> void; + auto instructionLDH_Direct_Address(n8&) -> void; + auto instructionLDH_Direct_Indirect(n8&, n8&) -> void; + auto instructionLDH_Indirect_Direct(n8&, n8&) -> void; auto instructionNOP() -> void; - auto instructionOR_Direct_Data(uint8&) -> void; - auto instructionOR_Direct_Direct(uint8&, uint8&) -> void; - auto instructionOR_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionPOP_Direct(uint16&) -> void; - auto instructionPOP_Direct_AF(uint16&) -> void; - auto instructionPUSH_Direct(uint16&) -> void; - auto instructionRES_Index_Direct(uint3, uint8&) -> void; - auto instructionRES_Index_Indirect(uint3, uint16&) -> void; + auto instructionOR_Direct_Data(n8&) -> void; + auto instructionOR_Direct_Direct(n8&, n8&) -> void; + auto instructionOR_Direct_Indirect(n8&, n16&) -> void; + auto instructionPOP_Direct(n16&) -> void; + auto instructionPOP_Direct_AF(n16&) -> void; + auto instructionPUSH_Direct(n16&) -> void; + auto instructionRES_Index_Direct(n3, n8&) -> void; + auto instructionRES_Index_Indirect(n3, n16&) -> void; auto instructionRET() -> void; auto instructionRET_Condition(bool) -> void; auto instructionRETI() -> void; - auto instructionRL_Direct(uint8&) -> void; - auto instructionRL_Indirect(uint16&) -> void; + auto instructionRL_Direct(n8&) -> void; + auto instructionRL_Indirect(n16&) -> void; auto instructionRLA() -> void; - auto instructionRLC_Direct(uint8&) -> void; - auto instructionRLC_Indirect(uint16&) -> void; + auto instructionRLC_Direct(n8&) -> void; + auto instructionRLC_Indirect(n16&) -> void; auto instructionRLCA() -> void; - auto instructionRR_Direct(uint8&) -> void; - auto instructionRR_Indirect(uint16&) -> void; + auto instructionRR_Direct(n8&) -> void; + auto instructionRR_Indirect(n16&) -> void; auto instructionRRA() -> void; - auto instructionRRC_Direct(uint8&) -> void; - auto instructionRRC_Indirect(uint16&) -> void; + auto instructionRRC_Direct(n8&) -> void; + auto instructionRRC_Indirect(n16&) -> void; auto instructionRRCA() -> void; - auto instructionRST_Implied(uint8) -> void; - auto instructionSBC_Direct_Data(uint8&) -> void; - auto instructionSBC_Direct_Direct(uint8&, uint8&) -> void; - auto instructionSBC_Direct_Indirect(uint8&, uint16&) -> void; + auto instructionRST_Implied(n8) -> void; + auto instructionSBC_Direct_Data(n8&) -> void; + auto instructionSBC_Direct_Direct(n8&, n8&) -> void; + auto instructionSBC_Direct_Indirect(n8&, n16&) -> void; auto instructionSCF() -> void; - auto instructionSET_Index_Direct(uint3, uint8&) -> void; - auto instructionSET_Index_Indirect(uint3, uint16&) -> void; - auto instructionSLA_Direct(uint8&) -> void; - auto instructionSLA_Indirect(uint16&) -> void; - auto instructionSRA_Direct(uint8&) -> void; - auto instructionSRA_Indirect(uint16&) -> void; - auto instructionSRL_Direct(uint8&) -> void; - auto instructionSRL_Indirect(uint16&) -> void; - auto instructionSUB_Direct_Data(uint8&) -> void; - auto instructionSUB_Direct_Direct(uint8&, uint8&) -> void; - auto instructionSUB_Direct_Indirect(uint8&, uint16&) -> void; - auto instructionSWAP_Direct(uint8& data) -> void; - auto instructionSWAP_Indirect(uint16& address) -> void; + auto instructionSET_Index_Direct(n3, n8&) -> void; + auto instructionSET_Index_Indirect(n3, n16&) -> void; + auto instructionSLA_Direct(n8&) -> void; + auto instructionSLA_Indirect(n16&) -> void; + auto instructionSRA_Direct(n8&) -> void; + auto instructionSRA_Indirect(n16&) -> void; + auto instructionSRL_Direct(n8&) -> void; + auto instructionSRL_Indirect(n16&) -> void; + auto instructionSUB_Direct_Data(n8&) -> void; + auto instructionSUB_Direct_Direct(n8&, n8&) -> void; + auto instructionSUB_Direct_Indirect(n8&, n16&) -> void; + auto instructionSWAP_Direct(n8& data) -> void; + auto instructionSWAP_Indirect(n16& address) -> void; auto instructionSTOP() -> void; - auto instructionXOR_Direct_Data(uint8&) -> void; - auto instructionXOR_Direct_Direct(uint8&, uint8&) -> void; - auto instructionXOR_Direct_Indirect(uint8&, uint16&) -> void; + auto instructionXOR_Direct_Data(n8&) -> void; + auto instructionXOR_Direct_Direct(n8&, n8&) -> void; + auto instructionXOR_Direct_Indirect(n8&, n16&) -> void; struct Registers { union Pair { Pair() : word(0) {} - uint16 word; - struct Byte { uint8 order_msb2(hi, lo); } byte; + n16 word; + struct Byte { n8 order_msb2(hi, lo); } byte; }; Pair af; @@ -171,15 +171,15 @@ struct SM83 { Pair sp; Pair pc; - uint1 ei; - uint1 halt; - uint1 stop; - uint1 ime; + n1 ei; + n1 halt; + n1 stop; + n1 ime; } r; //disassembler.cpp - auto disassembleOpcode(uint16 pc) -> string; - auto disassembleOpcodeCB(uint16 pc) -> string; + auto disassembleOpcode(n16 pc) -> string; + auto disassembleOpcodeCB(n16 pc) -> string; }; } diff --git a/ares/component/processor/spc700/algorithms.cpp b/ares/component/processor/spc700/algorithms.cpp index d7e3745ef8..1d62f18eb3 100644 --- a/ares/component/processor/spc700/algorithms.cpp +++ b/ares/component/processor/spc700/algorithms.cpp @@ -1,21 +1,21 @@ -auto SPC700::algorithmADC(uint8 x, uint8 y) -> uint8 { - int z = x + y + CF; +auto SPC700::algorithmADC(n8 x, n8 y) -> n8 { + s32 z = x + y + CF; CF = z > 0xff; - ZF = (uint8)z == 0; + ZF = (n8)z == 0; HF = (x ^ y ^ z) & 0x10; VF = ~(x ^ y) & (x ^ z) & 0x80; NF = z & 0x80; return z; } -auto SPC700::algorithmAND(uint8 x, uint8 y) -> uint8 { +auto SPC700::algorithmAND(n8 x, n8 y) -> n8 { x &= y; ZF = x == 0; NF = x & 0x80; return x; } -auto SPC700::algorithmASL(uint8 x) -> uint8 { +auto SPC700::algorithmASL(n8 x) -> n8 { CF = x & 0x80; x <<= 1; ZF = x == 0; @@ -23,42 +23,42 @@ auto SPC700::algorithmASL(uint8 x) -> uint8 { return x; } -auto SPC700::algorithmCMP(uint8 x, uint8 y) -> uint8 { - int z = x - y; +auto SPC700::algorithmCMP(n8 x, n8 y) -> n8 { + s32 z = x - y; CF = z >= 0; - ZF = (uint8)z == 0; + ZF = (n8)z == 0; NF = z & 0x80; return x; } -auto SPC700::algorithmDEC(uint8 x) -> uint8 { +auto SPC700::algorithmDEC(n8 x) -> n8 { x--; ZF = x == 0; NF = x & 0x80; return x; } -auto SPC700::algorithmEOR(uint8 x, uint8 y) -> uint8 { +auto SPC700::algorithmEOR(n8 x, n8 y) -> n8 { x ^= y; ZF = x == 0; NF = x & 0x80; return x; } -auto SPC700::algorithmINC(uint8 x) -> uint8 { +auto SPC700::algorithmINC(n8 x) -> n8 { x++; ZF = x == 0; NF = x & 0x80; return x; } -auto SPC700::algorithmLD(uint8 x, uint8 y) -> uint8 { +auto SPC700::algorithmLD(n8 x, n8 y) -> n8 { ZF = y == 0; NF = y & 0x80; return y; } -auto SPC700::algorithmLSR(uint8 x) -> uint8 { +auto SPC700::algorithmLSR(n8 x) -> n8 { CF = x & 0x01; x >>= 1; ZF = x == 0; @@ -66,14 +66,14 @@ auto SPC700::algorithmLSR(uint8 x) -> uint8 { return x; } -auto SPC700::algorithmOR(uint8 x, uint8 y) -> uint8 { +auto SPC700::algorithmOR(n8 x, n8 y) -> n8 { x |= y; ZF = x == 0; NF = x & 0x80; return x; } -auto SPC700::algorithmROL(uint8 x) -> uint8 { +auto SPC700::algorithmROL(n8 x) -> n8 { bool carry = CF; CF = x & 0x80; x = x << 1 | carry; @@ -82,7 +82,7 @@ auto SPC700::algorithmROL(uint8 x) -> uint8 { return x; } -auto SPC700::algorithmROR(uint8 x) -> uint8 { +auto SPC700::algorithmROR(n8 x) -> n8 { bool carry = CF; CF = x & 0x01; x = carry << 7 | x >> 1; @@ -91,14 +91,14 @@ auto SPC700::algorithmROR(uint8 x) -> uint8 { return x; } -auto SPC700::algorithmSBC(uint8 x, uint8 y) -> uint8 { +auto SPC700::algorithmSBC(n8 x, n8 y) -> n8 { return algorithmADC(x, ~y); } // -auto SPC700::algorithmADW(uint16 x, uint16 y) -> uint16 { - uint16 z; +auto SPC700::algorithmADW(n16 x, n16 y) -> n16 { + n16 z; CF = 0; z = algorithmADC(x, y); z |= algorithmADC(x >> 8, y >> 8) << 8; @@ -106,22 +106,22 @@ auto SPC700::algorithmADW(uint16 x, uint16 y) -> uint16 { return z; } -auto SPC700::algorithmCPW(uint16 x, uint16 y) -> uint16 { - int z = x - y; +auto SPC700::algorithmCPW(n16 x, n16 y) -> n16 { + s32 z = x - y; CF = z >= 0; - ZF = (uint16)z == 0; + ZF = (n16)z == 0; NF = z & 0x8000; return x; } -auto SPC700::algorithmLDW(uint16 x, uint16 y) -> uint16 { +auto SPC700::algorithmLDW(n16 x, n16 y) -> n16 { ZF = y == 0; NF = y & 0x8000; return y; } -auto SPC700::algorithmSBW(uint16 x, uint16 y) -> uint16 { - uint16 z; +auto SPC700::algorithmSBW(n16 x, n16 y) -> n16 { + n16 z; CF = 1; z = algorithmSBC(x, y); z |= algorithmSBC(x >> 8, y >> 8) << 8; diff --git a/ares/component/processor/spc700/disassembler.cpp b/ares/component/processor/spc700/disassembler.cpp index 0c0f554312..0d98bef8c5 100644 --- a/ares/component/processor/spc700/disassembler.cpp +++ b/ares/component/processor/spc700/disassembler.cpp @@ -1,19 +1,19 @@ -auto SPC700::disassembleInstruction(uint16 addr, uint1 p) -> string { - auto read = [&](uint16 addr) -> uint8 { +auto SPC700::disassembleInstruction(n16 addr, n1 p) -> string { + auto read = [&](n16 addr) -> n8 { return readDisassembler(addr); }; - auto relative = [&](uint length, int8 offset) -> uint16 { - uint16 pc = addr + length; + auto relative = [&](u32 length, i8 offset) -> n16 { + n16 pc = addr + length; return pc + offset; }; auto a = [&] { return hex((read(addr + 1) << 0) + (read(addr + 2) << 8), 4L); }; - auto b = [&](uint n) { return hex(read(addr + 1 + n), 2L); }; - auto rel = [&](uint r, uint n = 0) { return hex(addr + r + (int8)read(addr + 1 + n), 4L); }; - auto dp = [&](uint n) { return hex((p << 8) + read(addr + 1 + n), 3L); }; + auto b = [&](u32 n) { return hex(read(addr + 1 + n), 2L); }; + auto rel = [&](u32 r, u32 n = 0) { return hex(addr + r + (i8)read(addr + 1 + n), 4L); }; + auto dp = [&](u32 n) { return hex((p << 8) + read(addr + 1 + n), 3L); }; auto ab = [&] { - uint n = (read(addr + 1) << 0) + (read(addr + 2) << 8); + u32 n = (read(addr + 1) << 0) + (read(addr + 2) << 8); return string{hex(n & 0x1fff, 4L), ":", hex(n >> 13, 1L)}; }; diff --git a/ares/component/processor/spc700/instructions.cpp b/ares/component/processor/spc700/instructions.cpp index 395ade478b..b034867a57 100644 --- a/ares/component/processor/spc700/instructions.cpp +++ b/ares/component/processor/spc700/instructions.cpp @@ -1,9 +1,9 @@ -auto SPC700::instructionAbsoluteBitModify(uint3 mode) -> void { - uint16 address = fetch(); +auto SPC700::instructionAbsoluteBitModify(n3 mode) -> void { + n16 address = fetch(); address |= fetch() << 8; - uint3 bit = address >> 13; + n3 bit = address >> 13; address &= 0x1fff; - uint8 data = read(address); + n8 data = read(address); switch(mode) { case 0: //or addr:bit idle(); @@ -38,44 +38,44 @@ auto SPC700::instructionAbsoluteBitModify(uint3 mode) -> void { } } -auto SPC700::instructionAbsoluteBitSet(uint3 bit, bool value) -> void { - uint8 address = fetch(); - uint8 data = load(address); +auto SPC700::instructionAbsoluteBitSet(n3 bit, bool value) -> void { + n8 address = fetch(); + n8 data = load(address); data.bit(bit) = value; store(address, data); } -auto SPC700::instructionAbsoluteRead(fpb op, uint8& target) -> void { - uint16 address = fetch(); +auto SPC700::instructionAbsoluteRead(fpb op, n8& target) -> void { + n16 address = fetch(); address |= fetch() << 8; - uint8 data = read(address); + n8 data = read(address); target = alu(target, data); } auto SPC700::instructionAbsoluteModify(fps op) -> void { - uint16 address = fetch(); + n16 address = fetch(); address |= fetch() << 8; - uint8 data = read(address); + n8 data = read(address); write(address, alu(data)); } -auto SPC700::instructionAbsoluteWrite(uint8& data) -> void { - uint16 address = fetch(); +auto SPC700::instructionAbsoluteWrite(n8& data) -> void { + n16 address = fetch(); address |= fetch() << 8; read(address); write(address, data); } -auto SPC700::instructionAbsoluteIndexedRead(fpb op, uint8& index) -> void { - uint16 address = fetch(); +auto SPC700::instructionAbsoluteIndexedRead(fpb op, n8& index) -> void { + n16 address = fetch(); address |= fetch() << 8; idle(); - uint8 data = read(address + index); + n8 data = read(address + index); A = alu(A, data); } -auto SPC700::instructionAbsoluteIndexedWrite(uint8& index) -> void { - uint16 address = fetch(); +auto SPC700::instructionAbsoluteIndexedWrite(n8& index) -> void { + n16 address = fetch(); address |= fetch() << 8; idle(); read(address + index); @@ -83,66 +83,66 @@ auto SPC700::instructionAbsoluteIndexedWrite(uint8& index) -> void { } auto SPC700::instructionBranch(bool take) -> void { - uint8 data = fetch(); + n8 data = fetch(); if(!take) return; idle(); idle(); - PC += (int8)data; + PC += (i8)data; } -auto SPC700::instructionBranchBit(uint3 bit, bool match) -> void { - uint8 address = fetch(); - uint8 data = load(address); +auto SPC700::instructionBranchBit(n3 bit, bool match) -> void { + n8 address = fetch(); + n8 data = load(address); idle(); - uint8 displacement = fetch(); + n8 displacement = fetch(); if(data.bit(bit) != match) return; idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } auto SPC700::instructionBranchNotDirect() -> void { - uint8 address = fetch(); - uint8 data = load(address); + n8 address = fetch(); + n8 data = load(address); idle(); - uint8 displacement = fetch(); + n8 displacement = fetch(); if(A == data) return; idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } auto SPC700::instructionBranchNotDirectDecrement() -> void { - uint8 address = fetch(); - uint8 data = load(address); + n8 address = fetch(); + n8 data = load(address); store(address, --data); - uint8 displacement = fetch(); + n8 displacement = fetch(); if(data == 0) return; idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } -auto SPC700::instructionBranchNotDirectIndexed(uint8& index) -> void { - uint8 address = fetch(); +auto SPC700::instructionBranchNotDirectIndexed(n8& index) -> void { + n8 address = fetch(); idle(); - uint8 data = load(address + index); + n8 data = load(address + index); idle(); - uint8 displacement = fetch(); + n8 displacement = fetch(); if(A == data) return; idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } auto SPC700::instructionBranchNotYDecrement() -> void { read(PC); idle(); - uint8 displacement = fetch(); + n8 displacement = fetch(); if(--Y == 0) return; idle(); idle(); - PC += (int8)displacement; + PC += (i8)displacement; } auto SPC700::instructionBreak() -> void { @@ -151,7 +151,7 @@ auto SPC700::instructionBreak() -> void { push(PC >> 0); push(P); idle(); - uint16 address = read(0xffde + 0); + n16 address = read(0xffde + 0); address |= read(0xffde + 1) << 8; PC = address; IF = 0; @@ -159,7 +159,7 @@ auto SPC700::instructionBreak() -> void { } auto SPC700::instructionCallAbsolute() -> void { - uint16 address = fetch(); + n16 address = fetch(); address |= fetch() << 8; idle(); push(PC >> 8); @@ -170,7 +170,7 @@ auto SPC700::instructionCallAbsolute() -> void { } auto SPC700::instructionCallPage() -> void { - uint8 address = fetch(); + n8 address = fetch(); idle(); push(PC >> 8); push(PC >> 0); @@ -178,14 +178,14 @@ auto SPC700::instructionCallPage() -> void { PC = 0xff00 | address; } -auto SPC700::instructionCallTable(uint4 vector) -> void { +auto SPC700::instructionCallTable(n4 vector) -> void { read(PC); idle(); push(PC >> 8); push(PC >> 0); idle(); - uint16 address = 0xffde - (vector << 1); - uint16 pc = read(address + 0); + n16 address = 0xffde - (vector << 1); + n16 pc = read(address + 0); pc |= read(address + 1) << 8; PC = pc; } @@ -224,90 +224,90 @@ auto SPC700::instructionDecimalAdjustSub() -> void { NF = A & 0x80; } -auto SPC700::instructionDirectRead(fpb op, uint8& target) -> void { - uint8 address = fetch(); - uint8 data = load(address); +auto SPC700::instructionDirectRead(fpb op, n8& target) -> void { + n8 address = fetch(); + n8 data = load(address); target = alu(target, data); } auto SPC700::instructionDirectModify(fps op) -> void { - uint8 address = fetch(); - uint8 data = load(address); + n8 address = fetch(); + n8 data = load(address); store(address, alu(data)); } -auto SPC700::instructionDirectWrite(uint8& data) -> void { - uint8 address = fetch(); +auto SPC700::instructionDirectWrite(n8& data) -> void { + n8 address = fetch(); load(address); store(address, data); } auto SPC700::instructionDirectDirectCompare(fpb op) -> void { - uint8 source = fetch(); - uint8 rhs = load(source); - uint8 target = fetch(); - uint8 lhs = load(target); + n8 source = fetch(); + n8 rhs = load(source); + n8 target = fetch(); + n8 lhs = load(target); lhs = alu(lhs, rhs); idle(); } auto SPC700::instructionDirectDirectModify(fpb op) -> void { - uint8 source = fetch(); - uint8 rhs = load(source); - uint8 target = fetch(); - uint8 lhs = load(target); + n8 source = fetch(); + n8 rhs = load(source); + n8 target = fetch(); + n8 lhs = load(target); lhs = alu(lhs, rhs); store(target, lhs); } auto SPC700::instructionDirectDirectWrite() -> void { - uint8 source = fetch(); - uint8 data = load(source); - uint8 target = fetch(); + n8 source = fetch(); + n8 data = load(source); + n8 target = fetch(); store(target, data); } auto SPC700::instructionDirectImmediateCompare(fpb op) -> void { - uint8 immediate = fetch(); - uint8 address = fetch(); - uint8 data = load(address); + n8 immediate = fetch(); + n8 address = fetch(); + n8 data = load(address); data = alu(data, immediate); idle(); } auto SPC700::instructionDirectImmediateModify(fpb op) -> void { - uint8 immediate = fetch(); - uint8 address = fetch(); - uint8 data = load(address); + n8 immediate = fetch(); + n8 address = fetch(); + n8 data = load(address); data = alu(data, immediate); store(address, data); } auto SPC700::instructionDirectImmediateWrite() -> void { - uint8 immediate = fetch(); - uint8 address = fetch(); + n8 immediate = fetch(); + n8 address = fetch(); load(address); store(address, immediate); } auto SPC700::instructionDirectCompareWord(fpw op) -> void { - uint8 address = fetch(); - uint16 data = load(address + 0); + n8 address = fetch(); + n16 data = load(address + 0); data |= load(address + 1) << 8; YA = alu(YA, data); } auto SPC700::instructionDirectReadWord(fpw op) -> void { - uint8 address = fetch(); - uint16 data = load(address + 0); + n8 address = fetch(); + n16 data = load(address + 0); idle(); data |= load(address + 1) << 8; YA = alu(YA, data); } -auto SPC700::instructionDirectModifyWord(int adjust) -> void { - uint8 address = fetch(); - uint16 data = load(address + 0) + adjust; +auto SPC700::instructionDirectModifyWord(s32 adjust) -> void { + n8 address = fetch(); + n16 data = load(address + 0) + adjust; store(address + 0, data >> 0); data += load(address + 1) << 8; store(address + 1, data >> 8); @@ -316,28 +316,28 @@ auto SPC700::instructionDirectModifyWord(int adjust) -> void { } auto SPC700::instructionDirectWriteWord() -> void { - uint8 address = fetch(); + n8 address = fetch(); load(address + 0); store(address + 0, A); store(address + 1, Y); } -auto SPC700::instructionDirectIndexedRead(fpb op, uint8& target, uint8& index) -> void { - uint8 address = fetch(); +auto SPC700::instructionDirectIndexedRead(fpb op, n8& target, n8& index) -> void { + n8 address = fetch(); idle(); - uint8 data = load(address + index); + n8 data = load(address + index); target = alu(target, data); } -auto SPC700::instructionDirectIndexedModify(fps op, uint8& index) -> void { - uint8 address = fetch(); +auto SPC700::instructionDirectIndexedModify(fps op, n8& index) -> void { + n8 address = fetch(); idle(); - uint8 data = load(address + index); + n8 data = load(address + index); store(address + index, alu(data)); } -auto SPC700::instructionDirectIndexedWrite(uint8& data, uint8& index) -> void { - uint8 address = fetch(); +auto SPC700::instructionDirectIndexedWrite(n8& data, n8& index) -> void { + n8 address = fetch(); idle(); load(address + index); store(address + index, data); @@ -355,7 +355,7 @@ auto SPC700::instructionDivide() -> void { idle(); idle(); idle(); - uint16 ya = YA; + n16 ya = YA; //overflow set if quotient >= 256 HF = (Y & 15) >= (X & 15); VF = Y >= X; @@ -390,46 +390,46 @@ auto SPC700::instructionFlagSet(bool& flag, bool value) -> void { flag = value; } -auto SPC700::instructionImmediateRead(fpb op, uint8& target) -> void { - uint8 data = fetch(); +auto SPC700::instructionImmediateRead(fpb op, n8& target) -> void { + n8 data = fetch(); target = alu(target, data); } -auto SPC700::instructionImpliedModify(fps op, uint8& target) -> void { +auto SPC700::instructionImpliedModify(fps op, n8& target) -> void { read(PC); target = alu(target); } -auto SPC700::instructionIndexedIndirectRead(fpb op, uint8& index) -> void { - uint8 indirect = fetch(); +auto SPC700::instructionIndexedIndirectRead(fpb op, n8& index) -> void { + n8 indirect = fetch(); idle(); - uint16 address = load(indirect + index + 0); + n16 address = load(indirect + index + 0); address |= load(indirect + index + 1) << 8; - uint8 data = read(address); + n8 data = read(address); A = alu(A, data); } -auto SPC700::instructionIndexedIndirectWrite(uint8& data, uint8& index) -> void { - uint8 indirect = fetch(); +auto SPC700::instructionIndexedIndirectWrite(n8& data, n8& index) -> void { + n8 indirect = fetch(); idle(); - uint16 address = load(indirect + index + 0); + n16 address = load(indirect + index + 0); address |= load(indirect + index + 1) << 8; read(address); write(address, data); } -auto SPC700::instructionIndirectIndexedRead(fpb op, uint8& index) -> void { - uint8 indirect = fetch(); +auto SPC700::instructionIndirectIndexedRead(fpb op, n8& index) -> void { + n8 indirect = fetch(); idle(); - uint16 address = load(indirect + 0); + n16 address = load(indirect + 0); address |= load(indirect + 1) << 8; - uint8 data = read(address + index); + n8 data = read(address + index); A = alu(A, data); } -auto SPC700::instructionIndirectIndexedWrite(uint8& data, uint8& index) -> void { - uint8 indirect = fetch(); - uint16 address = load(indirect + 0); +auto SPC700::instructionIndirectIndexedWrite(n8& data, n8& index) -> void { + n8 indirect = fetch(); + n16 address = load(indirect + 0); address |= load(indirect + 1) << 8; idle(); read(address + index); @@ -438,17 +438,17 @@ auto SPC700::instructionIndirectIndexedWrite(uint8& data, uint8& index) -> void auto SPC700::instructionIndirectXRead(fpb op) -> void { read(PC); - uint8 data = load(X); + n8 data = load(X); A = alu(A, data); } -auto SPC700::instructionIndirectXWrite(uint8& data) -> void { +auto SPC700::instructionIndirectXWrite(n8& data) -> void { read(PC); load(X); store(X, data); } -auto SPC700::instructionIndirectXIncrementRead(uint8& data) -> void { +auto SPC700::instructionIndirectXIncrementRead(n8& data) -> void { read(PC); data = load(X++); idle(); //quirk: consumes extra idle cycle compared to most read instructions @@ -456,7 +456,7 @@ auto SPC700::instructionIndirectXIncrementRead(uint8& data) -> void { NF = data & 0x80; } -auto SPC700::instructionIndirectXIncrementWrite(uint8& data) -> void { +auto SPC700::instructionIndirectXIncrementWrite(n8& data) -> void { read(PC); idle(); //quirk: not a read cycle as with most write instructions store(X++, data); @@ -464,31 +464,31 @@ auto SPC700::instructionIndirectXIncrementWrite(uint8& data) -> void { auto SPC700::instructionIndirectXCompareIndirectY(fpb op) -> void { read(PC); - uint8 rhs = load(Y); - uint8 lhs = load(X); + n8 rhs = load(Y); + n8 lhs = load(X); lhs = alu(lhs, rhs); idle(); } auto SPC700::instructionIndirectXWriteIndirectY(fpb op) -> void { read(PC); - uint8 rhs = load(Y); - uint8 lhs = load(X); + n8 rhs = load(Y); + n8 lhs = load(X); lhs = alu(lhs, rhs); store(X, lhs); } auto SPC700::instructionJumpAbsolute() -> void { - uint16 address = fetch(); + n16 address = fetch(); address |= fetch() << 8; PC = address; } auto SPC700::instructionJumpIndirectX() -> void { - uint16 address = fetch(); + n16 address = fetch(); address |= fetch() << 8; idle(); - uint16 pc = read(address + X + 0); + n16 pc = read(address + X + 0); pc |= read(address + X + 1) << 8; PC = pc; } @@ -502,7 +502,7 @@ auto SPC700::instructionMultiply() -> void { idle(); idle(); idle(); - uint16 ya = Y * A; + n16 ya = Y * A; A = ya >> 0; Y = ya >> 8; //result is set based on y (high-byte) only @@ -520,7 +520,7 @@ auto SPC700::instructionOverflowClear() -> void { VF = 0; } -auto SPC700::instructionPull(uint8& data) -> void { +auto SPC700::instructionPull(n8& data) -> void { read(PC); idle(); data = pull(); @@ -532,7 +532,7 @@ auto SPC700::instructionPullP() -> void { P = pull(); } -auto SPC700::instructionPush(uint8 data) -> void { +auto SPC700::instructionPush(n8 data) -> void { read(PC); push(data); idle(); @@ -542,7 +542,7 @@ auto SPC700::instructionReturnInterrupt() -> void { read(PC); idle(); P = pull(); - uint16 address = pull(); + n16 address = pull(); address |= pull() << 8; PC = address; } @@ -550,7 +550,7 @@ auto SPC700::instructionReturnInterrupt() -> void { auto SPC700::instructionReturnSubroutine() -> void { read(PC); idle(); - uint16 address = pull(); + n16 address = pull(); address |= pull() << 8; PC = address; } @@ -564,16 +564,16 @@ auto SPC700::instructionStop() -> void { } auto SPC700::instructionTestSetBitsAbsolute(bool set) -> void { - uint16 address = fetch(); + n16 address = fetch(); address |= fetch() << 8; - uint8 data = read(address); + n8 data = read(address); ZF = (A - data) == 0; NF = (A - data) & 0x80; read(address); write(address, set ? data | A : data & ~A); } -auto SPC700::instructionTransfer(uint8& from, uint8& to) -> void { +auto SPC700::instructionTransfer(n8& from, n8& to) -> void { read(PC); to = from; if(&to == &S) return; diff --git a/ares/component/processor/spc700/memory.cpp b/ares/component/processor/spc700/memory.cpp index 7b43330bd8..7733b5879d 100644 --- a/ares/component/processor/spc700/memory.cpp +++ b/ares/component/processor/spc700/memory.cpp @@ -1,19 +1,19 @@ -inline auto SPC700::fetch() -> uint8 { +inline auto SPC700::fetch() -> n8 { return read(PC++); } -inline auto SPC700::load(uint8 address) -> uint8 { +inline auto SPC700::load(n8 address) -> n8 { return read(PF << 8 | address); } -inline auto SPC700::store(uint8 address, uint8 data) -> void { +inline auto SPC700::store(n8 address, n8 data) -> void { return write(PF << 8 | address, data); } -inline auto SPC700::pull() -> uint8 { +inline auto SPC700::pull() -> n8 { return read(1 << 8 | ++S); } -inline auto SPC700::push(uint8 data) -> void { +inline auto SPC700::push(n8 data) -> void { return write(1 << 8 | S--, data); } diff --git a/ares/component/processor/spc700/spc700.hpp b/ares/component/processor/spc700/spc700.hpp index 3966845bbe..a5875f3e63 100644 --- a/ares/component/processor/spc700/spc700.hpp +++ b/ares/component/processor/spc700/spc700.hpp @@ -4,72 +4,72 @@ namespace ares { struct SPC700 { virtual auto idle() -> void = 0; - virtual auto read(uint16 address) -> uint8 = 0; - virtual auto write(uint16 address, uint8 data) -> void = 0; + virtual auto read(n16 address) -> n8 = 0; + virtual auto write(n16 address, n8 data) -> void = 0; virtual auto synchronizing() const -> bool = 0; - virtual auto readDisassembler(uint16 address) -> uint8 { return 0; } + virtual auto readDisassembler(n16 address) -> n8 { return 0; } //spc700.cpp auto power() -> void; //memory.cpp - auto fetch() -> uint8; - auto load(uint8 address) -> uint8; - auto store(uint8 address, uint8 data) -> void; - auto pull() -> uint8; - auto push(uint8 data) -> void; + auto fetch() -> n8; + auto load(n8 address) -> n8; + auto store(n8 address, n8 data) -> void; + auto pull() -> n8; + auto push(n8 data) -> void; //instruction.cpp auto instruction() -> void; //algorithms.cpp - auto algorithmADC(uint8, uint8) -> uint8; - auto algorithmAND(uint8, uint8) -> uint8; - auto algorithmASL(uint8) -> uint8; - auto algorithmCMP(uint8, uint8) -> uint8; - auto algorithmDEC(uint8) -> uint8; - auto algorithmEOR(uint8, uint8) -> uint8; - auto algorithmINC(uint8) -> uint8; - auto algorithmLD (uint8, uint8) -> uint8; - auto algorithmLSR(uint8) -> uint8; - auto algorithmOR (uint8, uint8) -> uint8; - auto algorithmROL(uint8) -> uint8; - auto algorithmROR(uint8) -> uint8; - auto algorithmSBC(uint8, uint8) -> uint8; - auto algorithmADW(uint16, uint16) -> uint16; - auto algorithmCPW(uint16, uint16) -> uint16; - auto algorithmLDW(uint16, uint16) -> uint16; - auto algorithmSBW(uint16, uint16) -> uint16; + auto algorithmADC(n8, n8) -> n8; + auto algorithmAND(n8, n8) -> n8; + auto algorithmASL(n8) -> n8; + auto algorithmCMP(n8, n8) -> n8; + auto algorithmDEC(n8) -> n8; + auto algorithmEOR(n8, n8) -> n8; + auto algorithmINC(n8) -> n8; + auto algorithmLD (n8, n8) -> n8; + auto algorithmLSR(n8) -> n8; + auto algorithmOR (n8, n8) -> n8; + auto algorithmROL(n8) -> n8; + auto algorithmROR(n8) -> n8; + auto algorithmSBC(n8, n8) -> n8; + auto algorithmADW(n16, n16) -> n16; + auto algorithmCPW(n16, n16) -> n16; + auto algorithmLDW(n16, n16) -> n16; + auto algorithmSBW(n16, n16) -> n16; //instructions.cpp - using fps = auto (SPC700::*)(uint8) -> uint8; - using fpb = auto (SPC700::*)(uint8, uint8) -> uint8; - using fpw = auto (SPC700::*)(uint16, uint16) -> uint16; + using fps = auto (SPC700::*)(n8) -> n8; + using fpb = auto (SPC700::*)(n8, n8) -> n8; + using fpw = auto (SPC700::*)(n16, n16) -> n16; - auto instructionAbsoluteBitModify(uint3) -> void; - auto instructionAbsoluteBitSet(uint3, bool) -> void; - auto instructionAbsoluteRead(fpb, uint8&) -> void; + auto instructionAbsoluteBitModify(n3) -> void; + auto instructionAbsoluteBitSet(n3, bool) -> void; + auto instructionAbsoluteRead(fpb, n8&) -> void; auto instructionAbsoluteModify(fps) -> void; - auto instructionAbsoluteWrite(uint8&) -> void; - auto instructionAbsoluteIndexedRead(fpb, uint8&) -> void; - auto instructionAbsoluteIndexedWrite(uint8&) -> void; + auto instructionAbsoluteWrite(n8&) -> void; + auto instructionAbsoluteIndexedRead(fpb, n8&) -> void; + auto instructionAbsoluteIndexedWrite(n8&) -> void; auto instructionBranch(bool) -> void; - auto instructionBranchBit(uint3, bool) -> void; + auto instructionBranchBit(n3, bool) -> void; auto instructionBranchNotDirect() -> void; auto instructionBranchNotDirectDecrement() -> void; - auto instructionBranchNotDirectIndexed(uint8&) -> void; + auto instructionBranchNotDirectIndexed(n8&) -> void; auto instructionBranchNotYDecrement() -> void; auto instructionBreak() -> void; auto instructionCallAbsolute() -> void; auto instructionCallPage() -> void; - auto instructionCallTable(uint4) -> void; + auto instructionCallTable(n4) -> void; auto instructionComplementCarry() -> void; auto instructionDecimalAdjustAdd() -> void; auto instructionDecimalAdjustSub() -> void; - auto instructionDirectRead(fpb, uint8&) -> void; + auto instructionDirectRead(fpb, n8&) -> void; auto instructionDirectModify(fps) -> void; - auto instructionDirectWrite(uint8&) -> void; + auto instructionDirectWrite(n8&) -> void; auto instructionDirectDirectCompare(fpb) -> void; auto instructionDirectDirectModify(fpb) -> void; auto instructionDirectDirectWrite() -> void; @@ -78,24 +78,24 @@ struct SPC700 { auto instructionDirectImmediateWrite() -> void; auto instructionDirectCompareWord(fpw) -> void; auto instructionDirectReadWord(fpw) -> void; - auto instructionDirectModifyWord(int) -> void; + auto instructionDirectModifyWord(s32) -> void; auto instructionDirectWriteWord() -> void; - auto instructionDirectIndexedRead(fpb, uint8&, uint8&) -> void; - auto instructionDirectIndexedModify(fps, uint8&) -> void; - auto instructionDirectIndexedWrite(uint8&, uint8&) -> void; + auto instructionDirectIndexedRead(fpb, n8&, n8&) -> void; + auto instructionDirectIndexedModify(fps, n8&) -> void; + auto instructionDirectIndexedWrite(n8&, n8&) -> void; auto instructionDivide() -> void; auto instructionExchangeNibble() -> void; auto instructionFlagSet(bool&, bool) -> void; - auto instructionImmediateRead(fpb, uint8&) -> void; - auto instructionImpliedModify(fps, uint8&) -> void; - auto instructionIndexedIndirectRead(fpb, uint8&) -> void; - auto instructionIndexedIndirectWrite(uint8&, uint8&) -> void; - auto instructionIndirectIndexedRead(fpb, uint8&) -> void; - auto instructionIndirectIndexedWrite(uint8&, uint8&) -> void; + auto instructionImmediateRead(fpb, n8&) -> void; + auto instructionImpliedModify(fps, n8&) -> void; + auto instructionIndexedIndirectRead(fpb, n8&) -> void; + auto instructionIndexedIndirectWrite(n8&, n8&) -> void; + auto instructionIndirectIndexedRead(fpb, n8&) -> void; + auto instructionIndirectIndexedWrite(n8&, n8&) -> void; auto instructionIndirectXRead(fpb) -> void; - auto instructionIndirectXWrite(uint8&) -> void; - auto instructionIndirectXIncrementRead(uint8&) -> void; - auto instructionIndirectXIncrementWrite(uint8&) -> void; + auto instructionIndirectXWrite(n8&) -> void; + auto instructionIndirectXIncrementRead(n8&) -> void; + auto instructionIndirectXIncrementWrite(n8&) -> void; auto instructionIndirectXCompareIndirectY(fpb) -> void; auto instructionIndirectXWriteIndirectY(fpb) -> void; auto instructionJumpAbsolute() -> void; @@ -103,21 +103,21 @@ struct SPC700 { auto instructionMultiply() -> void; auto instructionNoOperation() -> void; auto instructionOverflowClear() -> void; - auto instructionPull(uint8&) -> void; + auto instructionPull(n8&) -> void; auto instructionPullP() -> void; - auto instructionPush(uint8) -> void; + auto instructionPush(n8) -> void; auto instructionReturnInterrupt() -> void; auto instructionReturnSubroutine() -> void; auto instructionStop() -> void; auto instructionTestSetBitsAbsolute(bool) -> void; - auto instructionTransfer(uint8&, uint8&) -> void; + auto instructionTransfer(n8&, n8&) -> void; auto instructionWait() -> void; //serialization.cpp auto serialize(serializer&) -> void; //disassembler.cpp - noinline auto disassembleInstruction(uint16 address, uint1 p) -> string; + noinline auto disassembleInstruction(n16 address, n1 p) -> string; noinline auto disassembleInstruction() -> string; noinline auto disassembleContext() -> string; @@ -131,11 +131,11 @@ struct SPC700 { bool v; //overflow bool n; //negative - operator uint() const { + operator u32() const { return c << 0 | z << 1 | i << 2 | h << 3 | b << 4 | p << 5 | v << 6 | n << 7; } - auto& operator=(uint8 data) { + auto& operator=(n8 data) { c = data.bit(0); z = data.bit(1); i = data.bit(2); @@ -151,10 +151,10 @@ struct SPC700 { struct Registers { union Pair { Pair() : w(0) {} - uint16 w; - struct Byte { uint8 order_lsb2(l, h); } byte; + n16 w; + struct Byte { n8 order_lsb2(l, h); } byte; } pc, ya; - uint8 x, s; + n8 x, s; Flags p; bool wait = false; diff --git a/ares/component/processor/tlcs900h/algorithms.cpp b/ares/component/processor/tlcs900h/algorithms.cpp index 97a4cc953f..5c4e4d3cd4 100644 --- a/ares/component/processor/tlcs900h/algorithms.cpp +++ b/ares/component/processor/tlcs900h/algorithms.cpp @@ -1,11 +1,11 @@ -template<> auto TLCS900H::parity< uint8>( uint8 data) const -> bool { +template<> auto TLCS900H::parity(n8 data) const -> bool { data ^= data >> 4; data ^= data >> 2; data ^= data >> 1; return !(data & 1); } -template<> auto TLCS900H::parity(uint16 data) const -> bool { +template<> auto TLCS900H::parity(n16 data) const -> bool { data ^= data >> 8; data ^= data >> 4; data ^= data >> 2; @@ -13,13 +13,13 @@ template<> auto TLCS900H::parity(uint16 data) const -> bool { return !(data & 1); } -template<> auto TLCS900H::parity(uint32 data) const -> bool { +template<> auto TLCS900H::parity(n32 data) const -> bool { return Undefined; } // -template auto TLCS900H::algorithmAdd(T target, T source, uint1 carry) -> T { +template auto TLCS900H::algorithmAdd(T target, T source, n1 carry) -> T { T result = target + source + carry; T carries = target ^ source ^ result; T overflow = (target ^ result) & (source ^ result); @@ -93,7 +93,7 @@ template auto TLCS900H::algorithmShifted(T result) -> T { return result; } -template auto TLCS900H::algorithmSubtract(T target, T source, uint1 carry) -> T { +template auto TLCS900H::algorithmSubtract(T target, T source, n1 carry) -> T { T result = target - source - carry; T carries = target ^ source ^ result; T overflow = (target ^ result) & (source ^ target); diff --git a/ares/component/processor/tlcs900h/conditions.cpp b/ares/component/processor/tlcs900h/conditions.cpp index 420952d094..c39151a700 100644 --- a/ares/component/processor/tlcs900h/conditions.cpp +++ b/ares/component/processor/tlcs900h/conditions.cpp @@ -1,4 +1,4 @@ -auto TLCS900H::condition(uint4 code) -> bool { +auto TLCS900H::condition(n4 code) -> bool { switch(code) { case 0: return 0 == 1; //F (false) case 1: return (SF ^ VF) == 1; //LT (signed less than) diff --git a/ares/component/processor/tlcs900h/control-registers.cpp b/ares/component/processor/tlcs900h/control-registers.cpp index 3ddccfdb1f..97a39ca3ac 100644 --- a/ares/component/processor/tlcs900h/control-registers.cpp +++ b/ares/component/processor/tlcs900h/control-registers.cpp @@ -1,4 +1,4 @@ -template<> auto TLCS900H::map(ControlRegister register) const -> maybe { +template<> auto TLCS900H::map(ControlRegister register) const -> maybe { switch(register.id) { #define r(id, name) case id: return r.name; r(0x00, dmas[0].b.b0) r(0x01, dmas[0].b.b1) r(0x02, dmas[0].b.b2) r(0x03, dmas[0].b.b3) @@ -19,7 +19,7 @@ template<> auto TLCS900H::map(ControlRegister register) const -> maybe auto TLCS900H::map(ControlRegister register) const -> maybe { +template<> auto TLCS900H::map(ControlRegister register) const -> maybe { switch(register.id & ~1) { #define r(id, name) case id: return r.name; r(0x00, dmas[0].w.w0) r(0x02, dmas[0].w.w1) @@ -40,7 +40,7 @@ template<> auto TLCS900H::map(ControlRegister register) const -> maybe auto TLCS900H::map(ControlRegister register) const -> maybe { +template<> auto TLCS900H::map(ControlRegister register) const -> maybe { switch(register.id & ~1) { #define r(id, name) case id: return r.name; r(0x00, dmas[0].l.l0) @@ -61,20 +61,20 @@ template<> auto TLCS900H::map(ControlRegister register) const -> maybe auto TLCS900H::load< uint8>(ControlRegister< uint8> register) const -> uint8 { return map(register)(Undefined); } -template<> auto TLCS900H::load(ControlRegister register) const -> uint16 { return map(register)(Undefined); } -template<> auto TLCS900H::load(ControlRegister register) const -> uint32 { return map(register)(Undefined); } +template<> auto TLCS900H::load(ControlRegister register) const -> n8 { return map(register)(Undefined); } +template<> auto TLCS900H::load(ControlRegister register) const -> n16 { return map(register)(Undefined); } +template<> auto TLCS900H::load(ControlRegister register) const -> n32 { return map(register)(Undefined); } -template<> auto TLCS900H::store(ControlRegister register, uint32 data) -> void { +template<> auto TLCS900H::store(ControlRegister register, n32 data) -> void { if(auto r = map(register)) r() = data; } -template<> auto TLCS900H::store(ControlRegister register, uint32 data) -> void { +template<> auto TLCS900H::store(ControlRegister register, n32 data) -> void { if(auto r = map(register)) r() = data; } -template<> auto TLCS900H::store(ControlRegister register, uint32 data) -> void { +template<> auto TLCS900H::store(ControlRegister register, n32 data) -> void { //INTNEST is 16-bit: this isn't the nicest way to handle this, but ... - if((register.id & ~3) == 0x3c) data = (uint16)data; + if((register.id & ~3) == 0x3c) data = (n16)data; if(auto r = map(register)) r() = data; } diff --git a/ares/component/processor/tlcs900h/disassembler.cpp b/ares/component/processor/tlcs900h/disassembler.cpp index 900823c0de..3aa060d8be 100644 --- a/ares/component/processor/tlcs900h/disassembler.cpp +++ b/ares/component/processor/tlcs900h/disassembler.cpp @@ -2,14 +2,14 @@ auto TLCS900H::disassembleInstruction() -> string { string output; auto pc = r.pc.l.l0; - uint8 op[8] = {}, ops = 0; + n8 op[8] = {}, ops = 0; - auto read8 = [&]() -> uint8 { return op[ops++] = disassembleRead(pc++); }; - auto read16 = [&]() -> uint16 { uint16 data = read8(); return data | read8() << 8; }; - auto read24 = [&]() -> uint24 { uint24 data = read8(); data |= read8() << 8; return data | read8() << 16; }; - auto read32 = [&]() -> uint32 { uint32 data = read8(); data |= read8() << 8; data |= read8() << 16; return data | read8() << 24; }; + auto read8 = [&]() -> n8 { return op[ops++] = disassembleRead(pc++); }; + auto read16 = [&]() -> n16 { n16 data = read8(); return data | read8() << 8; }; + auto read24 = [&]() -> n24 { n24 data = read8(); data |= read8() << 8; return data | read8() << 16; }; + auto read32 = [&]() -> n32 { n32 data = read8(); data |= read8() << 8; data |= read8() << 16; return data | read8() << 24; }; - enum : uint { + enum : u32 { Null, Text, //text Condition, //condition @@ -49,26 +49,26 @@ auto TLCS900H::disassembleInstruction() -> string { auto null() -> void { mode(Null); } auto text(string text_) -> void { mode(Text); _text = text_; } - auto condition(uint4 condition_) -> void { mode(Condition); _condition = condition_; } - auto register(natural size_, uint8 register_) -> void { mode(Register); size(size_); _register = register_; } - auto register3(natural size_, uint3 register_) -> void { mode(Register); size(size_); _register = lookup(size_, register_); } - auto control(natural size_, uint8 register_) -> void { mode(Control); size(size_); _register = register_; } + auto condition(n4 condition_) -> void { mode(Condition); _condition = condition_; } + auto register(natural size_, n8 register_) -> void { mode(Register); size(size_); _register = register_; } + auto register3(natural size_, n3 register_) -> void { mode(Register); size(size_); _register = lookup(size_, register_); } + auto control(natural size_, n8 register_) -> void { mode(Control); size(size_); _register = register_; } auto immediate(natural size_, natural immediate_) -> void { mode(Immediate); size(size_); _immediate = immediate_; } auto displacement(natural size_, natural displacement_) -> void { mode(Displacement); size(size_); _displacement = displacement_; } auto displacementPC(natural size_, natural displacement_) -> void { mode(DisplacementPC); size(size_); _displacement = displacement_; } - auto indirectRegister(natural size_, uint8 register_) -> void { mode(IndirectRegister); size(size_); _register = register_; } - auto indirectRegister3(natural size_, uint3 register_) -> void { mode(IndirectRegister); size(size_); _register = lookup(32, register_); } - auto indirectRegisterDecrement(natural size_, uint8 register_) -> void { mode(IndirectRegisterDecrement); size(size_); _register = register_; } - auto indirectRegisterIncrement(natural size_, uint8 register_) -> void { mode(IndirectRegisterIncrement); size(size_); _register = register_; } - auto indirectRegister3Increment(natural size_, uint3 register_) -> void { mode(IndirectRegisterIncrement); size(size_); _register = lookup(32, register_); } - auto indirectRegisterRegister8(natural size_, uint8 register32, uint8 register8) -> void { mode(IndirectRegisterRegister8); size(size_); _register = register32; _registerAdd = register8; } - auto indirectRegisterRegister16(natural size_, uint8 register32, uint8 register16) -> void { mode(IndirectRegisterRegister16); size(size_); _register = register32; _registerAdd = register16; } - auto indirectRegister3Displacement8(natural size_, uint3 register_, uint8 displacement_) -> void { mode(IndirectRegisterDisplacement8); size(size_); _register = lookup(32, register_); _displacement = displacement_; } - auto indirectRegisterDisplacement16(natural size_, uint8 register_, uint16 displacement_) -> void { mode(IndirectRegisterDisplacement16); size(size_); _register = register_; _displacement = displacement_; } - auto indirectImmediate8(natural size_, uint8 immediate_) -> void { mode(IndirectImmediate8); size(size_); _immediate = immediate_; } - auto indirectImmediate16(natural size_, uint16 immediate_) -> void { mode(IndirectImmediate16); size(size_); _immediate = immediate_; } - auto indirectImmediate24(natural size_, uint24 immediate_) -> void { mode(IndirectImmediate24); size(size_); _immediate = immediate_; } + auto indirectRegister(natural size_, n8 register_) -> void { mode(IndirectRegister); size(size_); _register = register_; } + auto indirectRegister3(natural size_, n3 register_) -> void { mode(IndirectRegister); size(size_); _register = lookup(32, register_); } + auto indirectRegisterDecrement(natural size_, n8 register_) -> void { mode(IndirectRegisterDecrement); size(size_); _register = register_; } + auto indirectRegisterIncrement(natural size_, n8 register_) -> void { mode(IndirectRegisterIncrement); size(size_); _register = register_; } + auto indirectRegister3Increment(natural size_, n3 register_) -> void { mode(IndirectRegisterIncrement); size(size_); _register = lookup(32, register_); } + auto indirectRegisterRegister8(natural size_, n8 register32, n8 register8) -> void { mode(IndirectRegisterRegister8); size(size_); _register = register32; _registerAdd = register8; } + auto indirectRegisterRegister16(natural size_, n8 register32, n8 register16) -> void { mode(IndirectRegisterRegister16); size(size_); _register = register32; _registerAdd = register16; } + auto indirectRegister3Displacement8(natural size_, n3 register_, n8 displacement_) -> void { mode(IndirectRegisterDisplacement8); size(size_); _register = lookup(32, register_); _displacement = displacement_; } + auto indirectRegisterDisplacement16(natural size_, n8 register_, n16 displacement_) -> void { mode(IndirectRegisterDisplacement16); size(size_); _register = register_; _displacement = displacement_; } + auto indirectImmediate8(natural size_, n8 immediate_) -> void { mode(IndirectImmediate8); size(size_); _immediate = immediate_; } + auto indirectImmediate16(natural size_, n16 immediate_) -> void { mode(IndirectImmediate16); size(size_); _immediate = immediate_; } + auto indirectImmediate24(natural size_, n24 immediate_) -> void { mode(IndirectImmediate24); size(size_); _immediate = immediate_; } private: natural _mode = Null; @@ -80,7 +80,7 @@ auto TLCS900H::disassembleInstruction() -> string { natural _immediate; natural _displacement; - static auto lookup(natural size, uint3 register) -> uint8 { + static auto lookup(natural size, n3 register) -> n8 { if(size == 8) return from_array<0xe1, 0xe0, 0xe5, 0xe4, 0xe9, 0xe8, 0xed, 0xec>(register); if(size == 16) return from_array<0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf4, 0xf8, 0xfc>(register); if(size == 32) return from_array<0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf4, 0xf8, 0xfc>(register); @@ -101,7 +101,7 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x03: name = "pop"; lhs.text("sr"); break; case 0x04: break; //"max" or "min" (not present on 900/H) case 0x05: name = "halt"; break; - case 0x06: name = "ei"; lhs.immediate(3, (uint3)read8()); if(lhs.immediate() == 7) name = "di", lhs.null(); break; + case 0x06: name = "ei"; lhs.immediate(3, (n3)read8()); if(lhs.immediate() == 7) name = "di", lhs.null(); break; case 0x07: name = "reti"; break; case 0x08: name = "ld"; lhs.indirectImmediate8(8, read8()); rhs.immediate(8, read8()); break; case 0x09: name = "push"; lhs.immediate(8, read8()); break; @@ -118,7 +118,7 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x14: name = "push"; lhs.register3(8, A.id); break; case 0x15: name = "pop"; lhs.register3(8, A.id); break; case 0x16: name = "ex"; lhs.text("f"); rhs.text("f'"); break; - case 0x17: name = "ldf"; lhs.immediate(2, (uint2)read8()); break; + case 0x17: name = "ldf"; lhs.immediate(2, (n2)read8()); break; case 0x18: name = "push"; lhs.text("f"); break; case 0x19: name = "pop"; lhs.text("f"); break; case 0x1a: name = "jp"; lhs.immediate(16, read16()); break; @@ -176,14 +176,14 @@ auto TLCS900H::disassembleInstruction() -> string { case 0xc3: case 0xd3: case 0xe3: case 0xf3: { opSourceMemory = fetch < 0xf0; opTargetMemory = !opSourceMemory; auto data = read8(); - if((uint2)data == 0) lhs.indirectRegister(opSize, data); - if((uint2)data == 1) lhs.indirectRegisterDisplacement16(opSize, data, read16()); + if((n2)data == 0) lhs.indirectRegister(opSize, data); + if((n2)data == 1) lhs.indirectRegisterDisplacement16(opSize, data, read16()); if(data == 0x03) { auto r32 = read8(); lhs.indirectRegisterRegister8(opSize, r32, read8()); } if(data == 0x07) { auto r32 = read8(); lhs.indirectRegisterRegister16(opSize, r32, read8()); } if(data == 0x17 && opTargetMemory) { opTargetMemory = false; name = "ldar"; - int16 d16 = read16(); + i16 d16 = read16(); data = read8(); if((data & 0xf8) == 0x20) { lhs.register3(16, data); @@ -217,12 +217,12 @@ auto TLCS900H::disassembleInstruction() -> string { case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef: opRegister = true; lhs.register3(32, fetch); break; case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: - name = "swi"; lhs.immediate(3, (uint3)fetch); break; + name = "swi"; lhs.immediate(3, (n3)fetch); break; } #undef opSize - auto reads = [&](uint size) -> uint32 { - if(size == 8) return read8(); + auto reads = [&](u32 size) -> n32 { + if(size == 8 ) return read8 (); if(size == 16) return read16(); if(size == 24) return read24(); if(size == 32) return read32(); @@ -258,11 +258,11 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x1a: case 0x1b: break; case 0x1c: name = "djnz"; rhs.displacementPC(8, read8()); break; case 0x1d: case 0x1e: case 0x1f: break; - case 0x20: name = "andcf"; rhs.immediate(4, (uint4)read8()); break; - case 0x21: name = "orcf"; rhs.immediate(4, (uint4)read8()); break; - case 0x22: name = "xorcf"; rhs.immediate(4, (uint4)read8()); break; - case 0x23: name = "ldcf"; rhs.immediate(4, (uint4)read8()); break; - case 0x24: name = "stcf"; rhs.immediate(4, (uint4)read8()); break; + case 0x20: name = "andcf"; rhs.immediate(4, (n4)read8()); break; + case 0x21: name = "orcf"; rhs.immediate(4, (n4)read8()); break; + case 0x22: name = "xorcf"; rhs.immediate(4, (n4)read8()); break; + case 0x23: name = "ldcf"; rhs.immediate(4, (n4)read8()); break; + case 0x24: name = "stcf"; rhs.immediate(4, (n4)read8()); break; case 0x25: case 0x26: case 0x27: break; case 0x28: name = "andcf"; rhs.register(8, A.id); break; case 0x29: name = "orcf"; rhs.register(8, A.id); break; @@ -272,11 +272,11 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x2d: break; case 0x2e: name = "ldc"; rhs = lhs; lhs.control(rhs.size(), read8()); break; case 0x2f: name = "ldc"; rhs.control(lhs.size(), read8()); break; - case 0x30: name = "res"; rhs.immediate(4, (uint4)read8()); break; - case 0x31: name = "set"; rhs.immediate(4, (uint4)read8()); break; - case 0x32: name = "chg"; rhs.immediate(4, (uint4)read8()); break; - case 0x33: name = "bit"; rhs.immediate(4, (uint4)read8()); break; - case 0x34: name = "tset"; rhs.immediate(4, (uint4)read8()); break; + case 0x30: name = "res"; rhs.immediate(4, (n4)read8()); break; + case 0x31: name = "set"; rhs.immediate(4, (n4)read8()); break; + case 0x32: name = "chg"; rhs.immediate(4, (n4)read8()); break; + case 0x33: name = "bit"; rhs.immediate(4, (n4)read8()); break; + case 0x34: name = "tset"; rhs.immediate(4, (n4)read8()); break; case 0x35: case 0x36: case 0x37: break; case 0x38: name = "minc1"; rhs.immediate(16, read16()); break; case 0x39: name = "minc2"; rhs.immediate(16, read16()); break; @@ -295,9 +295,9 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: name = "divs"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: - name = "inc"; rhs.immediate(4, fetch ? natural((uint3)fetch) : 8_n); break; + name = "inc"; rhs.immediate(4, fetch ? natural((n3)fetch) : 8_n); break; case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: - name = "dec"; rhs.immediate(4, fetch ? natural((uint3)fetch) : 8_n); break; + name = "dec"; rhs.immediate(4, fetch ? natural((n3)fetch) : 8_n); break; case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: name = "scc"; rhs = lhs; lhs.condition(fetch); break; @@ -312,7 +312,7 @@ auto TLCS900H::disassembleInstruction() -> string { case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: name = "sub"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: - name = "ld"; rhs.immediate(3, (uint3)fetch); break; + name = "ld"; rhs.immediate(3, (n3)fetch); break; case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: name = "sbb"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: @@ -330,7 +330,7 @@ auto TLCS900H::disassembleInstruction() -> string { case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7: name = "xor"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: - name = "cp"; rhs.immediate(3, (uint3)fetch); break; + name = "cp"; rhs.immediate(3, (n3)fetch); break; case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: name = "or"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0xe8: name = "rlc"; { auto data = read8(); rhs.immediate(5, data ? natural(data) : 16_n); } break; @@ -364,23 +364,23 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: break; case 0x10: name = lhs.size() == 8 ? "ldi" : "ldiw"; - lhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XDE.id : XIX.id); - rhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XHL.id : XIY.id); + lhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XDE.id : XIX.id); + rhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XHL.id : XIY.id); break; case 0x11: name = lhs.size() == 8 ? "ldir" : "ldirw"; - lhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XDE.id : XIX.id); - rhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XHL.id : XIY.id); + lhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XDE.id : XIX.id); + rhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XHL.id : XIY.id); break; case 0x12: name = lhs.size() == 8 ? "ldd" : "lddw"; - lhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XDE.id : XIX.id); - rhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XHL.id : XIY.id); + lhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XDE.id : XIX.id); + rhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XHL.id : XIY.id); break; case 0x13: name = lhs.size() == 8 ? "lddr" : "lddrw"; - lhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XDE.id : XIX.id); - rhs.indirectRegisterIncrement(32, (uint3)op[0] != 5 ? XHL.id : XIY.id); + lhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XDE.id : XIX.id); + rhs.indirectRegisterIncrement(32, (n3)op[0] != 5 ? XHL.id : XIY.id); break; case 0x14: name = lhs.size() == 8 ? "cpi" : "cpiw"; @@ -427,9 +427,9 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: name = "divs"; rhs = lhs; lhs.register3(rhs.size(), fetch); break; case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: - name = "inc"; rhs.immediate(4, (uint3)fetch ? natural((uint3)fetch) : 8_n); break; + name = "inc"; rhs.immediate(4, (n3)fetch ? natural((n3)fetch) : 8_n); break; case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: - name = "dec"; rhs.immediate(4, (uint3)fetch ? natural((uint3)fetch) : 8_n); break; + name = "dec"; rhs.immediate(4, (n3)fetch ? natural((n3)fetch) : 8_n); break; case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: break; case 0x78: name = "rlc"; break; case 0x79: name = "rrc"; break; @@ -512,25 +512,25 @@ auto TLCS900H::disassembleInstruction() -> string { case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: break; case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: break; case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: - name = "andcf"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "andcf"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: - name = "orcf"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "orcf"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: - name = "xorcf"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "xorcf"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: - name = "ldcf"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "ldcf"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: - name = "stcf"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "stcf"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: - name = "tset"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "tset"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: - name = "res"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "res"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: - name = "set"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "set"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: - name = "chg"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "chg"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: - name = "bit"; lhs.size(8); rhs.immediate(3, (uint3)fetch); break; + name = "bit"; lhs.size(8); rhs.immediate(3, (n3)fetch); break; case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7: case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: name = "jp"; lhs.size(32); rhs = lhs; lhs.condition(fetch); break; @@ -552,7 +552,7 @@ auto TLCS900H::disassembleInstruction() -> string { "a", "w", "qa", "qw", "c", "b", "qc", "qb", "e", "d", "qe", "qd", "l", "h", "ql", "qh", //e0-ef "ixl", "ixh", "qixl","qixh","iyl", "iyh", "qiyl","qiyh","izl", "izh", "qizl","qizh","spl", "sph", "qspl","qsph", //f0-ff }; - auto register8 = [&](uint8 register) -> string { + auto register8 = [&](n8 register) -> string { if(register < 0x40) return registers8[register]; if(register >= 0xd0) return registers8[(register - 0xd0 >> 0) + 0x40]; return "rb?"; @@ -567,7 +567,7 @@ auto TLCS900H::disassembleInstruction() -> string { "wa", "qwa", "bc", "qbc", "de", "qde", "hl", "qhl", //e0-ef "ix", "qix", "iy", "qiy", "iz", "qiz", "sp", "qsp", //f0-ff }; - auto register16 = [&](uint8 register) -> string { + auto register16 = [&](n8 register) -> string { if(register < 0x40) return registers16[register >> 1]; if(register >= 0xd0) return registers16[(register - 0xd0 >> 1) + 0x20]; return "rw?"; @@ -582,21 +582,21 @@ auto TLCS900H::disassembleInstruction() -> string { "xwa", "xbc", "xde", "xhl", //e0-ef "xix", "xiy", "xiz", "xsp", //f0-ff }; - auto register32 = [&](uint8 register) -> string { + auto register32 = [&](n8 register) -> string { if(register < 0x40) return registers32[register >> 2]; if(register >= 0xd0) return registers32[(register - 0xd0 >> 2) + 0x10]; return "rl?"; }; - auto registerSize = [&](natural size, uint8 register) -> string { - if(size == 8) return register8 (register); + auto registerSize = [&](natural size, n8 register) -> string { + if(size == 8 ) return register8 (register); if(size == 16) return register16(register); if(size == 32) return register32(register); return "r??"; }; //there are no names for byte-accesses to control registers - auto control8 = [&](uint8 register) -> string { + auto control8 = [&](n8 register) -> string { return {"c", hex(register, 2L)}; }; @@ -605,7 +605,7 @@ auto TLCS900H::disassembleInstruction() -> string { "dmad0l", "dmad0h", "dmad1l", "dmad1h", "dmad2l", "dmad2h", "dmad3l", "dmad3h", //10-1f "dmac0", "dmac0h", "dmac1", "dmac1h", "dmac2", "dmac2h", "dmac3", "dmac3h", //20-2f }; - auto control16 = [&](uint8 register) -> string { + auto control16 = [&](n8 register) -> string { if(register < 0x30) return controls16[register >> 1]; if(register >= 0x3c || register <= 0x3d) return "intnest"; return "cw?"; @@ -616,14 +616,14 @@ auto TLCS900H::disassembleInstruction() -> string { "dmad0", "dmad1", "dmad2", "dmad3", //10-1f "dmam0", "dmam1", "dmam2", "dmam3", //20-2f }; - auto control32 = [&](uint8 register) -> string { + auto control32 = [&](n8 register) -> string { if(register < 0x30) return controls32[register >> 2]; if(register >= 0x3c && register <= 0x3f) return "intnest"; return "cl?"; }; - auto controlSize = [&](natural size, uint8 register) -> string { - if(size == 8) return control8 (register); + auto controlSize = [&](natural size, n8 register) -> string { + if(size == 8 ) return control8 (register); if(size == 16) return control16(register); if(size == 32) return control32(register); return "c??"; @@ -648,23 +648,23 @@ auto TLCS900H::disassembleInstruction() -> string { } if(operand.mode() == Displacement) { if(operand.size() == 8) { - integer displacement = (int8)operand.displacement(); + integer displacement = (i8)operand.displacement(); if(displacement < 0) return {"-0x", hex(-displacement, 2L)}; if(displacement >= 0) return {"+0x", hex(+displacement, 2L)}; } if(operand.size() == 16) { - integer displacement = (int8)operand.displacement(); + integer displacement = (i8)operand.displacement(); if(displacement < 0) return {"-0x", hex(-displacement, 4L)}; if(displacement >= 0) return {"+0x", hex(+displacement, 4L)}; } } if(operand.mode() == DisplacementPC) { if(operand.size() == 8) { - natural displacement = pc + (int8)operand.displacement(); + natural displacement = pc + (i8)operand.displacement(); return {"0x", hex(displacement, 6L)}; } if(operand.size() == 16) { - natural displacement = pc + (int16)operand.displacement(); + natural displacement = pc + (i16)operand.displacement(); return {"0x", hex(displacement, 6L)}; } } @@ -674,13 +674,13 @@ auto TLCS900H::disassembleInstruction() -> string { if(operand.mode() == IndirectRegisterRegister8) return {"(", register32(operand.register()), "+", register8(operand.registerAdd()), ")"}; if(operand.mode() == IndirectRegisterRegister16) return {"(", register32(operand.register()), "+", register16(operand.registerAdd()), ")"}; if(operand.mode() == IndirectRegisterDisplacement8) { - integer displacement = (int8)operand.displacement(); + integer displacement = (i8)operand.displacement(); if(displacement == 0) return {"(", register32(operand.register()), ")"}; if(displacement < 0) return {"(", register32(operand.register()), "-0x", hex(-displacement, 2L), ")"}; if(displacement > 0) return {"(", register32(operand.register()), "+0x", hex(+displacement, 2L), ")"}; } if(operand.mode() == IndirectRegisterDisplacement16) { - integer displacement = (int16)operand.displacement(); + integer displacement = (i16)operand.displacement(); if(displacement == 0) return {"(", register32(operand.register()), ")"}; if(displacement < 0) return {"(", register32(operand.register()), "-0x", hex(-displacement, 4L), ")"}; if(displacement > 0) return {"(", register32(operand.register()), "+0x", hex(+displacement, 4L), ")"}; diff --git a/ares/component/processor/tlcs900h/dma.cpp b/ares/component/processor/tlcs900h/dma.cpp index a2de3a1bcf..45bdca3101 100644 --- a/ares/component/processor/tlcs900h/dma.cpp +++ b/ares/component/processor/tlcs900h/dma.cpp @@ -1,11 +1,11 @@ -auto TLCS900H::dma(uint2 channel) -> bool { +auto TLCS900H::dma(n2 channel) -> bool { auto& source = r.dmas[channel].l.l0; auto& target = r.dmad[channel].l.l0; auto& length = r.dmam[channel].w.w0; //0 = 65536 auto& config = r.dmam[channel].w.w1; - uint32 mode = config.bit(2,4); - uint32 size; + n32 mode = config.bit(2,4); + n32 size; switch(config.bit(0,1)) { case 0: size = Byte; break; case 1: size = Word; break; diff --git a/ares/component/processor/tlcs900h/instruction.cpp b/ares/component/processor/tlcs900h/instruction.cpp index 6152d18374..ddd97ea871 100644 --- a/ares/component/processor/tlcs900h/instruction.cpp +++ b/ares/component/processor/tlcs900h/instruction.cpp @@ -3,41 +3,41 @@ #pragma clang diagnostic ignored "-Wunused-value" #endif -template auto TLCS900H::idleBW(uint b, uint w) -> void { +template auto TLCS900H::idleBW(u32 b, u32 w) -> void { if constexpr(Bits == 8) return idle(b); if constexpr(Bits == 16) return idle(w); } -template auto TLCS900H::idleWL(uint w, uint l) -> void { +template auto TLCS900H::idleWL(u32 w, u32 l) -> void { if constexpr(Bits == 16) return idle(w); if constexpr(Bits == 32) return idle(l); } -template auto TLCS900H::idleBWL(uint b, uint w, uint l) -> void { +template auto TLCS900H::idleBWL(u32 b, u32 w, u32 l) -> void { if constexpr(Bits == 8) return idle(b); if constexpr(Bits == 16) return idle(w); if constexpr(Bits == 32) return idle(l); } -template<> auto TLCS900H::toRegister3(uint3 code) const -> Register { - static const Register< uint8> lookup[] = {W, A, B, C, D, E, H, L}; +template<> auto TLCS900H::toRegister3(n3 code) const -> Register { + static const Register lookup[] = {W, A, B, C, D, E, H, L}; return lookup[code]; } -template<> auto TLCS900H::toRegister3(uint3 code) const -> Register { - static const Register lookup[] = {WA, BC, DE, HL, IX, IY, IZ, SP}; +template<> auto TLCS900H::toRegister3(n3 code) const -> Register { + static const Register lookup[] = {WA, BC, DE, HL, IX, IY, IZ, SP}; return lookup[code]; } -template<> auto TLCS900H::toRegister3(uint3 code) const -> Register { - static const Register lookup[] = {XWA, XBC, XDE, XHL, XIX, XIY, XIZ, XSP}; +template<> auto TLCS900H::toRegister3(n3 code) const -> Register { + static const Register lookup[] = {XWA, XBC, XDE, XHL, XIX, XIY, XIZ, XSP}; return lookup[code]; } -template auto TLCS900H::toRegister8(uint8 code) const -> Register { return {code}; } -template auto TLCS900H::toControlRegister(uint8 code) const -> ControlRegister { return {code}; } -template auto TLCS900H::toMemory(uint32 address) const -> Memory { return {address}; } -template auto TLCS900H::toImmediate(uint32 constant) const -> Immediate { return {constant}; } +template auto TLCS900H::toRegister8(n8 code) const -> Register { return {code}; } +template auto TLCS900H::toControlRegister(n8 code) const -> ControlRegister { return {code}; } +template auto TLCS900H::toMemory(n32 address) const -> Memory { return {address}; } +template auto TLCS900H::toImmediate(n32 constant) const -> Immediate { return {constant}; } template auto TLCS900H::toImmediate3(natural constant) const -> Immediate { return {constant.clip(3) ? constant.clip(3) : 8}; } //note: much of this code is split to multiple statements due to C++ not guaranteeing @@ -67,22 +67,22 @@ auto TLCS900H::instruction() -> void { case 0x05: return instructionHalt(); case 0x06: - return instructionSetInterruptFlipFlop((uint3)fetch()); + return instructionSetInterruptFlipFlop((n3)fetch()); case 0x07: return instructionReturnInterrupt(); case 0x08: { - auto memory = fetchMemory(); + auto memory = fetchMemory(); idle(1); - return instructionLoad(memory, fetchImmediate()); } + return instructionLoad(memory, fetchImmediate()); } case 0x09: - return instructionPush(fetchImmediate()); + return instructionPush(fetchImmediate()); case 0x0a: { - auto memory = fetchMemory(); + auto memory = fetchMemory(); idle(2); - return instructionLoad(memory, fetchImmediate()); } + return instructionLoad(memory, fetchImmediate()); } case 0x0b: idle(1); - return instructionPush(fetchImmediate()); + return instructionPush(fetchImmediate()); case 0x0c: return instructionSetRegisterFilePointer(RFP + 1); case 0x0d: @@ -90,7 +90,7 @@ auto TLCS900H::instruction() -> void { case 0x0e: return instructionReturn(); case 0x0f: - return instructionReturnDeallocate(fetchImmediate()); + return instructionReturnDeallocate(fetchImmediate()); case 0x10: return instructionSetCarryFlag(0); case 0x11: @@ -108,7 +108,7 @@ auto TLCS900H::instruction() -> void { case 0x16: return instructionExchange(F, FP); case 0x17: - return instructionSetRegisterFilePointer((uint2)fetch()); + return instructionSetRegisterFilePointer((n2)fetch()); case 0x18: idle(1); return instructionPush(F); @@ -116,287 +116,287 @@ auto TLCS900H::instruction() -> void { idle(2); return instructionPop(F); case 0x1a: - return instructionJump(fetchImmediate()); + return instructionJump(fetchImmediate()); case 0x1b: idle(1); - return instructionJump(fetchImmediate()); + return instructionJump(fetchImmediate()); case 0x1c: - return instructionCall(fetchImmediate()); + return instructionCall(fetchImmediate()); case 0x1d: idle(1); - return instructionCall(fetchImmediate()); + return instructionCall(fetchImmediate()); case 0x1e: - return instructionCallRelative(fetchImmediate()); + return instructionCallRelative(fetchImmediate()); case 0x1f: return undefined(); case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: - return instructionLoad(toRegister3(data), fetchImmediate()); + return instructionLoad(toRegister3(data), fetchImmediate()); case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: idle(1); - return instructionPush(toRegister3(data)); + return instructionPush(toRegister3(data)); case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: idle(1); - return instructionLoad(toRegister3(data), fetchImmediate()); + return instructionLoad(toRegister3(data), fetchImmediate()); case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: idle(1); - return instructionPush(toRegister3(data)); + return instructionPush(toRegister3(data)); case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: idle(3); - return instructionLoad(toRegister3(data), fetchImmediate()); + return instructionLoad(toRegister3(data), fetchImmediate()); case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: idle(2); - return instructionPop(toRegister3(data)); + return instructionPop(toRegister3(data)); case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: return undefined(); case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: idle(4); - return instructionPop(toRegister3(data)); + return instructionPop(toRegister3(data)); case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: { - auto immediate = fetchImmediate(); - if(!condition((uint4)data)) return; + auto immediate = fetchImmediate(); + if(!condition((n4)data)) return; return instructionJumpRelative(immediate); } case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: { - auto immediate = fetchImmediate(); - if(!condition((uint4)data)) return; + auto immediate = fetchImmediate(); + if(!condition((n4)data)) return; return instructionJumpRelative(immediate); } case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: - return instructionSourceMemory(toMemory(load(toRegister3(data)))); + return instructionSourceMemory(toMemory(load(toRegister3(data)))); case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: idle(1); - return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: - return instructionSourceMemory(toMemory(load(toRegister3(data)))); + return instructionSourceMemory(toMemory(load(toRegister3(data)))); case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: idle(1); - return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: - return instructionSourceMemory(toMemory(load(toRegister3(data)))); + return instructionSourceMemory(toMemory(load(toRegister3(data)))); case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: idle(1); - return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister3(data)) + fetch())); case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: - return instructionTargetMemory(load(toRegister3(data))); + return instructionTargetMemory(load(toRegister3(data))); case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: idle(1); - return instructionTargetMemory(load(toRegister3(data)) + fetch()); + return instructionTargetMemory(load(toRegister3(data)) + fetch()); case 0xc0: idle(1); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xc1: idle(2); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xc2: idle(3); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xc3: { data = fetch(); if((data & 3) == 0) { idle(1); - return instructionSourceMemory(toMemory(load(toRegister8(data)))); + return instructionSourceMemory(toMemory(load(toRegister8(data)))); } if((data & 3) == 1) { idle(3); - return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); } if(data == 0x03) { - auto r32 = load(fetchRegister()); - auto r8 = load(fetchRegister< uint8>()); + auto r32 = load(fetchRegister()); + auto r8 = load(fetchRegister()); idle(3); - return instructionSourceMemory(Memory{r32 + (int8)r8}); + return instructionSourceMemory(Memory{r32 + (i8)r8}); } if(data == 0x07) { - auto r32 = load(fetchRegister()); - auto r16 = load(fetchRegister()); + auto r32 = load(fetchRegister()); + auto r16 = load(fetchRegister()); idle(3); - return instructionSourceMemory(Memory{r32 + (int16)r16}); + return instructionSourceMemory(Memory{r32 + (i16)r16}); } return undefined(); } case 0xc4: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location -= 1); if((data & 3) == 1) store(register, location -= 2); if((data & 3) == 2) store(register, location -= 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xc5: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location + 1); if((data & 3) == 1) store(register, location + 2); if((data & 3) == 2) store(register, location + 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xc6: return undefined(); case 0xc7: - return instructionRegister(fetchRegister()); + return instructionRegister(fetchRegister()); case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: - return instructionRegister(toRegister3(data)); + return instructionRegister(toRegister3(data)); case 0xd0: idle(1); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xd1: idle(2); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xd2: idle(3); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xd3: { data = fetch(); if((data & 3) == 0) { idle(1); - return instructionSourceMemory(toMemory(load(toRegister8(data)))); + return instructionSourceMemory(toMemory(load(toRegister8(data)))); } if((data & 3) == 1) { idle(3); - return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); } if(data == 0x03) { - auto r32 = load(fetchRegister()); - auto r8 = load(fetchRegister< uint8>()); + auto r32 = load(fetchRegister()); + auto r8 = load(fetchRegister()); idle(3); - return instructionSourceMemory(toMemory(r32 + (int8)r8)); + return instructionSourceMemory(toMemory(r32 + (i8)r8)); } if(data == 0x07) { - auto r32 = load(fetchRegister()); - auto r16 = load(fetchRegister()); + auto r32 = load(fetchRegister()); + auto r16 = load(fetchRegister()); idle(3); - return instructionSourceMemory(toMemory(r32 + (int16)r16)); + return instructionSourceMemory(toMemory(r32 + (i16)r16)); } return undefined(); } case 0xd4: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location -= 1); if((data & 3) == 1) store(register, location -= 2); if((data & 3) == 2) store(register, location -= 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xd5: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location + 1); if((data & 3) == 1) store(register, location + 2); if((data & 3) == 2) store(register, location + 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xd6: return undefined(); case 0xd7: - return instructionRegister(fetchRegister()); + return instructionRegister(fetchRegister()); case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: - return instructionRegister(toRegister3(data)); + return instructionRegister(toRegister3(data)); case 0xe0: idle(1); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xe1: idle(2); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xe2: idle(3); - return instructionSourceMemory(fetchMemory()); + return instructionSourceMemory(fetchMemory()); case 0xe3: { data = fetch(); if((data & 3) == 0) { idle(1); - return instructionSourceMemory(toMemory(load(toRegister8(data)))); + return instructionSourceMemory(toMemory(load(toRegister8(data)))); } if((data & 3) == 1) { idle(3); - return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); + return instructionSourceMemory(toMemory(load(toRegister8(data)) + fetch())); } if(data == 0x03) { - auto r32 = load(fetchRegister()); - auto r8 = load(fetchRegister< uint8>()); + auto r32 = load(fetchRegister()); + auto r8 = load(fetchRegister()); idle(3); - return instructionSourceMemory(toMemory(r32 + (int8)r8)); + return instructionSourceMemory(toMemory(r32 + (i8)r8)); } if(data == 0x07) { - auto r32 = load(fetchRegister()); - auto r16 = load(fetchRegister()); + auto r32 = load(fetchRegister()); + auto r16 = load(fetchRegister()); idle(3); - return instructionSourceMemory(toMemory(r32 + (int16)r16)); + return instructionSourceMemory(toMemory(r32 + (i16)r16)); } return undefined(); } case 0xe4: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location -= 1); if((data & 3) == 1) store(register, location -= 2); if((data & 3) == 2) store(register, location -= 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xe5: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location + 1); if((data & 3) == 1) store(register, location + 2); if((data & 3) == 2) store(register, location + 4); if((data & 3) == 3) Undefined; idle(1); - return instructionSourceMemory(toMemory(location)); } + return instructionSourceMemory(toMemory(location)); } case 0xe6: return undefined(); case 0xe7: - return instructionRegister(fetchRegister()); + return instructionRegister(fetchRegister()); case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef: - return instructionRegister(toRegister3(data)); + return instructionRegister(toRegister3(data)); case 0xf0: idle(1); - return instructionTargetMemory(fetch< uint8>()); + return instructionTargetMemory(fetch()); case 0xf1: idle(2); - return instructionTargetMemory(fetch()); + return instructionTargetMemory(fetch()); case 0xf2: idle(3); - return instructionTargetMemory(fetch()); + return instructionTargetMemory(fetch()); case 0xf3: { data = fetch(); if((data & 3) == 0) { idle(1); - return instructionTargetMemory(load(toRegister8(data))); + return instructionTargetMemory(load(toRegister8(data))); } if((data & 3) == 1) { idle(3); - return instructionTargetMemory(load(toRegister8(data)) + fetch()); + return instructionTargetMemory(load(toRegister8(data)) + fetch()); } if(data == 0x03) { - auto r32 = load(fetchRegister()); - auto r8 = load(fetchRegister< uint8>()); + auto r32 = load(fetchRegister()); + auto r8 = load(fetchRegister()); idle(3); - return instructionTargetMemory(r32 + (int8)r8); + return instructionTargetMemory(r32 + (i8)r8); } if(data == 0x07) { - auto r32 = load(fetchRegister()); - auto r16 = load(fetchRegister()); + auto r32 = load(fetchRegister()); + auto r16 = load(fetchRegister()); idle(3); - return instructionTargetMemory(r32 + (int16)r16); + return instructionTargetMemory(r32 + (i16)r16); } if(data == 0x17) { - auto d16 = fetch(); + auto d16 = fetch(); data = fetch(); idle(5); if((data & 0xf8) == 0x20) { - auto register = toRegister3(data); + auto register = toRegister3(data); store(register, load(PC) + d16); return; } if((data & 0xf8) == 0x30) { - auto register = toRegister3(data); + auto register = toRegister3(data); store(register, load(PC) + d16); return; } @@ -404,7 +404,7 @@ auto TLCS900H::instruction() -> void { return undefined(); } case 0xf4: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location -= 1); if((data & 3) == 1) store(register, location -= 2); @@ -414,7 +414,7 @@ auto TLCS900H::instruction() -> void { return instructionTargetMemory(location); } case 0xf5: { data = fetch(); - auto register = toRegister8(data); + auto register = toRegister8(data); auto location = load(register); if((data & 3) == 0) store(register, location + 1); if((data & 3) == 1) store(register, location + 2); @@ -426,21 +426,21 @@ auto TLCS900H::instruction() -> void { return undefined(); case 0xf7: { if(fetch()) Undefined; - auto memory = fetchMemory(); + auto memory = fetchMemory(); if(fetch()) Undefined; - auto immediate = fetchImmediate(); + auto immediate = fetchImmediate(); if(fetch()) Undefined; idle(4); return instructionLoad(memory, immediate); } case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: - return instructionSoftwareInterrupt((uint3)data); + return instructionSoftwareInterrupt((n3)data); } } template auto TLCS900H::instructionRegister(R register) -> void { using T = typename R::type; - enum : uint { bits = R::bits }; + enum : u32 { bits = R::bits }; auto data = fetch(); switch(data) { @@ -480,7 +480,7 @@ auto TLCS900H::instructionRegister(R register) -> void { case 0x0c: if constexpr(bits != 32) return undefined(); else { idle(6); - return instructionLink(register, fetchImmediate()); } + return instructionLink(register, fetchImmediate()); } case 0x0d: if constexpr(bits != 32) return undefined(); else { idle(5); @@ -525,29 +525,29 @@ auto TLCS900H::instructionRegister(R register) -> void { return undefined(); case 0x1c: if constexpr(bits == 32) return undefined(); else { - return instructionDecrementJumpNotZero(register, fetchImmediate()); } + return instructionDecrementJumpNotZero(register, fetchImmediate()); } case 0x1d: case 0x1e: case 0x1f: return undefined(); case 0x20: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionAndCarry(register, fetchImmediate()); } + return instructionAndCarry(register, fetchImmediate()); } case 0x21: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionOrCarry(register, fetchImmediate()); } + return instructionOrCarry(register, fetchImmediate()); } case 0x22: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionXorCarry(register, fetchImmediate()); } + return instructionXorCarry(register, fetchImmediate()); } case 0x23: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionLoadCarry(register, fetchImmediate()); } + return instructionLoadCarry(register, fetchImmediate()); } case 0x24: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionStoreCarry(register, fetchImmediate()); } + return instructionStoreCarry(register, fetchImmediate()); } case 0x25: case 0x26: case 0x27: return undefined(); case 0x28: @@ -583,51 +583,51 @@ auto TLCS900H::instructionRegister(R register) -> void { case 0x30: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionReset(register, fetchImmediate()); } + return instructionReset(register, fetchImmediate()); } case 0x31: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionSet(register, fetchImmediate()); } + return instructionSet(register, fetchImmediate()); } case 0x32: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionChange(register, fetchImmediate()); } + return instructionChange(register, fetchImmediate()); } case 0x33: if constexpr(bits == 32) return undefined(); else { idle(1); - return instructionBit(register, fetchImmediate()); } + return instructionBit(register, fetchImmediate()); } case 0x34: if constexpr(bits == 32) return undefined(); else { idle(2); - return instructionTestSet(register, fetchImmediate()); } + return instructionTestSet(register, fetchImmediate()); } case 0x35: case 0x36: case 0x37: return undefined(); case 0x38: if constexpr(bits != 16) return undefined(); else { idle(3); - return instructionModuloIncrement<1>(register, fetchImmediate()); } + return instructionModuloIncrement<1>(register, fetchImmediate()); } case 0x39: if constexpr(bits != 16) return undefined(); else { idle(3); - return instructionModuloIncrement<2>(register, fetchImmediate()); } + return instructionModuloIncrement<2>(register, fetchImmediate()); } case 0x3a: if constexpr(bits != 16) return undefined(); else { idle(3); - return instructionModuloIncrement<4>(register, fetchImmediate()); } + return instructionModuloIncrement<4>(register, fetchImmediate()); } case 0x3b: return undefined(); case 0x3c: if constexpr(bits != 16) return undefined(); else { idle(2); - return instructionModuloDecrement<1>(register, fetchImmediate()); } + return instructionModuloDecrement<1>(register, fetchImmediate()); } case 0x3d: if constexpr(bits != 16) return undefined(); else { idle(2); - return instructionModuloDecrement<2>(register, fetchImmediate()); } + return instructionModuloDecrement<2>(register, fetchImmediate()); } case 0x3e: if constexpr(bits != 16) return undefined(); else { idle(2); - return instructionModuloDecrement<4>(register, fetchImmediate()); } + return instructionModuloDecrement<4>(register, fetchImmediate()); } case 0x3f: return undefined(); case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: @@ -648,14 +648,14 @@ auto TLCS900H::instructionRegister(R register) -> void { return instructionDivideSigned(toRegister3(data), register); } case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: idle(1); - return instructionIncrement(register, toImmediate((uint3)data)); + return instructionIncrement(register, toImmediate((n3)data)); case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: idle(1); - return instructionDecrement(register, toImmediate((uint3)data)); + return instructionDecrement(register, toImmediate((n3)data)); case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: if constexpr(bits == 32) return undefined(); else { - return instructionSetConditionCode((uint4)data, register); } + return instructionSetConditionCode((n4)data, register); } case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: return instructionAdd(toRegister3(data), register); case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: @@ -667,7 +667,7 @@ auto TLCS900H::instructionRegister(R register) -> void { case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: return instructionSubtract(toRegister3(data), register); case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: - return instructionLoad(register, toImmediate((uint3)data)); + return instructionLoad(register, toImmediate((n3)data)); case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: return instructionSubtractBorrow(toRegister3(data), register); case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: @@ -704,33 +704,33 @@ auto TLCS900H::instructionRegister(R register) -> void { return instructionXor(toRegister3(data), register); case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: if constexpr(bits == 32) return undefined(); else { - return instructionCompare(register, toImmediate((uint3)data)); } + return instructionCompare(register, toImmediate((n3)data)); } case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: return instructionOr(toRegister3(data), register); case 0xe8: idle(1); - return instructionRotateLeftWithoutCarry(register, fetchImmediate()); + return instructionRotateLeftWithoutCarry(register, fetchImmediate()); case 0xe9: idle(1); - return instructionRotateRightWithoutCarry(register, fetchImmediate()); + return instructionRotateRightWithoutCarry(register, fetchImmediate()); case 0xea: idle(1); - return instructionRotateLeft(register, fetchImmediate()); + return instructionRotateLeft(register, fetchImmediate()); case 0xeb: idle(1); - return instructionRotateRight(register, fetchImmediate()); + return instructionRotateRight(register, fetchImmediate()); case 0xec: idle(1); - return instructionShiftLeftArithmetic(register, fetchImmediate()); + return instructionShiftLeftArithmetic(register, fetchImmediate()); case 0xed: idle(1); - return instructionShiftRightArithmetic(register, fetchImmediate()); + return instructionShiftRightArithmetic(register, fetchImmediate()); case 0xee: idle(1); - return instructionShiftLeftLogical(register, fetchImmediate()); + return instructionShiftLeftLogical(register, fetchImmediate()); case 0xef: idle(1); - return instructionShiftRightLogical(register, fetchImmediate()); + return instructionShiftRightLogical(register, fetchImmediate()); case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7: return instructionCompare(toRegister3(data), register); case 0xf8: @@ -763,7 +763,7 @@ auto TLCS900H::instructionRegister(R register) -> void { template auto TLCS900H::instructionSourceMemory(M memory) -> void { using T = typename M::type; - enum : uint { bits = M::bits }; + enum : u32 { bits = M::bits }; auto data = fetch(); switch(data) { @@ -821,7 +821,7 @@ auto TLCS900H::instructionSourceMemory(M memory) -> void { case 0x19: if constexpr(bits == 32) return undefined(); else { idle(6); - return instructionLoad(fetchMemory(), memory); } + return instructionLoad(fetchMemory(), memory); } case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: return undefined(); case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: @@ -883,45 +883,45 @@ auto TLCS900H::instructionSourceMemory(M memory) -> void { case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionIncrement(memory, toImmediate((uint3)data)); } + return instructionIncrement(memory, toImmediate((n3)data)); } case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionDecrement(memory, toImmediate((uint3)data)); } + return instructionDecrement(memory, toImmediate((n3)data)); } case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: return undefined(); case 0x78: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionRotateLeftWithoutCarry(memory, toImmediate(1)); } + return instructionRotateLeftWithoutCarry(memory, toImmediate(1)); } case 0x79: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionRotateRightWithoutCarry(memory, toImmediate(1)); } + return instructionRotateRightWithoutCarry(memory, toImmediate(1)); } case 0x7a: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionRotateLeft(memory, toImmediate(1)); } + return instructionRotateLeft(memory, toImmediate(1)); } case 0x7b: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionRotateRight(memory, toImmediate(1)); } + return instructionRotateRight(memory, toImmediate(1)); } case 0x7c: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionShiftLeftArithmetic(memory, toImmediate(1)); } + return instructionShiftLeftArithmetic(memory, toImmediate(1)); } case 0x7d: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionShiftRightArithmetic(memory, toImmediate(1)); } + return instructionShiftRightArithmetic(memory, toImmediate(1)); } case 0x7e: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionShiftLeftLogical(memory, toImmediate(1)); } + return instructionShiftLeftLogical(memory, toImmediate(1)); } case 0x7f: if constexpr(bits == 32) return undefined(); else { idle(4); - return instructionShiftRightLogical(memory, toImmediate(1)); } + return instructionShiftRightLogical(memory, toImmediate(1)); } case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: idleBWL(2, 2, 4); return instructionAdd(toRegister3(data), memory); @@ -973,28 +973,28 @@ auto TLCS900H::instructionSourceMemory(M memory) -> void { } } -auto TLCS900H::instructionTargetMemory(uint32 address) -> void { +auto TLCS900H::instructionTargetMemory(n32 address) -> void { auto data = fetch(); switch(data) { case 0x00: idle(1); - return instructionLoad(toMemory(address), fetchImmediate()); + return instructionLoad(toMemory(address), fetchImmediate()); case 0x01: return undefined(); case 0x02: idle(2); - return instructionLoad(toMemory(address), fetchImmediate()); + return instructionLoad(toMemory(address), fetchImmediate()); case 0x03: return undefined(); case 0x04: idle(1); - return instructionPop(toMemory(address)); + return instructionPop(toMemory(address)); case 0x05: return undefined(); case 0x06: idle(1); - return instructionPop(toMemory(address)); + return instructionPop(toMemory(address)); case 0x07: return undefined(); case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: @@ -1003,54 +1003,54 @@ auto TLCS900H::instructionTargetMemory(uint32 address) -> void { return undefined(); case 0x14: idle(4); - return instructionLoad(toMemory(address), fetchMemory()); + return instructionLoad(toMemory(address), fetchMemory()); case 0x15: return undefined(); case 0x16: idle(4); - return instructionLoad(toMemory(address), fetchMemory()); + return instructionLoad(toMemory(address), fetchMemory()); case 0x17: return undefined(); case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: return undefined(); case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: idle(2); - return instructionLoad(toRegister3(data), toImmediate(address)); + return instructionLoad(toRegister3(data), toImmediate(address)); case 0x28: idle(1); - return instructionAndCarry(toMemory(address), A); + return instructionAndCarry(toMemory(address), A); case 0x29: idle(1); - return instructionOrCarry(toMemory(address), A); + return instructionOrCarry(toMemory(address), A); case 0x2a: idle(1); - return instructionXorCarry(toMemory(address), A); + return instructionXorCarry(toMemory(address), A); case 0x2b: idle(1); - return instructionLoadCarry(toMemory(address), A); + return instructionLoadCarry(toMemory(address), A); case 0x2c: idle(2); - return instructionStoreCarry(toMemory(address), A); + return instructionStoreCarry(toMemory(address), A); case 0x2d: case 0x2e: case 0x2f: return undefined(); case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: idle(2); - return instructionLoad(toRegister3(data), toImmediate(address)); + return instructionLoad(toRegister3(data), toImmediate(address)); case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: return undefined(); case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: idle(2); - return instructionLoad(toMemory(address), toRegister3(data)); + return instructionLoad(toMemory(address), toRegister3(data)); case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: return undefined(); case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: idle(2); - return instructionLoad(toMemory(address), toRegister3(data)); + return instructionLoad(toMemory(address), toRegister3(data)); case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: return undefined(); case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: idle(4); - return instructionLoad(toMemory(address), toRegister3(data)); + return instructionLoad(toMemory(address), toRegister3(data)); case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: return undefined(); case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: @@ -1059,46 +1059,46 @@ auto TLCS900H::instructionTargetMemory(uint32 address) -> void { return undefined(); case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: idle(4); - return instructionAndCarry(toMemory(address), toImmediate(data)); + return instructionAndCarry(toMemory(address), toImmediate(data)); case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: idle(4); - return instructionOrCarry(toMemory(address), toImmediate(data)); + return instructionOrCarry(toMemory(address), toImmediate(data)); case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: idle(4); - return instructionXorCarry(toMemory(address), toImmediate(data)); + return instructionXorCarry(toMemory(address), toImmediate(data)); case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: idle(4); - return instructionLoadCarry(toMemory(address), toImmediate(data)); + return instructionLoadCarry(toMemory(address), toImmediate(data)); case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: idle(5); - return instructionStoreCarry(toMemory(address), toImmediate(data)); + return instructionStoreCarry(toMemory(address), toImmediate(data)); case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: idle(5); - return instructionTestSet(toMemory(address), toImmediate(data)); + return instructionTestSet(toMemory(address), toImmediate(data)); case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: idle(5); - return instructionReset(toMemory(address), toImmediate(data)); + return instructionReset(toMemory(address), toImmediate(data)); case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: idle(5); - return instructionSet(toMemory(address), toImmediate(data)); + return instructionSet(toMemory(address), toImmediate(data)); case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: idle(5); - return instructionChange(toMemory(address), toImmediate(data)); + return instructionChange(toMemory(address), toImmediate(data)); case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: idle(4); - return instructionBit(toMemory(address), toImmediate(data)); + return instructionBit(toMemory(address), toImmediate(data)); case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7: case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: - if(!condition((uint4)data)) return; - return instructionJump(toImmediate(address)); + if(!condition((n4)data)) return; + return instructionJump(toImmediate(address)); case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef: - if(!condition((uint4)data)) return; + if(!condition((n4)data)) return; idle(3); - return instructionCall(toImmediate(address)); + return instructionCall(toImmediate(address)); case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7: case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: - if(!condition((uint4)data)) return; + if(!condition((n4)data)) return; idle(2); return instructionReturn(); } diff --git a/ares/component/processor/tlcs900h/instructions.cpp b/ares/component/processor/tlcs900h/instructions.cpp index d48891c32f..e4dbfc0d6e 100644 --- a/ares/component/processor/tlcs900h/instructions.cpp +++ b/ares/component/processor/tlcs900h/instructions.cpp @@ -15,7 +15,7 @@ auto TLCS900H::instructionAnd(Target target, Source source) -> void { template auto TLCS900H::instructionAndCarry(Source source, Offset offset) -> void { - if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } + if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } CF &= load(source).bit(load(offset) & Source::bits - 1); } @@ -28,17 +28,17 @@ auto TLCS900H::instructionBit(Source source, Offset offset) -> void { SF = Undefined; } -auto TLCS900H::instructionBitSearch1Backward(Register register) -> void { +auto TLCS900H::instructionBitSearch1Backward(Register register) -> void { auto value = load(register); - for(uint index : reverse(range(16))) { + for(u32 index : reverse(range(16))) { if(value.bit(index)) return VF = 0, store(A, index); } VF = 1; } -auto TLCS900H::instructionBitSearch1Forward(Register register) -> void { +auto TLCS900H::instructionBitSearch1Forward(Register register) -> void { auto value = load(register); - for(uint index : range(16)) { + for(u32 index : range(16)) { if(value.bit(index)) return VF = 0, store(A, index); } VF = 1; @@ -70,9 +70,9 @@ auto TLCS900H::instructionChange(Target target, Offset offset) -> void { store(target, result); } -template +template auto TLCS900H::instructionCompare(Target target) -> void { - auto source = toRegister3(r.prefix); + auto source = toRegister3(r.prefix); auto cf = CF; //CF is not modified; but algorithmSubtract will modify it algorithmSubtract(load(target), load(toMemory(load(source)))); store(source, load(source) + Adjust); @@ -83,7 +83,7 @@ auto TLCS900H::instructionCompare(Target target) -> void { //note: unlike LDIR and LDDR, CPIR and CPDR do not appear to have the extra read when BC=0 //however, the penalty cycle still exists and is emulated here. -template +template auto TLCS900H::instructionCompareRepeat(Target target) -> void { instructionCompare(target); if(load(BC) && !ZF) return store(PC, load(PC) - 2); @@ -102,15 +102,15 @@ auto TLCS900H::instructionComplement(Target target) -> void { HF = 1; } -auto TLCS900H::instructionDecimalAdjustAccumulator(Register register) -> void { +auto TLCS900H::instructionDecimalAdjustAccumulator(Register register) -> void { prefetch(); auto input = load(register), value = input; - if(CF || (uint8)value > 0x99) value += NF ? -0x60 : 0x60; - if(HF || (uint4)value > 0x09) value += NF ? -0x06 : 0x06; + if(CF || (n8)value > 0x99) value += NF ? -0x60 : 0x60; + if(HF || (n4)value > 0x09) value += NF ? -0x06 : 0x06; if(NF == 0) CF |= value < input; if(NF == 1) CF |= value > input; PF = parity(value); - HF = uint8(value ^ input).bit(4); + HF = n8(value ^ input).bit(4); ZF = value == 0; SF = value.bit(-1); store(register, value); @@ -120,7 +120,7 @@ template auto TLCS900H::instructionDecrement(Target target, Source source) -> void { auto immediate = load(source); if(!immediate) immediate = 8; - if constexpr(is_same_v> || is_same_v>) { + if constexpr(is_same_v> || is_same_v>) { //decw #n,r; decl #n,r: does not update flags store(target, load(target) - immediate); } else { @@ -189,7 +189,7 @@ template auto TLCS900H::instructionIncrement(Target target, Source source) -> void { auto immediate = load(source); if(!immediate) immediate = 8; - if constexpr(is_same_v> || is_same_v>) { + if constexpr(is_same_v> || is_same_v>) { //incw #n,r; incl #n,r: does not update flags store(target, load(target) + immediate); } else { @@ -227,13 +227,13 @@ auto TLCS900H::instructionLoad(Target target, Source source) -> void { template auto TLCS900H::instructionLoadCarry(Source source, Offset offset) -> void { - if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } + if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } CF = load(source).bit(load(offset) & Source::bits - 1); } -template auto TLCS900H::instructionLoad() -> void { - auto source = (uint3)r.prefix == 5 ? XIY : XHL; - auto target = (uint3)r.prefix == 5 ? XIX : XDE; +template auto TLCS900H::instructionLoad() -> void { + auto source = (n3)r.prefix == 5 ? XIY : XHL; + auto target = (n3)r.prefix == 5 ? XIX : XDE; store(toMemory(load(target)), load(toMemory(load(source)))); store(source, load(source) + Adjust); store(target, load(target) + Adjust); @@ -250,7 +250,7 @@ template auto TLCS900H::instructionLoad() -> void { //or if it always occurs at the end of ever LDIR and LDDR instruction. //since I'm not sure how to emulate this, I don't try and guess here. //I do however add the extra penalty cycle at the end of the transfer. -template auto TLCS900H::instructionLoadRepeat() -> void { +template auto TLCS900H::instructionLoadRepeat() -> void { instructionLoad(); if(load(BC)) return store(PC, load(PC) - 2); idle(1); @@ -258,7 +258,7 @@ template auto TLCS900H::instructionLoadRepeat() -> vo //reverse all bits in a 16-bit register //note: an 8-bit lookup table is faster (when in L1/L2 cache), but much more code -auto TLCS900H::instructionMirror(Register register) -> void { +auto TLCS900H::instructionMirror(Register register) -> void { idle(1); auto data = load(register); data = data << 1 & 0xaaaa | data >> 1 & 0x5555; @@ -267,7 +267,7 @@ auto TLCS900H::instructionMirror(Register register) -> void { store(register, data << 8 | data >> 8); } -template +template auto TLCS900H::instructionModuloDecrement(Target target, Source source) -> void { auto result = load(target); auto number = load(source); @@ -279,7 +279,7 @@ auto TLCS900H::instructionModuloDecrement(Target target, Source source) -> void store(target, result); } -template +template auto TLCS900H::instructionModuloIncrement(Target target, Source source) -> void { auto result = load(target); auto number = load(source); @@ -296,9 +296,9 @@ auto TLCS900H::instructionMultiply(Target target, Source source) -> void { store(expand(target), load(target) * load(source)); } -auto TLCS900H::instructionMultiplyAdd(Register register) -> void { - auto xde = toMemory(load(XDE)); - auto xhl = toMemory(load(XHL)); +auto TLCS900H::instructionMultiplyAdd(Register register) -> void { + auto xde = toMemory(load(XDE)); + auto xhl = toMemory(load(XHL)); auto source = load(expand(register)); auto target = load(xde) * load(xhl); @@ -306,7 +306,7 @@ auto TLCS900H::instructionMultiplyAdd(Register register) -> void { store(XHL, load(XHL) - 2); auto result = load(expand(register)); - VF = uint32((target ^ result) & (source ^ result)).bit(-1); + VF = n32((target ^ result) & (source ^ result)).bit(-1); ZF = result == 0; SF = result.bit(-1); } @@ -331,7 +331,7 @@ auto TLCS900H::instructionOr(Target target, Source source) -> void { template auto TLCS900H::instructionOrCarry(Source source, Offset offset) -> void { - if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } + if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } CF |= load(source).bit(load(offset) & Source::bits - 1); } @@ -407,8 +407,8 @@ auto TLCS900H::instructionRotateLeft(Target target, Amount amount) -> void { auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { - uint cf = result.bit(-1); + for(u32 n : range(length)) { + u32 cf = result.bit(-1); result = result << 1 | CF; CF = cf; } @@ -421,7 +421,7 @@ auto TLCS900H::instructionRotateLeftWithoutCarry(Target target, Amount amount) - auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(-1); result = result << 1 | CF; } @@ -451,8 +451,8 @@ auto TLCS900H::instructionRotateRight(Target target, Amount amount) -> void { auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { - uint cf = result.bit(0); + for(u32 n : range(length)) { + u32 cf = result.bit(0); result = CF << Target::bits - 1 | result >> 1; CF = cf; } @@ -465,7 +465,7 @@ auto TLCS900H::instructionRotateRightWithoutCarry(Target target, Amount amount) auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(0); result = CF << Target::bits - 1 | result >> 1; } @@ -481,7 +481,7 @@ auto TLCS900H::instructionSet(Target target, Offset offset) -> void { //RCF: reset carry flag //SCF: set carry flag -auto TLCS900H::instructionSetCarryFlag(uint1 value) -> void { +auto TLCS900H::instructionSetCarryFlag(n1 value) -> void { CF = value; NF = 0; HF = 0; @@ -489,23 +489,23 @@ auto TLCS900H::instructionSetCarryFlag(uint1 value) -> void { //CCF: complement carry flag //ZCF: complement zero flag to carry flag -auto TLCS900H::instructionSetCarryFlagComplement(uint1 value) -> void { +auto TLCS900H::instructionSetCarryFlagComplement(n1 value) -> void { CF = !value; NF = 0; HF = Undefined; } template -auto TLCS900H::instructionSetConditionCode(uint4 code, Target target) -> void { +auto TLCS900H::instructionSetConditionCode(n4 code, Target target) -> void { store(target, condition(code)); } -auto TLCS900H::instructionSetInterruptFlipFlop(uint3 value) -> void { +auto TLCS900H::instructionSetInterruptFlipFlop(n3 value) -> void { idle(1 + (value == 7)); IFF = value; } -auto TLCS900H::instructionSetRegisterFilePointer(uint2 value) -> void { +auto TLCS900H::instructionSetRegisterFilePointer(n2 value) -> void { RFP = value; } @@ -515,7 +515,7 @@ auto TLCS900H::instructionShiftLeftArithmetic(Target target, Amount amount) -> v auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(-1); result = result << 1; } @@ -528,7 +528,7 @@ auto TLCS900H::instructionShiftLeftLogical(Target target, Amount amount) -> void auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(-1); result = result << 1; } @@ -541,7 +541,7 @@ auto TLCS900H::instructionShiftRightArithmetic(Target target, Amount amount) -> auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(0); result = result >> 1; result.bit(-1) = result.bit(-2); @@ -555,7 +555,7 @@ auto TLCS900H::instructionShiftRightLogical(Target target, Amount amount) -> voi auto length = load(amount).clip(4); if(!length) length = 16; idle(length >> 2); - for(uint n : range(length)) { + for(u32 n : range(length)) { CF = result.bit(0); result = result >> 1; } @@ -570,7 +570,7 @@ auto TLCS900H::instructionStoreCarry(Target target, Offset offset) -> void { store(target, result); } -auto TLCS900H::instructionSoftwareInterrupt(uint3 vector) -> void { +auto TLCS900H::instructionSoftwareInterrupt(n3 vector) -> void { idle(1); interrupt(vector << 2); } @@ -611,6 +611,6 @@ auto TLCS900H::instructionXor(Target target, Source source) -> void { template auto TLCS900H::instructionXorCarry(Source source, Offset offset) -> void { - if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } + if constexpr(Source::bits == 8 && is_same_v>) { if(load(offset).bit(3)) return (void)Undefined; } CF ^= load(source).bit(load(offset) & Source::bits - 1); } diff --git a/ares/component/processor/tlcs900h/memory.cpp b/ares/component/processor/tlcs900h/memory.cpp index 5d6995de55..d610322670 100644 --- a/ares/component/processor/tlcs900h/memory.cpp +++ b/ares/component/processor/tlcs900h/memory.cpp @@ -1,40 +1,40 @@ #define PC r.pc.l.l0 -template<> auto TLCS900H::fetch< uint8>() -> uint8 { +template<> auto TLCS900H::fetch() -> n8 { //while(p.valid < 3) prefetch(); if(p.valid == 0) prefetch(); - uint8 data = p.data; + n8 data = p.data; p.data >>= 8; p.valid--; return PC++, data; } -template<> auto TLCS900H::fetch() -> uint16 { - uint16 data = fetch() << 0; - return data | fetch() << 8; +template<> auto TLCS900H::fetch() -> n16 { + n16 data = fetch() << 0; + return data | fetch() << 8; } -template<> auto TLCS900H::fetch() -> uint24 { - uint24 data = fetch() << 0; - data |= fetch() << 8; - return data |= fetch() << 16; +template<> auto TLCS900H::fetch() -> n24 { + n24 data = fetch() << 0; + data |= fetch() << 8; + return data |= fetch() << 16; } -template<> auto TLCS900H::fetch() -> uint32 { - uint32 data = fetch() << 0; - data |= fetch() << 8; - data |= fetch() << 16; - return data |= fetch() << 24; +template<> auto TLCS900H::fetch() -> n32 { + n32 data = fetch() << 0; + data |= fetch() << 8; + data |= fetch() << 16; + return data |= fetch() << 24; } #undef PC -template<> auto TLCS900H::fetch< int8>() -> int8 { return ( int8)fetch< uint8>(); } -template<> auto TLCS900H::fetch() -> int16 { return (int16)fetch(); } -template<> auto TLCS900H::fetch() -> int24 { return (int24)fetch(); } -template<> auto TLCS900H::fetch() -> int32 { return (int32)fetch(); } +template<> auto TLCS900H::fetch() -> i8 { return (i8 )fetch(); } +template<> auto TLCS900H::fetch() -> i16 { return (i16)fetch(); } +template<> auto TLCS900H::fetch() -> i24 { return (i24)fetch(); } +template<> auto TLCS900H::fetch() -> i32 { return (i32)fetch(); } -template auto TLCS900H::fetchRegister() -> Register { return Register{fetch()}; } +template auto TLCS900H::fetchRegister() -> Register { return Register{fetch()}; } template auto TLCS900H::fetchMemory() -> Memory { return Memory{fetch()}; } template auto TLCS900H::fetchImmediate() -> Immediate { return Immediate{fetch()}; } @@ -63,14 +63,14 @@ template auto TLCS900H::push(T data) -> void { // -template<> auto TLCS900H::load(Memory< uint8> memory) -> uint8 { return read(Byte, memory.address); } -template<> auto TLCS900H::load(Memory memory) -> uint16 { return read(Word, memory.address); } -template<> auto TLCS900H::load(Memory memory) -> uint32 { return read(Long, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> n8 { return read(Byte, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> n16 { return read(Word, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> n32 { return read(Long, memory.address); } -template<> auto TLCS900H::load(Memory< int8> memory) -> int8 { return (int8)read(Byte, memory.address); } -template<> auto TLCS900H::load(Memory memory) -> int16 { return (int16)read(Word, memory.address); } -template<> auto TLCS900H::load(Memory memory) -> int32 { return (int32)read(Long, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> i8 { return (i8 )read(Byte, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> i16 { return (i16)read(Word, memory.address); } +template<> auto TLCS900H::load(Memory memory) -> i32 { return (i32)read(Long, memory.address); } -template<> auto TLCS900H::store(Memory< uint8> memory, uint32 data) -> void { write(Byte, memory.address, data); } -template<> auto TLCS900H::store(Memory memory, uint32 data) -> void { write(Word, memory.address, data); } -template<> auto TLCS900H::store(Memory memory, uint32 data) -> void { write(Long, memory.address, data); } +template<> auto TLCS900H::store(Memory memory, n32 data) -> void { write(Byte, memory.address, data); } +template<> auto TLCS900H::store(Memory memory, n32 data) -> void { write(Word, memory.address, data); } +template<> auto TLCS900H::store(Memory memory, n32 data) -> void { write(Long, memory.address, data); } diff --git a/ares/component/processor/tlcs900h/registers.cpp b/ares/component/processor/tlcs900h/registers.cpp index 74b5804be3..03c472b454 100644 --- a/ares/component/processor/tlcs900h/registers.cpp +++ b/ares/component/processor/tlcs900h/registers.cpp @@ -1,7 +1,7 @@ #define a RFP #define p RFP - 1 & 3 -template<> auto TLCS900H::map(Register register) const -> maybe { +template<> auto TLCS900H::map(Register register) const -> maybe { switch(register.id) { #define r(id, name) case id: return r.name; r(0x00, xwa[0].b.b0) r(0x01, xwa[0].b.b1) r(0x02, xwa[0].b.b2) r(0x03, xwa[0].b.b3) @@ -37,7 +37,7 @@ template<> auto TLCS900H::map(Register register) const -> maybe { return nothing; } -template<> auto TLCS900H::map(Register register) const -> maybe { +template<> auto TLCS900H::map(Register register) const -> maybe { switch(register.id & ~1) { #define r(id, name) case id: return r.name; r(0x00, xwa[0].w.w0) r(0x02, xwa[0].w.w1) r(0x04, xbc[0].w.w0) r(0x06, xbc[0].w.w1) @@ -59,7 +59,7 @@ template<> auto TLCS900H::map(Register register) const -> maybe return nothing; } -template<> auto TLCS900H::map(Register register) const -> maybe { +template<> auto TLCS900H::map(Register register) const -> maybe { switch(register.id & ~3) { #define r(id, name) case id: return r.name; r(0x00, xwa[0].l.l0) r(0x04, xbc[0].l.l0) r(0x08, xde[0].l.l0) r(0x0c, xhl[0].l.l0) @@ -77,50 +77,50 @@ template<> auto TLCS900H::map(Register register) const -> maybe #undef a #undef p -template<> auto TLCS900H::load< uint8>(Register< uint8> register) const -> uint8 { return map(register)(Undefined); } -template<> auto TLCS900H::load(Register register) const -> uint16 { return map(register)(Undefined); } -template<> auto TLCS900H::load(Register register) const -> uint32 { return map(register)(Undefined); } +template<> auto TLCS900H::load(Register register) const -> n8 { return map(register)(Undefined); } +template<> auto TLCS900H::load(Register register) const -> n16 { return map(register)(Undefined); } +template<> auto TLCS900H::load(Register register) const -> n32 { return map(register)(Undefined); } -template<> auto TLCS900H::store< uint8>(Register< uint8> register, uint32 data) -> void { if(auto r = map(register)) r() = data; } -template<> auto TLCS900H::store(Register register, uint32 data) -> void { if(auto r = map(register)) r() = data; } -template<> auto TLCS900H::store(Register register, uint32 data) -> void { if(auto r = map(register)) r() = data; } +template<> auto TLCS900H::store(Register register, n32 data) -> void { if(auto r = map(register)) r() = data; } +template<> auto TLCS900H::store(Register register, n32 data) -> void { if(auto r = map(register)) r() = data; } +template<> auto TLCS900H::store(Register register, n32 data) -> void { if(auto r = map(register)) r() = data; } -auto TLCS900H::expand(Register< uint8> register) const -> Register { return {register.id & ~1}; } -auto TLCS900H::expand(Register register) const -> Register { return {register.id & ~3}; } +auto TLCS900H::expand(Register register) const -> Register { return {register.id & ~1}; } +auto TLCS900H::expand(Register register) const -> Register { return {register.id & ~3}; } -auto TLCS900H::shrink(Register register) const -> Register { return {register.id}; } -auto TLCS900H::shrink(Register register) const -> Register< uint8> { return {register.id}; } +auto TLCS900H::shrink(Register register) const -> Register { return {register.id}; } +auto TLCS900H::shrink(Register register) const -> Register { return {register.id}; } -auto TLCS900H::load(FlagRegister f) const -> uint8 { +auto TLCS900H::load(FlagRegister f) const -> n8 { switch(f.id) { case 0: return r.c << 0 | r.n << 1 | r.v << 2 | r.h << 4 | r.z << 6 | r.s << 7; case 1: return r.cp << 0 | r.np << 1 | r.vp << 2 | r.hp << 4 | r.zp << 6 | r.sp << 7; } unreachable; } -auto TLCS900H::store(FlagRegister f, uint8 data) -> void { +auto TLCS900H::store(FlagRegister f, n8 data) -> void { switch(f.id) { case 0: r.c = data.bit(0); r.n = data.bit(1); r.v = data.bit(2); r.h = data.bit(4); r.z = data.bit(6); r.s = data.bit(7); return; case 1: r.cp = data.bit(0); r.np = data.bit(1); r.vp = data.bit(2); r.hp = data.bit(4); r.zp = data.bit(6); r.sp = data.bit(7); return; } unreachable; } -auto TLCS900H::load(StatusRegister) const -> uint16 { +auto TLCS900H::load(StatusRegister) const -> n16 { //900/H: d10 = RFP2 (always 0); d11 = MAX (always 1); d15 = SYSM (always 1) return load(F) | r.rfp << 8 | 0 << 10 | 1 << 11 | r.iff << 12 | 1 << 15; } -auto TLCS900H::store(StatusRegister, uint16 data) -> void { +auto TLCS900H::store(StatusRegister, n16 data) -> void { store(F, data.bit(0,7)); r.rfp = data.bit(8,9); r.iff = data.bit(12,14); } -auto TLCS900H::load(ProgramCounter) const -> uint32 { +auto TLCS900H::load(ProgramCounter) const -> n32 { return r.pc.l.l0; } -auto TLCS900H::store(ProgramCounter, uint32 data) -> void { +auto TLCS900H::store(ProgramCounter, n32 data) -> void { r.pc.l.l0 = data; invalidate(); } diff --git a/ares/component/processor/tlcs900h/serialization.cpp b/ares/component/processor/tlcs900h/serialization.cpp index 45d2774b22..a279e54ab4 100644 --- a/ares/component/processor/tlcs900h/serialization.cpp +++ b/ares/component/processor/tlcs900h/serialization.cpp @@ -1,5 +1,5 @@ auto TLCS900H::serialize(serializer& s) -> void { - for(uint n : range(4)) { + for(u32 n : range(4)) { s(r.xwa[n].l.l0); s(r.xbc[n].l.l0); s(r.xde[n].l.l0); @@ -11,7 +11,7 @@ auto TLCS900H::serialize(serializer& s) -> void { s(r.xsp.l.l0); s(r.pc.l.l0); - for(uint n : range(4)) { + for(u32 n : range(4)) { s(r.dmas[n].l.l0); s(r.dmad[n].l.l0); s(r.dmam[n].l.l0); diff --git a/ares/component/processor/tlcs900h/tlcs900h.cpp b/ares/component/processor/tlcs900h/tlcs900h.cpp index 899e4de238..0eac0b284b 100644 --- a/ares/component/processor/tlcs900h/tlcs900h.cpp +++ b/ares/component/processor/tlcs900h/tlcs900h.cpp @@ -26,10 +26,10 @@ namespace ares { #include "serialization.cpp" #include "disassembler.cpp" -auto TLCS900H::interrupt(uint8 vector) -> void { +auto TLCS900H::interrupt(n8 vector) -> void { push(PC); push(SR); - store(PC, load(Memory{0xffff00 | vector})); + store(PC, load(Memory{0xffff00 | vector})); store(INTNEST, load(INTNEST) + 1); idle(1); prefetch(); diff --git a/ares/component/processor/tlcs900h/tlcs900h.hpp b/ares/component/processor/tlcs900h/tlcs900h.hpp index 7aedbe2a9c..d95fa27c20 100644 --- a/ares/component/processor/tlcs900h/tlcs900h.hpp +++ b/ares/component/processor/tlcs900h/tlcs900h.hpp @@ -17,91 +17,91 @@ namespace ares { struct TLCS900H { - enum : uint { Byte = 1, Word = 2, Long = 4 }; + enum : u32 { Byte = 1, Word = 2, Long = 4 }; - virtual auto idle(uint clocks) -> void = 0; - virtual auto width(uint24 address) -> uint = 0; - virtual auto read(uint size, uint24 address) -> uint32 = 0; - virtual auto write(uint size, uint24 address, uint32 data) -> void = 0; + virtual auto idle(u32 clocks) -> void = 0; + virtual auto width(n24 address) -> u32 = 0; + virtual auto read(u32 size, n24 address) -> n32 = 0; + virtual auto write(u32 size, n24 address, n32 data) -> void = 0; - struct FlagRegister { using type = uint8; enum : uint { bits = 8 }; uint1 id; }; - struct StatusRegister { using type = uint16; enum : uint { bits = 16 }; }; - struct ProgramCounter { using type = uint32; enum : uint { bits = 32 }; }; - template struct ControlRegister { using type = T; enum : uint { bits = 8 * sizeof(T) }; uint8 id; }; - template struct Register { using type = T; enum : uint { bits = 8 * sizeof(T) }; uint8 id; }; - template struct Memory { using type = T; enum : uint { bits = 8 * sizeof(T) }; uint32 address; }; - template struct Immediate { using type = T; enum : uint { bits = 8 * sizeof(T) }; uint32 constant; }; + struct FlagRegister { using type = n8; enum : u32 { bits = 8 }; n1 id; }; + struct StatusRegister { using type = n16; enum : u32 { bits = 16 }; }; + struct ProgramCounter { using type = n32; enum : u32 { bits = 32 }; }; + template struct ControlRegister { using type = T; enum : u32 { bits = 8 * sizeof(T) }; n8 id; }; + template struct Register { using type = T; enum : u32 { bits = 8 * sizeof(T) }; n8 id; }; + template struct Memory { using type = T; enum : u32 { bits = 8 * sizeof(T) }; n32 address; }; + template struct Immediate { using type = T; enum : u32 { bits = 8 * sizeof(T) }; n32 constant; }; template auto load(Immediate immediate) const -> T { return immediate.constant; } //tlcs900h.cpp - auto interrupt(uint8 vector) -> void; + auto interrupt(n8 vector) -> void; auto power() -> void; //registers.cpp template auto map(Register) const -> maybe; template auto load(Register) const -> T; - template auto store(Register, uint32) -> void; - auto expand(Register< uint8>) const -> Register; - auto expand(Register) const -> Register; - auto shrink(Register) const -> Register; - auto shrink(Register) const -> Register< uint8>; - auto load(FlagRegister) const -> uint8; - auto store(FlagRegister, uint8) -> void; - auto load(StatusRegister) const -> uint16; - auto store(StatusRegister, uint16) -> void; - auto load(ProgramCounter) const -> uint32; - auto store(ProgramCounter, uint32) -> void; + template auto store(Register, n32) -> void; + auto expand(Register) const -> Register; + auto expand(Register) const -> Register; + auto shrink(Register) const -> Register; + auto shrink(Register) const -> Register; + auto load(FlagRegister) const -> n8; + auto store(FlagRegister, n8) -> void; + auto load(StatusRegister) const -> n16; + auto store(StatusRegister, n16) -> void; + auto load(ProgramCounter) const -> n32; + auto store(ProgramCounter, n32) -> void; //control-registers.cpp template auto map(ControlRegister) const -> maybe; template auto load(ControlRegister) const -> T; - template auto store(ControlRegister, uint32) -> void; + template auto store(ControlRegister, n32) -> void; //memory.cpp - template auto fetch() -> T; + template auto fetch() -> T; template auto fetchRegister() -> Register; template auto fetchMemory() -> Memory; template auto fetchImmediate() -> Immediate; template auto push(T) -> void; template auto pop(T) -> void; template auto load(Memory) -> T; - template auto store(Memory, uint32) -> void; + template auto store(Memory, n32) -> void; //conditions.cpp - auto condition(uint4 code) -> bool; + auto condition(n4 code) -> bool; //algorithms.cpp template auto parity(T) const -> bool; - template auto algorithmAdd(T target, T source, uint1 carry = 0) -> T; + template auto algorithmAdd(T target, T source, n1 carry = 0) -> T; template auto algorithmAnd(T target, T source) -> T; template auto algorithmDecrement(T target, T source) -> T; template auto algorithmIncrement(T target, T source) -> T; template auto algorithmOr(T target, T source) -> T; template auto algorithmRotated(T result) -> T; template auto algorithmShifted(T result) -> T; - template auto algorithmSubtract(T target, T source, uint1 carry = 0) -> T; + template auto algorithmSubtract(T target, T source, n1 carry = 0) -> T; template auto algorithmXor(T target, T source) -> T; //dma.cpp - auto dma(uint2 channel) -> bool; + auto dma(n2 channel) -> bool; //instruction.cpp - template auto idleBW(uint b, uint w) -> void; - template auto idleWL(uint w, uint l) -> void; - template auto idleBWL(uint b, uint w, uint l) -> void; - - template auto toRegister3(uint3) const -> Register; - template auto toRegister8(uint8) const -> Register; - template auto toControlRegister(uint8) const -> ControlRegister; - template auto toMemory(uint32 address) const -> Memory; - template auto toImmediate(uint32 constant) const -> Immediate; + template auto idleBW(u32 b, u32 w) -> void; + template auto idleWL(u32 w, u32 l) -> void; + template auto idleBWL(u32 b, u32 w, u32 l) -> void; + + template auto toRegister3(n3) const -> Register; + template auto toRegister8(n8) const -> Register; + template auto toControlRegister(n8) const -> ControlRegister; + template auto toMemory(n32 address) const -> Memory; + template auto toImmediate(n32 constant) const -> Immediate; template auto toImmediate3(natural constant) const -> Immediate; auto undefined() -> void; auto instruction() -> void; template auto instructionRegister(Register) -> void; template auto instructionSourceMemory(Memory) -> void; - auto instructionTargetMemory(uint32 address) -> void; + auto instructionTargetMemory(n32 address) -> void; //instructions.cpp template auto instructionAdd(Target, Source) -> void; @@ -109,16 +109,16 @@ struct TLCS900H { template auto instructionAnd(Target, Source) -> void; template auto instructionAndCarry(Source, Offset) -> void; template auto instructionBit(Source, Offset) -> void; - auto instructionBitSearch1Backward(Register) -> void; - auto instructionBitSearch1Forward(Register) -> void; + auto instructionBitSearch1Backward(Register) -> void; + auto instructionBitSearch1Forward(Register) -> void; template auto instructionCall(Source) -> void; template auto instructionCallRelative(Source) -> void; template auto instructionChange(Target, Offset) -> void; - template auto instructionCompare(Target) -> void; - template auto instructionCompareRepeat(Target) -> void; + template auto instructionCompare(Target) -> void; + template auto instructionCompareRepeat(Target) -> void; template auto instructionCompare(Target, Source) -> void; template auto instructionComplement(Target) -> void; - auto instructionDecimalAdjustAccumulator(Register) -> void; + auto instructionDecimalAdjustAccumulator(Register) -> void; template auto instructionDecrement(Target, Source) -> void; template auto instructionDecrementJumpNotZero(Target, Offset) -> void; template auto instructionDivide(Target, Source) -> void; @@ -133,13 +133,13 @@ struct TLCS900H { template auto instructionLink(Target, Offset) -> void; template auto instructionLoad(Target, Source) -> void; template auto instructionLoadCarry(Source, Offset) -> void; - template auto instructionLoad() -> void; - template auto instructionLoadRepeat() -> void; - template auto instructionModuloDecrement(Target, Source) -> void; - template auto instructionModuloIncrement(Target, Source) -> void; - auto instructionMirror(Register) -> void; + template auto instructionLoad() -> void; + template auto instructionLoadRepeat() -> void; + template auto instructionModuloDecrement(Target, Source) -> void; + template auto instructionModuloIncrement(Target, Source) -> void; + auto instructionMirror(Register) -> void; template auto instructionMultiply(Target, Source) -> void; - auto instructionMultiplyAdd(Register) -> void; + auto instructionMultiplyAdd(Register) -> void; template auto instructionMultiplySigned(Target, Source) -> void; template auto instructionNegate(Target) -> void; auto instructionNoOperation() -> void; @@ -159,17 +159,17 @@ struct TLCS900H { template auto instructionRotateRight(Target, Amount) -> void; template auto instructionRotateRightWithoutCarry(Target, Amount) -> void; template auto instructionSet(Target, Offset) -> void; - auto instructionSetCarryFlag(uint1 value) -> void; - auto instructionSetCarryFlagComplement(uint1 value) -> void; - template auto instructionSetConditionCode(uint4 code, Target) -> void; - auto instructionSetInterruptFlipFlop(uint3 value) -> void; - auto instructionSetRegisterFilePointer(uint2 value) -> void; + auto instructionSetCarryFlag(n1 value) -> void; + auto instructionSetCarryFlagComplement(n1 value) -> void; + template auto instructionSetConditionCode(n4 code, Target) -> void; + auto instructionSetInterruptFlipFlop(n3 value) -> void; + auto instructionSetRegisterFilePointer(n2 value) -> void; template auto instructionShiftLeftArithmetic(Target, Amount) -> void; template auto instructionShiftLeftLogical(Target, Amount) -> void; template auto instructionShiftRightArithmetic(Target, Amount) -> void; template auto instructionShiftRightLogical(Target, Amount) -> void; template auto instructionStoreCarry(Target, Offset) -> void; - auto instructionSoftwareInterrupt(uint3 interrupt) -> void; + auto instructionSoftwareInterrupt(n3 interrupt) -> void; template auto instructionSubtract(Target, Source) -> void; template auto instructionSubtractBorrow(Target, Source) -> void; template auto instructionTestSet(Target, Offset) -> void; @@ -182,9 +182,9 @@ struct TLCS900H { union DataRegister { DataRegister() { l.l0 = 0; } - struct { uint32 order_lsb1(l0); } l; - struct { uint16 order_lsb2(w0, w1); } w; - struct { uint8 order_lsb4(b0, b1, b2, b3); } b; + struct { n32 order_lsb1(l0); } l; + struct { n16 order_lsb2(w0, w1); } w; + struct { n8 order_lsb4(b0, b1, b2, b3); } b; }; struct Registers { @@ -203,57 +203,57 @@ struct TLCS900H { DataRegister dmam[4]; DataRegister intnest; //16-bit - uint1 c, cp; //carry - uint1 n, np; //negative - uint1 v, vp; //overflow or parity - uint1 h, hp; //half carry - uint1 z, zp; //zero - uint1 s, sp; //sign - uint2 rfp; //register file pointer - uint3 iff = 7; //interrupt mask flip-flop - - uint1 halted; //set if halt instruction executed; waits for an interrupt to resume - uint8 prefix; //first opcode byte; needed for [CP|LD][ID](R) instructions + n1 c, cp; //carry + n1 n, np; //negative + n1 v, vp; //overflow or parity + n1 h, hp; //half carry + n1 z, zp; //zero + n1 s, sp; //sign + n2 rfp; //register file pointer + n3 iff = 7; //interrupt mask flip-flop + + n1 halted; //set if halt instruction executed; waits for an interrupt to resume + n8 prefix; //first opcode byte; needed for [CP|LD][ID](R) instructions } r; struct Prefetch { - uint3 valid; //0-4 bytes - uint32 data; + n3 valid; //0-4 bytes + n32 data; } p; //prefetch.cpp auto invalidate() -> void; auto prefetch() -> void; - uint24 mar; //A0-A23: memory address register - uint16 mdr; //D0-D15: memory data register - - static inline const Register< uint8> A{0xe0}; - static inline const Register< uint8> W{0xe1}; - static inline const Register< uint8> C{0xe4}; - static inline const Register< uint8> B{0xe5}; - static inline const Register< uint8> E{0xe8}; - static inline const Register< uint8> D{0xe9}; - static inline const Register< uint8> L{0xec}; - static inline const Register< uint8> H{0xed}; - - static inline const Register WA{0xe0}; - static inline const Register BC{0xe4}; - static inline const Register DE{0xe8}; - static inline const Register HL{0xec}; - static inline const Register IX{0xf0}; - static inline const Register IY{0xf4}; - static inline const Register IZ{0xf8}; - static inline const Register SP{0xfc}; - - static inline const Register XWA{0xe0}; - static inline const Register XBC{0xe4}; - static inline const Register XDE{0xe8}; - static inline const Register XHL{0xec}; - static inline const Register XIX{0xf0}; - static inline const Register XIY{0xf4}; - static inline const Register XIZ{0xf8}; - static inline const Register XSP{0xfc}; + n24 mar; //A0-A23: memory address register + n16 mdr; //D0-D15: memory data register + + static inline const Register A{0xe0}; + static inline const Register W{0xe1}; + static inline const Register C{0xe4}; + static inline const Register B{0xe5}; + static inline const Register E{0xe8}; + static inline const Register D{0xe9}; + static inline const Register L{0xec}; + static inline const Register H{0xed}; + + static inline const Register WA{0xe0}; + static inline const Register BC{0xe4}; + static inline const Register DE{0xe8}; + static inline const Register HL{0xec}; + static inline const Register IX{0xf0}; + static inline const Register IY{0xf4}; + static inline const Register IZ{0xf8}; + static inline const Register SP{0xfc}; + + static inline const Register XWA{0xe0}; + static inline const Register XBC{0xe4}; + static inline const Register XDE{0xe8}; + static inline const Register XHL{0xec}; + static inline const Register XIX{0xf0}; + static inline const Register XIY{0xf4}; + static inline const Register XIZ{0xf8}; + static inline const Register XSP{0xfc}; static inline const FlagRegister F {0}; static inline const FlagRegister FP{1}; @@ -261,32 +261,32 @@ struct TLCS900H { static inline const StatusRegister SR{}; static inline const ProgramCounter PC{}; - static inline const ControlRegister DMAS0{0x00}; - static inline const ControlRegister DMAS1{0x04}; - static inline const ControlRegister DMAS2{0x08}; - static inline const ControlRegister DMAS3{0x0c}; - static inline const ControlRegister DMAD0{0x10}; - static inline const ControlRegister DMAD1{0x14}; - static inline const ControlRegister DMAD2{0x18}; - static inline const ControlRegister DMAD3{0x1c}; - static inline const ControlRegister DMAM0{0x20}; - static inline const ControlRegister DMAM1{0x24}; - static inline const ControlRegister DMAM2{0x28}; - static inline const ControlRegister DMAM3{0x2c}; - - static inline const ControlRegister DMAC0{0x20}; - static inline const ControlRegister DMAC1{0x24}; - static inline const ControlRegister DMAC2{0x28}; - static inline const ControlRegister DMAC3{0x2c}; - static inline const ControlRegister INTNEST{0x3c}; - - static inline const uint4 False{0x00}; - static inline const uint4 True {0x08}; - - static inline const uint1 Undefined = 0; + static inline const ControlRegister DMAS0{0x00}; + static inline const ControlRegister DMAS1{0x04}; + static inline const ControlRegister DMAS2{0x08}; + static inline const ControlRegister DMAS3{0x0c}; + static inline const ControlRegister DMAD0{0x10}; + static inline const ControlRegister DMAD1{0x14}; + static inline const ControlRegister DMAD2{0x18}; + static inline const ControlRegister DMAD3{0x1c}; + static inline const ControlRegister DMAM0{0x20}; + static inline const ControlRegister DMAM1{0x24}; + static inline const ControlRegister DMAM2{0x28}; + static inline const ControlRegister DMAM3{0x2c}; + + static inline const ControlRegister DMAC0{0x20}; + static inline const ControlRegister DMAC1{0x24}; + static inline const ControlRegister DMAC2{0x28}; + static inline const ControlRegister DMAC3{0x2c}; + static inline const ControlRegister INTNEST{0x3c}; + + static inline const n4 False{0x00}; + static inline const n4 True {0x08}; + + static inline const n1 Undefined = 0; //disassembler.cpp - virtual auto disassembleRead(uint24 address) -> uint8 { return read(Byte, address); } + virtual auto disassembleRead(n24 address) -> n8 { return read(Byte, address); } noinline auto disassembleInstruction() -> string; noinline auto disassembleContext() -> string; }; diff --git a/ares/component/processor/upd96050/disassembler.cpp b/ares/component/processor/upd96050/disassembler.cpp index 6b85f79679..4189124569 100644 --- a/ares/component/processor/upd96050/disassembler.cpp +++ b/ares/component/processor/upd96050/disassembler.cpp @@ -1,19 +1,19 @@ -auto uPD96050::disassembleInstruction(maybe _ip) -> string { - uint14 ip = _ip ? *_ip : (uint14)regs.pc; +auto uPD96050::disassembleInstruction(maybe _ip) -> string { + n14 ip = _ip ? *_ip : (n14)regs.pc; string output; - uint24 opcode = programROM[ip]; - uint2 type = opcode >> 22; + n24 opcode = programROM[ip]; + n2 type = opcode >> 22; if(type == 0 || type == 1) { //OP,RT - uint2 pselect = opcode >> 20; - uint4 alu = opcode >> 16; - uint1 asl = opcode >> 15; - uint2 dpl = opcode >> 13; - uint4 dphm = opcode >> 9; - uint1 rpdcr = opcode >> 8; - uint4 src = opcode >> 4; - uint4 dst = opcode >> 0; + n2 pselect = opcode >> 20; + n4 alu = opcode >> 16; + n1 asl = opcode >> 15; + n2 dpl = opcode >> 13; + n4 dphm = opcode >> 9; + n1 rpdcr = opcode >> 8; + n4 src = opcode >> 4; + n4 dst = opcode >> 0; switch(alu) { case 0: output.append("nop "); break; @@ -111,11 +111,11 @@ auto uPD96050::disassembleInstruction(maybe _ip) -> string { } if(type == 2) { //JP - uint9 brch = opcode >> 13; - uint11 na = opcode >> 2; - uint8 bank = opcode >> 0; + n9 brch = opcode >> 13; + n11 na = opcode >> 2; + n8 bank = opcode >> 0; - uint14 jp = (regs.pc & 0x2000) | (bank << 11) | (na << 0); + n14 jp = (regs.pc & 0x2000) | (bank << 11) | (na << 0); switch(brch) { case 0x000: output.append("jmpso "); jp = 0; break; @@ -165,8 +165,8 @@ auto uPD96050::disassembleInstruction(maybe _ip) -> string { if(type == 3) { //LD output.append("ld "); - uint16 id = opcode >> 6; - uint4 dst = opcode >> 0; + n16 id = opcode >> 6; + n4 dst = opcode >> 0; output.append("$", hex(id, 4L), ","); diff --git a/ares/component/processor/upd96050/instructions.cpp b/ares/component/processor/upd96050/instructions.cpp index b881846064..ae2d4a4f48 100644 --- a/ares/component/processor/upd96050/instructions.cpp +++ b/ares/component/processor/upd96050/instructions.cpp @@ -1,5 +1,5 @@ auto uPD96050::exec() -> void { - uint24 opcode = programROM[regs.pc++]; + n24 opcode = programROM[regs.pc++]; switch(opcode >> 22) { case 0: execOP(opcode); break; case 1: execRT(opcode); break; @@ -7,22 +7,22 @@ auto uPD96050::exec() -> void { case 3: execLD(opcode); break; } - int32 result = (int32)regs.k * regs.l; //sign + 30-bit result + i32 result = (i32)regs.k * regs.l; //sign + 30-bit result regs.m = result >> 15; //store sign + top 15-bits regs.n = result << 1; //store low 15-bits + zero } -auto uPD96050::execOP(uint24 opcode) -> void { - uint2 pselect = opcode >> 20; //P select - uint4 alu = opcode >> 16; //ALU operation mode - uint1 asl = opcode >> 15; //accumulator select - uint2 dpl = opcode >> 13; //DP low modify - uint4 dphm = opcode >> 9; //DP high XOR modify - uint1 rpdcr = opcode >> 8; //RP decrement - uint4 src = opcode >> 4; //move source - uint4 dst = opcode >> 0; //move destination - - uint16 idb; +auto uPD96050::execOP(n24 opcode) -> void { + n2 pselect = opcode >> 20; //P select + n4 alu = opcode >> 16; //ALU operation mode + n1 asl = opcode >> 15; //accumulator select + n2 dpl = opcode >> 13; //DP low modify + n4 dphm = opcode >> 9; //DP high XOR modify + n1 rpdcr = opcode >> 8; //RP decrement + n4 src = opcode >> 4; //move source + n4 dst = opcode >> 0; //move destination + + n16 idb; switch(src) { case 0: idb = regs.trb; break; case 1: idb = regs.a; break; @@ -43,7 +43,7 @@ auto uPD96050::execOP(uint24 opcode) -> void { } if(alu) { - uint16 p, q, r; + n16 p, q, r; Flag flag; boolean c; @@ -102,8 +102,8 @@ auto uPD96050::execOP(uint24 opcode) -> void { case 7: //ADC case 8: //DEC case 9: { //INC - uint16 carries = q ^ p ^ r; - uint16 overflow = (q ^ r) & (p ^ (alu & 1 ? r : q)); + n16 carries = q ^ p ^ r; + n16 overflow = (q ^ r) & (p ^ (alu & 1 ? r : q)); flag.ov0 = overflow & 0x8000; flag.ov1 = flag.ov0 & flag.ov1 ? flag.s0 == flag.s1 : flag.ov0 | flag.ov1; flag.c = (carries ^ overflow) & 0x8000; @@ -148,17 +148,17 @@ auto uPD96050::execOP(uint24 opcode) -> void { } } -auto uPD96050::execRT(uint24 opcode) -> void { +auto uPD96050::execRT(n24 opcode) -> void { execOP(opcode); regs.pc = regs.stack[--regs.sp]; } -auto uPD96050::execJP(uint24 opcode) -> void { - uint9 brch = opcode >> 13; //branch - uint11 na = opcode >> 2; //next address - uint2 bank = opcode >> 0; //bank address +auto uPD96050::execJP(n24 opcode) -> void { + n9 brch = opcode >> 13; //branch + n11 na = opcode >> 2; //next address + n2 bank = opcode >> 0; //bank address - uint14 jp = regs.pc & 0x2000 | bank << 11 | na << 0; + n14 jp = regs.pc & 0x2000 | bank << 11 | na << 0; switch(brch) { case 0x000: regs.pc = regs.so; return; //JMPSO @@ -215,9 +215,9 @@ auto uPD96050::execJP(uint24 opcode) -> void { } } -auto uPD96050::execLD(uint24 opcode) -> void { - uint16 id = opcode >> 6; //immediate data - uint4 dst = opcode >> 0; //destination +auto uPD96050::execLD(n24 opcode) -> void { + n16 id = opcode >> 6; //immediate data + n4 dst = opcode >> 0; //destination switch(dst) { case 0: break; diff --git a/ares/component/processor/upd96050/memory.cpp b/ares/component/processor/upd96050/memory.cpp index 1d3df9a244..43276f263b 100644 --- a/ares/component/processor/upd96050/memory.cpp +++ b/ares/component/processor/upd96050/memory.cpp @@ -1,11 +1,11 @@ -auto uPD96050::readSR() -> uint8 { +auto uPD96050::readSR() -> n8 { return regs.sr >> 8; } -auto uPD96050::writeSR(uint8 data) -> void { +auto uPD96050::writeSR(n8 data) -> void { } -auto uPD96050::readDR() -> uint8 { +auto uPD96050::readDR() -> n8 { if(regs.sr.drc == 0) { //16-bit if(regs.sr.drs == 0) { @@ -23,7 +23,7 @@ auto uPD96050::readDR() -> uint8 { } } -auto uPD96050::writeDR(uint8 data) -> void { +auto uPD96050::writeDR(n8 data) -> void { if(regs.sr.drc == 0) { //16-bit if(regs.sr.drs == 0) { @@ -41,24 +41,24 @@ auto uPD96050::writeDR(uint8 data) -> void { } } -auto uPD96050::readDP(uint12 addr) -> uint8 { - bool hi = addr & 1; - addr = (addr >> 1) & 2047; +auto uPD96050::readDP(n12 address) -> n8 { + bool hi = address & 1; + address = (address >> 1) & 2047; if(hi == false) { - return dataRAM[addr] >> 0; + return dataRAM[address] >> 0; } else { - return dataRAM[addr] >> 8; + return dataRAM[address] >> 8; } } -auto uPD96050::writeDP(uint12 addr, uint8 data) -> void { - bool hi = addr & 1; - addr = (addr >> 1) & 2047; +auto uPD96050::writeDP(n12 address, n8 data) -> void { + bool hi = address & 1; + address = (address >> 1) & 2047; if(hi == false) { - dataRAM[addr] = (dataRAM[addr] & 0xff00) | (data << 0); + dataRAM[address] = (dataRAM[address] & 0xff00) | (data << 0); } else { - dataRAM[addr] = (dataRAM[addr] & 0x00ff) | (data << 8); + dataRAM[address] = (dataRAM[address] & 0x00ff) | (data << 8); } } diff --git a/ares/component/processor/upd96050/upd96050.cpp b/ares/component/processor/upd96050/upd96050.cpp index ceb29895d5..aec032780a 100644 --- a/ares/component/processor/upd96050/upd96050.cpp +++ b/ares/component/processor/upd96050/upd96050.cpp @@ -21,7 +21,7 @@ auto uPD96050::power() -> void { regs.dp.resize(11); } - for(uint n : range(16)) regs.stack[n] = 0x0000; + for(u32 n : range(16)) regs.stack[n] = 0x0000; regs.pc = 0x0000; regs.rp = 0x0000; regs.dp = 0x0000; diff --git a/ares/component/processor/upd96050/upd96050.hpp b/ares/component/processor/upd96050/upd96050.hpp index 2717d85637..b8cd24ea0d 100644 --- a/ares/component/processor/upd96050/upd96050.hpp +++ b/ares/component/processor/upd96050/upd96050.hpp @@ -10,35 +10,35 @@ struct uPD96050 { auto exec() -> void; auto serialize(serializer&) -> void; - auto execOP(uint24 opcode) -> void; - auto execRT(uint24 opcode) -> void; - auto execJP(uint24 opcode) -> void; - auto execLD(uint24 opcode) -> void; + auto execOP(n24 opcode) -> void; + auto execRT(n24 opcode) -> void; + auto execJP(n24 opcode) -> void; + auto execLD(n24 opcode) -> void; - auto readSR() -> uint8; - auto writeSR(uint8 data) -> void; + auto readSR() -> n8; + auto writeSR(n8 data) -> void; - auto readDR() -> uint8; - auto writeDR(uint8 data) -> void; + auto readDR() -> n8; + auto writeDR(n8 data) -> void; - auto readDP(uint12 addr) -> uint8; - auto writeDP(uint12 addr, uint8 data) -> void; + auto readDP(n12 address) -> n8; + auto writeDP(n12 address, n8 data) -> void; //disassembler.cpp - noinline auto disassembleInstruction(maybe ip = {}) -> string; + noinline auto disassembleInstruction(maybe ip = {}) -> string; noinline auto disassembleContext() -> string; - enum class Revision : uint { uPD7725, uPD96050 } revision; - uint24 programROM[16384]; - uint16 dataROM[2048]; - uint16 dataRAM[2048]; + enum class Revision : u32 { uPD7725, uPD96050 } revision; + n24 programROM[16384]; + n16 dataROM[2048]; + n16 dataRAM[2048]; struct Flag { - operator uint() const { + operator u32() const { return ov0 << 0 | ov1 << 1 | z << 2 | c << 3 | s0 << 4 | s1 << 5; } - auto operator=(uint16 data) -> Flag& { + auto operator=(n16 data) -> Flag& { ov0 = data.bit(0); ov1 = data.bit(1); z = data.bit(2); @@ -59,13 +59,13 @@ struct uPD96050 { }; struct Status { - operator uint() const { + operator u32() const { bool _drs = drs & !drc; //when DRC=1, DRS=0 return p0 << 0 | p1 << 1 | ei << 7 | sic << 8 | soc << 9 | drc << 10 | dma << 11 | _drs << 12 | usf0 << 13 | usf1 << 14 | rqm << 15; } - auto operator=(uint16 data) -> Status& { + auto operator=(n16 data) -> Status& { p0 = data.bit( 0); p1 = data.bit( 1); ei = data.bit( 7); @@ -102,22 +102,22 @@ struct uPD96050 { struct Registers { auto serialize(serializer&) -> void; - uint16 stack[16]; //LIFO + n16 stack[16]; //LIFO VariadicNatural pc; //program counter VariadicNatural rp; //ROM pointer VariadicNatural dp; //data pointer - uint4 sp; //stack pointer - uint16 si; //serial input - uint16 so; //serial output - int16 k; - int16 l; - int16 m; - int16 n; - int16 a; //accumulator - int16 b; //accumulator - uint16 tr; //temporary register - uint16 trb; //temporary register - uint16 dr; //data register + n4 sp; //stack pointer + n16 si; //serial input + n16 so; //serial output + i16 k; + i16 l; + i16 m; + i16 n; + i16 a; //accumulator + i16 b; //accumulator + n16 tr; //temporary register + n16 trb; //temporary register + n16 dr; //data register Status sr; //status register } regs; diff --git a/ares/component/processor/v30mz/algorithms.cpp b/ares/component/processor/v30mz/algorithms.cpp index 340480521d..2a91012506 100644 --- a/ares/component/processor/v30mz/algorithms.cpp +++ b/ares/component/processor/v30mz/algorithms.cpp @@ -1,5 +1,5 @@ //(0 = odd, 1 = even) number of bits set in value -auto V30MZ::parity(uint8 value) const -> bool { +auto V30MZ::parity(n8 value) const -> bool { value ^= value >> 4; value ^= value >> 2; value ^= value >> 1; @@ -10,23 +10,23 @@ auto V30MZ::parity(uint8 value) const -> bool { #define mask (size == Byte ? 0xff : 0xffff) #define sign (size == Byte ? 0x80 : 0x8000) -auto V30MZ::ADC(Size size, uint16 x, uint16 y) -> uint16 { +auto V30MZ::ADC(Size size, n16 x, n16 y) -> n16 { return ADD(size, x, y + r.f.c); } -auto V30MZ::ADD(Size size, uint16 x, uint16 y) -> uint16 { - uint16 result = (x + y) & mask; +auto V30MZ::ADD(Size size, n16 x, n16 y) -> n16 { + n16 result = (x + y) & mask; r.f.c = x + y > mask; r.f.p = parity(result); - r.f.h = (uint4)x + (uint4)y >= 16; + r.f.h = (n4)x + (n4)y >= 16; r.f.z = result == 0; r.f.s = result & sign; r.f.v = (result ^ x) & (result ^ y) & sign; return result; } -auto V30MZ::AND(Size size, uint16 x, uint16 y) -> uint16 { - uint16 result = (x & y) & mask; +auto V30MZ::AND(Size size, n16 x, n16 y) -> n16 { + n16 result = (x & y) & mask; r.f.c = 0; r.f.p = parity(result); r.f.h = 0; @@ -36,8 +36,8 @@ auto V30MZ::AND(Size size, uint16 x, uint16 y) -> uint16 { return result; } -auto V30MZ::DEC(Size size, uint16 x) -> uint16 { - uint16 result = (x - 1) & mask; +auto V30MZ::DEC(Size size, n16 x) -> n16 { + n16 result = (x - 1) & mask; r.f.p = parity(result); r.f.h = (x & 0x0f) == 0; r.f.z = result == 0; @@ -46,24 +46,24 @@ auto V30MZ::DEC(Size size, uint16 x) -> uint16 { return result; } -auto V30MZ::DIV(Size size, uint32 x, uint32 y) -> uint32 { +auto V30MZ::DIV(Size size, n32 x, n32 y) -> n32 { if(y == 0) return interrupt(0), 0; - uint32 quotient = x / y; - uint32 remainder = x % y; + n32 quotient = x / y; + n32 remainder = x % y; return (remainder & mask) << bits | (quotient & mask); } -auto V30MZ::DIVI(Size size, int32 x, int32 y) -> uint32 { +auto V30MZ::DIVI(Size size, i32 x, i32 y) -> n32 { if(y == 0) return interrupt(0), 0; - x = size == Byte ? (int8_t)x : (int16_t)x; - y = size == Byte ? (int8_t)y : (int16_t)y; - uint32 quotient = x / y; - uint32 remainder = x % y; + x = size == Byte ? (s8)x : (s16)x; + y = size == Byte ? (s8)y : (s16)y; + n32 quotient = x / y; + n32 remainder = x % y; return (remainder & mask) << bits | (quotient & mask); } -auto V30MZ::INC(Size size, uint16 x) -> uint16 { - uint16 result = (x + 1) & mask; +auto V30MZ::INC(Size size, n16 x) -> n16 { + n16 result = (x + 1) & mask; r.f.p = parity(result); r.f.h = (x & 0x0f) == 0x0f; r.f.z = result == 0; @@ -72,24 +72,24 @@ auto V30MZ::INC(Size size, uint16 x) -> uint16 { return result; } -auto V30MZ::MUL(Size size, uint16 x, uint16 y) -> uint32 { - uint32 result = x * y; +auto V30MZ::MUL(Size size, n16 x, n16 y) -> n32 { + n32 result = x * y; r.f.c = result >> bits; r.f.v = result >> bits; return result; } -auto V30MZ::MULI(Size size, int16 x, int16 y) -> uint32 { - x = size == Byte ? (int8_t)x : (int16_t)x; - y = size == Byte ? (int8_t)y : (int16_t)y; - uint32 result = x * y; +auto V30MZ::MULI(Size size, i16 x, i16 y) -> n32 { + x = size == Byte ? (s8)x : (s16)x; + y = size == Byte ? (s8)y : (s16)y; + n32 result = x * y; r.f.c = result >> bits; r.f.v = result >> bits; return result; } -auto V30MZ::NEG(Size size, uint16 x) -> uint16 { - uint16 result = (-x) & mask; +auto V30MZ::NEG(Size size, n16 x) -> n16 { + n16 result = (-x) & mask; r.f.c = x; r.f.p = parity(result); r.f.h = x & 0x0f; @@ -99,13 +99,13 @@ auto V30MZ::NEG(Size size, uint16 x) -> uint16 { return result; } -auto V30MZ::NOT(Size size, uint16 x) -> uint16 { - uint16 result = (~x) & mask; +auto V30MZ::NOT(Size size, n16 x) -> n16 { + n16 result = (~x) & mask; return result; } -auto V30MZ::OR(Size size, uint16 x, uint16 y) -> uint16 { - uint16 result = (x | y) & mask; +auto V30MZ::OR(Size size, n16 x, n16 y) -> n16 { + n16 result = (x | y) & mask; r.f.c = 0; r.f.p = parity(result); r.f.h = 0; @@ -115,9 +115,9 @@ auto V30MZ::OR(Size size, uint16 x, uint16 y) -> uint16 { return result; } -auto V30MZ::RCL(Size size, uint16 x, uint5 y) -> uint16 { - uint16 result = x; - for(uint n = 0; n < y; n++) { +auto V30MZ::RCL(Size size, n16 x, n5 y) -> n16 { + n16 result = x; + for(u32 n = 0; n < y; n++) { bool carry = result & sign; result = (result << 1) | r.f.c; r.f.c = carry; @@ -126,9 +126,9 @@ auto V30MZ::RCL(Size size, uint16 x, uint5 y) -> uint16 { return result & mask; } -auto V30MZ::RCR(Size size, uint16 x, uint5 y) -> uint16 { - uint16 result = x; - for(uint n = 0; n < y; n++) { +auto V30MZ::RCR(Size size, n16 x, n5 y) -> n16 { + n16 result = x; + for(u32 n = 0; n < y; n++) { bool carry = result & 1; result = (r.f.c ? sign : 0) | (result >> 1); r.f.c = carry; @@ -137,23 +137,23 @@ auto V30MZ::RCR(Size size, uint16 x, uint5 y) -> uint16 { return result & mask; } -auto V30MZ::ROL(Size size, uint16 x, uint4 y) -> uint16 { +auto V30MZ::ROL(Size size, n16 x, n4 y) -> n16 { r.f.c = (x << y) & (1 << bits); - uint16 result = ((x << y) | (x >> (bits - y))) & mask; + n16 result = ((x << y) | (x >> (bits - y))) & mask; r.f.v = (x ^ result) & sign; return result; } -auto V30MZ::ROR(Size size, uint16 x, uint4 y) -> uint16 { +auto V30MZ::ROR(Size size, n16 x, n4 y) -> n16 { r.f.c = (x >> (y - 1)) & 1; - uint16 result = ((x >> y) | (x << (bits - y))) & mask; + n16 result = ((x >> y) | (x << (bits - y))) & mask; r.f.v = (x ^ result) & sign; return result; } -auto V30MZ::SAL(Size size, uint16 x, uint5 y) -> uint16 { +auto V30MZ::SAL(Size size, n16 x, n5 y) -> n16 { r.f.c = (x << y) & (1 << bits); - uint16 result = (x << y) & mask; + n16 result = (x << y) & mask; r.f.p = parity(result); r.f.z = result == 0; r.f.s = result & sign; @@ -161,13 +161,13 @@ auto V30MZ::SAL(Size size, uint16 x, uint5 y) -> uint16 { return result; } -auto V30MZ::SAR(Size size, uint16 x, uint5 y) -> uint16 { +auto V30MZ::SAR(Size size, n16 x, n5 y) -> n16 { if(y & 16) { r.f.c = x & sign; return 0 - r.f.c; } r.f.c = (x >> (y - 1)) & 1; - uint16 result = (x >> y) & mask; + n16 result = (x >> y) & mask; if(x & sign) result |= mask << (bits - y); r.f.p = parity(result); r.f.z = result == 0; @@ -176,13 +176,13 @@ auto V30MZ::SAR(Size size, uint16 x, uint5 y) -> uint16 { return result; } -auto V30MZ::SBB(Size size, uint16 x, uint16 y) -> uint16 { +auto V30MZ::SBB(Size size, n16 x, n16 y) -> n16 { return SUB(size, x, y + r.f.c); } -auto V30MZ::SHL(Size size, uint16 x, uint5 y) -> uint16 { +auto V30MZ::SHL(Size size, n16 x, n5 y) -> n16 { r.f.c = (x << y) & (1 << bits); - uint16 result = (x << y) & mask; + n16 result = (x << y) & mask; r.f.p = parity(result); r.f.z = result == 0; r.f.s = result & sign; @@ -190,9 +190,9 @@ auto V30MZ::SHL(Size size, uint16 x, uint5 y) -> uint16 { return result; } -auto V30MZ::SHR(Size size, uint16 x, uint5 y) -> uint16 { +auto V30MZ::SHR(Size size, n16 x, n5 y) -> n16 { r.f.c = (x >> (y - 1)) & 1; - uint16 result = (x >> y) & mask; + n16 result = (x >> y) & mask; r.f.p = parity(result); r.f.z = result == 0; r.f.s = result & sign; @@ -200,19 +200,19 @@ auto V30MZ::SHR(Size size, uint16 x, uint5 y) -> uint16 { return result; } -auto V30MZ::SUB(Size size, uint16 x, uint16 y) -> uint16 { - uint16 result = (x - y) & mask; +auto V30MZ::SUB(Size size, n16 x, n16 y) -> n16 { + n16 result = (x - y) & mask; r.f.c = y > x; r.f.p = parity(result); - r.f.h = (uint4)y > (uint4)x; + r.f.h = (n4)y > (n4)x; r.f.z = result == 0; r.f.s = result & sign; r.f.v = (x ^ y) & (x ^ result) & sign; return result; } -auto V30MZ::XOR(Size size, uint16 x, uint16 y) -> uint16 { - uint16 result = (x ^ y) & mask; +auto V30MZ::XOR(Size size, n16 x, n16 y) -> n16 { + n16 result = (x ^ y) & mask; r.f.c = 0; r.f.p = parity(result); r.f.h = 0; diff --git a/ares/component/processor/v30mz/disassembler.cpp b/ares/component/processor/v30mz/disassembler.cpp index 2e9dc23848..ea0b21445c 100644 --- a/ares/component/processor/v30mz/disassembler.cpp +++ b/ares/component/processor/v30mz/disassembler.cpp @@ -1,15 +1,15 @@ -auto V30MZ::disassembleInstruction(uint16 cs, uint16 ip) -> string { +auto V30MZ::disassembleInstruction(n16 cs, n16 ip) -> string { //hack: prefixes execute as separate instructions; combine them instead - static uint32 suppress = 0xffffffff; + static n32 suppress = 0xffffffff; if((cs << 16 | ip) == suppress) return {}; string output, repeat, prefix; - auto read = [&](uint offset) -> uint8 { + auto read = [&](u32 offset) -> n8 { return V30MZ::read(Byte, cs, ip + offset); }; - auto modRM = [&](uint offset = 1) -> uint { + auto modRM = [&](u32 offset = 1) -> u32 { auto modRM = read(offset++); if((modRM & 0xc7) == 0x06) return offset + 2; if((modRM & 0xc0) == 0x40) return offset + 1; @@ -32,72 +32,72 @@ auto V30MZ::disassembleInstruction(uint16 cs, uint16 ip) -> string { return {opcode}; }; - auto segmentRegister = [&](uint offset = 1) -> string { + auto segmentRegister = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string seg[] = {"es", "cs", "ss", "ds"}; return {seg[modRM >> 3 & 2]}; }; - auto readByte = [&](uint offset) -> string { + auto readByte = [&](u32 offset) -> string { return hex(read(offset), 2L); }; - auto immediateByte = [&](uint offset = 1) -> string { + auto immediateByte = [&](u32 offset = 1) -> string { return {"0x", readByte(offset)}; }; - auto immediateWord = [&](uint offset = 1) -> string { + auto immediateWord = [&](u32 offset = 1) -> string { return {"0x", readByte(offset + 1), readByte(offset + 0)}; }; - auto immediateLong = [&](uint offset = 1) -> string { + auto immediateLong = [&](u32 offset = 1) -> string { return {"0x", readByte(offset + 3), readByte(offset + 2), ":", "0x", readByte(offset + 1), readByte(offset + 0)}; }; - auto indirectByte = [&](uint offset = 1) -> string { + auto indirectByte = [&](u32 offset = 1) -> string { return {"[", immediateByte(), "]"}; }; - auto indirectWord = [&](uint offset = 1) -> string { + auto indirectWord = [&](u32 offset = 1) -> string { return {"[", immediateWord(), "]"}; }; - auto relativeByte = [&](uint offset = 1) -> string { - int8 displacement = read(offset); + auto relativeByte = [&](u32 offset = 1) -> string { + i8 displacement = read(offset); return {"cs:0x", hex(ip + offset + 1 + displacement, 4L)}; }; - auto relativeWord = [&](uint offset = 1) -> string { - int16 displacement = read(offset + 1) << 8 | read(offset + 0) << 0; + auto relativeWord = [&](u32 offset = 1) -> string { + i16 displacement = read(offset + 1) << 8 | read(offset + 0) << 0; return {"cs:0x", hex(ip + offset + 2 + displacement, 4L)}; }; - auto adjustByte = [&](uint offset = 2) -> string { - int8 displacement = read(offset); + auto adjustByte = [&](u32 offset = 2) -> string { + i8 displacement = read(offset); if(displacement >= 0) return {"+0x", hex(displacement, 2L)}; return {"-0x", hex(abs(displacement), 2L)}; }; - auto adjustWord = [&](uint offset = 2) -> string { - int16 displacement = read(offset + 1) << 8 | read(offset + 0) << 0; + auto adjustWord = [&](u32 offset = 2) -> string { + i16 displacement = read(offset + 1) << 8 | read(offset + 0) << 0; if(displacement >= 0) return {"+0x", hex(displacement, 4L)}; return {"-0x", hex(abs(displacement), 2L)}; }; - auto registerByte = [&](uint offset = 1) -> string { + auto registerByte = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string reg[] = {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"}; return reg[modRM >> 3 & 7]; }; - auto registerWord = [&](uint offset = 1) -> string { + auto registerWord = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string reg[] = {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"}; return reg[modRM >> 3 & 7]; }; - auto memoryByte = [&](uint offset = 1) -> string { + auto memoryByte = [&](u32 offset = 1) -> string { auto modRM = read(offset); if(modRM >= 0xc0) { static const string reg[] = {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"}; @@ -111,7 +111,7 @@ auto V30MZ::disassembleInstruction(uint16 cs, uint16 ip) -> string { return {"byte[", segment(seg[modRM & 7]), mem[modRM & 7], "]"}; }; - auto memoryWord = [&](uint offset = 1) -> string { + auto memoryWord = [&](u32 offset = 1) -> string { auto modRM = read(offset); if(modRM >= 0xc0) { static const string reg[] = {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"}; @@ -125,25 +125,25 @@ auto V30MZ::disassembleInstruction(uint16 cs, uint16 ip) -> string { return {"word[", segment(seg[modRM & 7]), mem[modRM & 7], "]"}; }; - auto group1 = [&](uint offset = 1) -> string { + auto group1 = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string opcode[] = {"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"}; return opcode[modRM >> 3 & 7]; }; - auto group2 = [&](uint offset = 1) -> string { + auto group2 = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string opcode[] = {"rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar"}; return opcode[modRM >> 3 & 7]; }; - auto group3 = [&](uint offset = 1) -> string { + auto group3 = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string opcode[] = {"test", "test", "not", "neg", "mul", "imul", "div", "idiv"}; return opcode[modRM >> 3 & 7]; }; - auto group4 = [&](uint offset = 1) -> string { + auto group4 = [&](u32 offset = 1) -> string { auto modRM = read(offset); static const string opcode[] = {"inc", "dec", "call", "callf", "jmp", "jmpf", "push", "push"}; return opcode[modRM >> 3 & 7]; @@ -154,7 +154,7 @@ auto V30MZ::disassembleInstruction(uint16 cs, uint16 ip) -> string { break auto opcode = read(0); - for(uint index : range(7)) { + for(u32 index : range(7)) { if(opcode == 0x26) { prefix = "es"; ip++; opcode = read(0); suppress = cs << 16 | ip; continue; } if(opcode == 0x2e) { prefix = "cs"; ip++; opcode = read(0); suppress = cs << 16 | ip; continue; } if(opcode == 0x36) { prefix = "ss"; ip++; opcode = read(0); suppress = cs << 16 | ip; continue; } diff --git a/ares/component/processor/v30mz/instruction.cpp b/ares/component/processor/v30mz/instruction.cpp index 6edee074ea..228254d30f 100644 --- a/ares/component/processor/v30mz/instruction.cpp +++ b/ares/component/processor/v30mz/instruction.cpp @@ -1,4 +1,4 @@ -auto V30MZ::interrupt(uint8 vector) -> void { +auto V30MZ::interrupt(n8 vector) -> void { wait(32); state.halt = false; @@ -240,10 +240,10 @@ auto V30MZ::instruction() -> void { op(0xcd, IntImm) op(0xce, Into) op(0xcf, ReturnInt) - op(0xd0, Group2MemImm, Byte, (uint8)1) - op(0xd1, Group2MemImm, Word, (uint8)1) - op(0xd2, Group2MemImm, Byte, (uint8)r.cl) - op(0xd3, Group2MemImm, Word, (uint8)r.cl) + op(0xd0, Group2MemImm, Byte, (n8)1) + op(0xd1, Group2MemImm, Word, (n8)1) + op(0xd2, Group2MemImm, Byte, (n8)r.cl) + op(0xd3, Group2MemImm, Word, (n8)r.cl) op(0xd4, AdjustAfterMultiply) op(0xd5, AdjustAfterDivide) op(0xd6, Translate) //xlat (undocumented mirror) diff --git a/ares/component/processor/v30mz/instructions-adjust.cpp b/ares/component/processor/v30mz/instructions-adjust.cpp index aac849e752..1496b82a59 100644 --- a/ares/component/processor/v30mz/instructions-adjust.cpp +++ b/ares/component/processor/v30mz/instructions-adjust.cpp @@ -1,6 +1,6 @@ auto V30MZ::instructionDecimalAdjust(bool negate) -> void { wait(9); - uint8 al = r.al; + n8 al = r.al; if(r.f.h || ((al & 0x0f) > 0x09)) { r.al += negate ? -0x06 : 0x06; r.f.h = 1; diff --git a/ares/component/processor/v30mz/instructions-alu.cpp b/ares/component/processor/v30mz/instructions-alu.cpp index dfe496a3ae..2af8a6c75d 100644 --- a/ares/component/processor/v30mz/instructions-alu.cpp +++ b/ares/component/processor/v30mz/instructions-alu.cpp @@ -122,21 +122,21 @@ auto V30MZ::instructionTestMemReg(Size size) -> void { auto V30MZ::instructionMultiplySignedRegMemImm(Size size) -> void { wait(2); modRM(); - setReg(Word, MULI(Word, getMem(Word), size == Word ? (int16_t)fetch(Word) : (int8_t)fetch(Byte))); + setReg(Word, MULI(Word, getMem(Word), size == Word ? (s16)fetch(Word) : (s8)fetch(Byte))); } -auto V30MZ::instructionIncReg(uint16_t& reg) -> void { +auto V30MZ::instructionIncReg(u16& reg) -> void { reg = INC(Word, reg); } -auto V30MZ::instructionDecReg(uint16_t& reg) -> void { +auto V30MZ::instructionDecReg(u16& reg) -> void { reg = DEC(Word, reg); } auto V30MZ::instructionSignExtendByte() -> void { - setAcc(Word, (int8)getAcc(Byte)); + setAcc(Word, (i8)getAcc(Byte)); } auto V30MZ::instructionSignExtendWord() -> void { - setAcc(Long, (int16)getAcc(Word)); + setAcc(Long, (i16)getAcc(Word)); } diff --git a/ares/component/processor/v30mz/instructions-exec.cpp b/ares/component/processor/v30mz/instructions-exec.cpp index bc89523681..4a96f5bdf2 100644 --- a/ares/component/processor/v30mz/instructions-exec.cpp +++ b/ares/component/processor/v30mz/instructions-exec.cpp @@ -1,6 +1,6 @@ auto V30MZ::instructionLoop() -> void { wait(1); - auto offset = (int8)fetch(); + auto offset = (i8)fetch(); if(--r.cx) { wait(3); r.ip += offset; @@ -9,7 +9,7 @@ auto V30MZ::instructionLoop() -> void { auto V30MZ::instructionLoopWhile(bool value) -> void { wait(2); - auto offset = (int8)fetch(); + auto offset = (i8)fetch(); if(--r.cx && r.f.z == value) { wait(3); r.ip += offset; @@ -18,18 +18,18 @@ auto V30MZ::instructionLoopWhile(bool value) -> void { auto V30MZ::instructionJumpShort() -> void { wait(3); - auto offset = (int8)fetch(); + auto offset = (i8)fetch(); r.ip += offset; } auto V30MZ::instructionJumpIf(bool condition) -> void { - auto offset = (int8)fetch(); + auto offset = (i8)fetch(); if(condition) r.ip += offset; } auto V30MZ::instructionJumpNear() -> void { wait(3); - r.ip += (int16)fetch(Word); + r.ip += (i16)fetch(Word); } auto V30MZ::instructionJumpFar() -> void { @@ -42,7 +42,7 @@ auto V30MZ::instructionJumpFar() -> void { auto V30MZ::instructionCallNear() -> void { wait(4); - auto offset = (int16)fetch(Word); + auto offset = (i16)fetch(Word); push(r.ip); r.ip += offset; } @@ -116,7 +116,7 @@ auto V30MZ::instructionEnter() -> void { if(length) { wait(length > 1 ? 7 : 6); - for(uint n = 1; n < length; n++) { + for(u32 n = 1; n < length; n++) { wait(4); auto data = read(Word, segment(r.ss), r.bp - n * 2); push(data); @@ -131,11 +131,11 @@ auto V30MZ::instructionLeave() -> void { r.bp = pop(); } -auto V30MZ::instructionPushReg(uint16_t& reg) -> void { +auto V30MZ::instructionPushReg(u16& reg) -> void { push(reg); } -auto V30MZ::instructionPopReg(uint16_t& reg) -> void { +auto V30MZ::instructionPopReg(u16& reg) -> void { reg = pop(); if(® == &r.ss) state.poll = false; } @@ -178,7 +178,7 @@ auto V30MZ::instructionPopAll() -> void { } auto V30MZ::instructionPushImm(Size size) -> void { - if(size == Byte) push((int8)fetch(Byte)); + if(size == Byte) push((i8)fetch(Byte)); if(size == Word) push(fetch(Word)); } diff --git a/ares/component/processor/v30mz/instructions-flag.cpp b/ares/component/processor/v30mz/instructions-flag.cpp index 569137db70..17dd9e28c3 100644 --- a/ares/component/processor/v30mz/instructions-flag.cpp +++ b/ares/component/processor/v30mz/instructions-flag.cpp @@ -13,12 +13,12 @@ auto V30MZ::instructionComplementCarry() -> void { r.f.c = !r.f.c; } -auto V30MZ::instructionClearFlag(uint bit) -> void { +auto V30MZ::instructionClearFlag(u32 bit) -> void { wait(3); r.f &= ~(1 << bit); } -auto V30MZ::instructionSetFlag(uint bit) -> void { +auto V30MZ::instructionSetFlag(u32 bit) -> void { wait(3); r.f |= 1 << bit; if(bit == r.f.i.bit()) state.poll = false; diff --git a/ares/component/processor/v30mz/instructions-group.cpp b/ares/component/processor/v30mz/instructions-group.cpp index 2172271929..374c0df1a2 100644 --- a/ares/component/processor/v30mz/instructions-group.cpp +++ b/ares/component/processor/v30mz/instructions-group.cpp @@ -1,8 +1,8 @@ auto V30MZ::instructionGroup1MemImm(Size size, bool sign) -> void { modRM(); auto mem = getMem(size); - uint16 imm = 0; - if(sign) imm = (int8)fetch(); + n16 imm = 0; + if(sign) imm = (i8)fetch(); else if(size == Byte) imm = fetch(); else imm = fetch(Word); switch(modrm.reg) { @@ -17,7 +17,7 @@ auto V30MZ::instructionGroup1MemImm(Size size, bool sign) -> void { } } -auto V30MZ::instructionGroup2MemImm(Size size, maybe imm) -> void { +auto V30MZ::instructionGroup2MemImm(Size size, maybe imm) -> void { modRM(); auto mem = getMem(size); if(!imm) { diff --git a/ares/component/processor/v30mz/instructions-misc.cpp b/ares/component/processor/v30mz/instructions-misc.cpp index 269d6d636d..096f954efe 100644 --- a/ares/component/processor/v30mz/instructions-misc.cpp +++ b/ares/component/processor/v30mz/instructions-misc.cpp @@ -1,4 +1,4 @@ -auto V30MZ::instructionSegment(uint16 segment) -> void { +auto V30MZ::instructionSegment(n16 segment) -> void { if(prefixes.size() >= 7) prefixes.removeRight(); prefixes.prepend(opcode); state.prefix = true; diff --git a/ares/component/processor/v30mz/instructions-move.cpp b/ares/component/processor/v30mz/instructions-move.cpp index 2f1b4a6261..09f31f1de8 100644 --- a/ares/component/processor/v30mz/instructions-move.cpp +++ b/ares/component/processor/v30mz/instructions-move.cpp @@ -29,11 +29,11 @@ auto V30MZ::instructionMoveMemAcc(Size size) -> void { write(size, segment(r.ds), fetch(Word), getAcc(size)); } -auto V30MZ::instructionMoveRegImm(uint8_t& reg) -> void { +auto V30MZ::instructionMoveRegImm(u8& reg) -> void { reg = fetch(Byte); } -auto V30MZ::instructionMoveRegImm(uint16_t& reg) -> void { +auto V30MZ::instructionMoveRegImm(u16& reg) -> void { reg = fetch(Word); } @@ -42,9 +42,9 @@ auto V30MZ::instructionMoveMemImm(Size size) -> void { setMem(size, fetch(size)); } -auto V30MZ::instructionExchange(uint16_t& x, uint16_t& y) -> void { +auto V30MZ::instructionExchange(u16& x, u16& y) -> void { wait(2); - uint16 z = x; + n16 z = x; x = y; y = z; } @@ -63,7 +63,7 @@ auto V30MZ::instructionLoadEffectiveAddressRegMem() -> void { setReg(Word, modrm.address); } -auto V30MZ::instructionLoadSegmentMem(uint16_t& segment) -> void { +auto V30MZ::instructionLoadSegmentMem(u16& segment) -> void { wait(5); modRM(); setReg(Word, getMem(Word)); diff --git a/ares/component/processor/v30mz/memory.cpp b/ares/component/processor/v30mz/memory.cpp index bcc9cd2419..dab669755a 100644 --- a/ares/component/processor/v30mz/memory.cpp +++ b/ares/component/processor/v30mz/memory.cpp @@ -1,5 +1,5 @@ -auto V30MZ::read(Size size, uint16 segment, uint16 address) -> uint32 { - uint32 data; +auto V30MZ::read(Size size, n16 segment, n16 address) -> n32 { + n32 data; if(size >= Byte) data.byte(0) = read(segment * 16 + address++); if(size >= Word) data.byte(1) = read(segment * 16 + address++); if(size >= Long) data.byte(2) = read(segment * 16 + address++); @@ -7,41 +7,41 @@ auto V30MZ::read(Size size, uint16 segment, uint16 address) -> uint32 { return data; } -auto V30MZ::write(Size size, uint16 segment, uint16 address, uint16 data) -> void { +auto V30MZ::write(Size size, n16 segment, n16 address, n16 data) -> void { if(size >= Byte) write(segment * 16 + address++, data.byte(0)); if(size >= Word) write(segment * 16 + address++, data.byte(1)); } // -auto V30MZ::in(Size size, uint16 address) -> uint16 { - uint16 data; +auto V30MZ::in(Size size, n16 address) -> n16 { + n16 data; if(size >= Byte) data.byte(0) = in(address++); if(size >= Word) data.byte(1) = in(address++); return data; } -auto V30MZ::out(Size size, uint16 address, uint16 data) -> void { +auto V30MZ::out(Size size, n16 address, n16 data) -> void { if(size >= Byte) out(address++, data.byte(0)); if(size >= Word) out(address++, data.byte(1)); } // -auto V30MZ::fetch(Size size) -> uint16 { +auto V30MZ::fetch(Size size) -> n16 { wait(size); - uint16 data = read(size, r.cs, r.ip); + n16 data = read(size, r.cs, r.ip); return r.ip += size, data; } // -auto V30MZ::pop() -> uint16 { - uint16 data = read(Word, r.ss, r.sp); +auto V30MZ::pop() -> n16 { + n16 data = read(Word, r.ss, r.sp); return r.sp += Word, data; } -auto V30MZ::push(uint16 data) -> void { +auto V30MZ::push(n16 data) -> void { r.sp -= Word; write(Word, r.ss, r.sp, data); } diff --git a/ares/component/processor/v30mz/modrm.cpp b/ares/component/processor/v30mz/modrm.cpp index d858bf7e1c..6296506214 100644 --- a/ares/component/processor/v30mz/modrm.cpp +++ b/ares/component/processor/v30mz/modrm.cpp @@ -18,21 +18,21 @@ auto V30MZ::modRM() -> void { case 6: modrm.segment = segment(r.ss); modrm.address = r.bp; break; case 7: modrm.segment = segment(r.ds); modrm.address = r.bx; break; } - if(modrm.mod == 1) modrm.address += (int8)fetch(Byte); - if(modrm.mod == 2) modrm.address += (int16)fetch(Word); + if(modrm.mod == 1) modrm.address += (i8 )fetch(Byte); + if(modrm.mod == 2) modrm.address += (i16)fetch(Word); } } // -auto V30MZ::getMem(Size size, uint offset) -> uint16 { +auto V30MZ::getMem(Size size, u32 offset) -> n16 { if(modrm.mod != 3) return read(size, modrm.segment, modrm.address + offset); if(size == Byte) return *r.b[modrm.mem]; if(size == Word) return *r.w[modrm.mem]; unreachable; } -auto V30MZ::setMem(Size size, uint16 data) -> void { +auto V30MZ::setMem(Size size, n16 data) -> void { if(modrm.mod != 3) return write(size, modrm.segment, modrm.address, data); if(size == Byte) *r.b[modrm.mem] = data; if(size == Word) *r.w[modrm.mem] = data; @@ -40,23 +40,23 @@ auto V30MZ::setMem(Size size, uint16 data) -> void { // -auto V30MZ::getReg(Size size) -> uint16 { +auto V30MZ::getReg(Size size) -> n16 { if(size == Byte) return *r.b[modrm.reg]; if(size == Word) return *r.w[modrm.reg]; unreachable; } -auto V30MZ::setReg(Size size, uint16 data) -> void { +auto V30MZ::setReg(Size size, n16 data) -> void { if(size == Byte) *r.b[modrm.reg] = data; if(size == Word) *r.w[modrm.reg] = data; } // -auto V30MZ::getSeg() -> uint16 { +auto V30MZ::getSeg() -> n16 { return *r.s[modrm.reg]; } -auto V30MZ::setSeg(uint16 data) -> void { +auto V30MZ::setSeg(n16 data) -> void { *r.s[modrm.reg] = data; } diff --git a/ares/component/processor/v30mz/registers.cpp b/ares/component/processor/v30mz/registers.cpp index 19b3920c83..f029c22c06 100644 --- a/ares/component/processor/v30mz/registers.cpp +++ b/ares/component/processor/v30mz/registers.cpp @@ -1,4 +1,4 @@ -auto V30MZ::repeat() -> uint8 { +auto V30MZ::repeat() -> n8 { for(auto prefix : prefixes) { if(prefix == RepeatWhileZeroLo) return prefix; if(prefix == RepeatWhileZeroHi) return prefix; @@ -6,7 +6,7 @@ auto V30MZ::repeat() -> uint8 { return {}; } -auto V30MZ::segment(uint16 segment) -> uint16 { +auto V30MZ::segment(n16 segment) -> n16 { for(auto prefix : prefixes) { if(prefix == SegmentOverrideES) return r.es; if(prefix == SegmentOverrideCS) return r.cs; @@ -16,14 +16,14 @@ auto V30MZ::segment(uint16 segment) -> uint16 { return segment; } -auto V30MZ::getAcc(Size size) -> uint32 { +auto V30MZ::getAcc(Size size) -> n32 { if(size == Byte) return r.al; if(size == Word) return r.ax; if(size == Long) return r.dx << 16 | r.ax; unreachable; } -auto V30MZ::setAcc(Size size, uint32 data) -> void { +auto V30MZ::setAcc(Size size, n32 data) -> void { if(size == Byte) r.al = data; if(size == Word) r.ax = data; if(size == Long) r.ax = data, r.dx = data >> 16; diff --git a/ares/component/processor/v30mz/serialization.cpp b/ares/component/processor/v30mz/serialization.cpp index ac4f67291d..c9f1082396 100644 --- a/ares/component/processor/v30mz/serialization.cpp +++ b/ares/component/processor/v30mz/serialization.cpp @@ -5,17 +5,17 @@ auto V30MZ::serialize(serializer& s) -> void { s(opcode); if(s.reading()) { - uint8 _prefixes[7] = {}; - uint8 _prefixCount = 0; + n8 _prefixes[7] = {}; + n8 _prefixCount = 0; s(_prefixCount); s(_prefixes); prefixes.resize(_prefixCount); - for(uint n : range(_prefixCount)) prefixes[n] = _prefixes[n]; + for(u32 n : range(_prefixCount)) prefixes[n] = _prefixes[n]; } if(s.writing()) { - uint8 _prefixes[7] = {}; - uint8 _prefixCount = prefixes.size(); - for(uint n : range(_prefixCount)) _prefixes[n] = prefixes[n]; + n8 _prefixes[7] = {}; + n8 _prefixCount = prefixes.size(); + for(u32 n : range(_prefixCount)) _prefixes[n] = prefixes[n]; s(_prefixCount); s(_prefixes); } diff --git a/ares/component/processor/v30mz/v30mz.hpp b/ares/component/processor/v30mz/v30mz.hpp index 9d6faa0ad6..3ab0e79e94 100644 --- a/ares/component/processor/v30mz/v30mz.hpp +++ b/ares/component/processor/v30mz/v30mz.hpp @@ -45,9 +45,9 @@ namespace ares { struct V30MZ { - using Size = uint; - enum : uint { Byte = 1, Word = 2, Long = 4 }; - enum : uint { + using Size = u32; + enum : u32 { Byte = 1, Word = 2, Long = 4 }; + enum : u32 { SegmentOverrideES = 0x26, SegmentOverrideCS = 0x2e, SegmentOverrideSS = 0x36, @@ -57,75 +57,75 @@ struct V30MZ { RepeatWhileZeroHi = 0xf3, }; - virtual auto wait(uint clocks = 1) -> void = 0; - virtual auto read(uint20 addr) -> uint8 = 0; - virtual auto write(uint20 addr, uint8 data) -> void = 0; - virtual auto in(uint16 port) -> uint8 = 0; - virtual auto out(uint16 port, uint8 data) -> void = 0; + virtual auto wait(u32 clocks = 1) -> void = 0; + virtual auto read(n20 address) -> n8 = 0; + virtual auto write(n20 address, n8 data) -> void = 0; + virtual auto in(n16 port) -> n8 = 0; + virtual auto out(n16 port, n8 data) -> void = 0; auto warning(string text) -> void; auto power() -> void; auto exec() -> void; //instruction.cpp - auto interrupt(uint8 vector) -> void; + auto interrupt(n8 vector) -> void; auto instruction() -> void; //registers.cpp - auto repeat() -> uint8; - auto segment(uint16) -> uint16; + auto repeat() -> n8; + auto segment(n16) -> n16; - auto getAcc(Size) -> uint32; - auto setAcc(Size, uint32) -> void; + auto getAcc(Size) -> n32; + auto setAcc(Size, n32) -> void; //modrm.cpp auto modRM() -> void; - auto getMem(Size, uint offset = 0) -> uint16; - auto setMem(Size, uint16) -> void; + auto getMem(Size, u32 offset = 0) -> n16; + auto setMem(Size, n16) -> void; - auto getReg(Size) -> uint16; - auto setReg(Size, uint16) -> void; + auto getReg(Size) -> n16; + auto setReg(Size, n16) -> void; - auto getSeg() -> uint16; - auto setSeg(uint16) -> void; + auto getSeg() -> n16; + auto setSeg(n16) -> void; //memory.cpp - auto read(Size, uint16, uint16) -> uint32; - auto write(Size, uint16, uint16, uint16) -> void; + auto read(Size, n16, n16) -> n32; + auto write(Size, n16, n16, n16) -> void; - auto in(Size, uint16) -> uint16; - auto out(Size, uint16, uint16) -> void; + auto in(Size, n16) -> n16; + auto out(Size, n16, n16) -> void; - auto fetch(Size = Byte) -> uint16; - auto pop() -> uint16; - auto push(uint16) -> void; + auto fetch(Size = Byte) -> n16; + auto pop() -> n16; + auto push(n16) -> void; //algorithms.cpp - auto parity(uint8) const -> bool; - auto ADC (Size, uint16, uint16) -> uint16; - auto ADD (Size, uint16, uint16) -> uint16; - auto AND (Size, uint16, uint16) -> uint16; - auto DEC (Size, uint16 ) -> uint16; - auto DIV (Size, uint32, uint32) -> uint32; - auto DIVI(Size, int32, int32) -> uint32; - auto INC (Size, uint16 ) -> uint16; - auto MUL (Size, uint16, uint16) -> uint32; - auto MULI(Size, int16, int16) -> uint32; - auto NEG (Size, uint16 ) -> uint16; - auto NOT (Size, uint16 ) -> uint16; - auto OR (Size, uint16, uint16) -> uint16; - auto RCL (Size, uint16, uint5) -> uint16; - auto RCR (Size, uint16, uint5) -> uint16; - auto ROL (Size, uint16, uint4) -> uint16; - auto ROR (Size, uint16, uint4) -> uint16; - auto SAL (Size, uint16, uint5) -> uint16; - auto SAR (Size, uint16, uint5) -> uint16; - auto SBB (Size, uint16, uint16) -> uint16; - auto SUB (Size, uint16, uint16) -> uint16; - auto SHL (Size, uint16, uint5) -> uint16; - auto SHR (Size, uint16, uint5) -> uint16; - auto XOR (Size, uint16, uint16) -> uint16; + auto parity(n8) const -> bool; + auto ADC (Size, n16, n16) -> n16; + auto ADD (Size, n16, n16) -> n16; + auto AND (Size, n16, n16) -> n16; + auto DEC (Size, n16 ) -> n16; + auto DIV (Size, n32, n32) -> n32; + auto DIVI(Size, i32, i32) -> n32; + auto INC (Size, n16 ) -> n16; + auto MUL (Size, n16, n16) -> n32; + auto MULI(Size, i16, i16) -> n32; + auto NEG (Size, n16 ) -> n16; + auto NOT (Size, n16 ) -> n16; + auto OR (Size, n16, n16) -> n16; + auto RCL (Size, n16, n5 ) -> n16; + auto RCR (Size, n16, n5 ) -> n16; + auto ROL (Size, n16, n4 ) -> n16; + auto ROR (Size, n16, n4 ) -> n16; + auto SAL (Size, n16, n5 ) -> n16; + auto SAR (Size, n16, n5 ) -> n16; + auto SBB (Size, n16, n16) -> n16; + auto SUB (Size, n16, n16) -> n16; + auto SHL (Size, n16, n5 ) -> n16; + auto SHR (Size, n16, n5 ) -> n16; + auto XOR (Size, n16, n16) -> n16; //instructions-adjust.cpp auto instructionDecimalAdjust(bool) -> void; @@ -161,8 +161,8 @@ struct V30MZ { auto instructionTestMemReg(Size) -> void; auto instructionTestAcc(Size) -> void; auto instructionMultiplySignedRegMemImm(Size) -> void; - auto instructionIncReg(uint16_t&) -> void; - auto instructionDecReg(uint16_t&) -> void; + auto instructionIncReg(u16&) -> void; + auto instructionDecReg(u16&) -> void; auto instructionSignExtendByte() -> void; auto instructionSignExtendWord() -> void; @@ -185,8 +185,8 @@ struct V30MZ { auto instructionInto() -> void; auto instructionEnter() -> void; auto instructionLeave() -> void; - auto instructionPushReg(uint16_t&) -> void; - auto instructionPopReg(uint16_t&) -> void; + auto instructionPushReg(u16&) -> void; + auto instructionPopReg(u16&) -> void; auto instructionPushFlags() -> void; auto instructionPopFlags() -> void; auto instructionPushAll() -> void; @@ -198,17 +198,17 @@ struct V30MZ { auto instructionStoreFlagsAcc() -> void; auto instructionLoadAccFlags() -> void; auto instructionComplementCarry() -> void; - auto instructionClearFlag(uint) -> void; - auto instructionSetFlag(uint) -> void; + auto instructionClearFlag(u32) -> void; + auto instructionSetFlag(u32) -> void; //instructions-group.cpp auto instructionGroup1MemImm(Size, bool) -> void; - auto instructionGroup2MemImm(Size, maybe = {}) -> void; + auto instructionGroup2MemImm(Size, maybe = {}) -> void; auto instructionGroup3MemImm(Size) -> void; auto instructionGroup4MemImm(Size) -> void; //instructions-misc.cpp - auto instructionSegment(uint16) -> void; + auto instructionSegment(n16) -> void; auto instructionRepeat() -> void; auto instructionLock() -> void; auto instructionWait() -> void; @@ -228,13 +228,13 @@ struct V30MZ { auto instructionMoveSegMem() -> void; auto instructionMoveAccMem(Size) -> void; auto instructionMoveMemAcc(Size) -> void; - auto instructionMoveRegImm(uint8_t&) -> void; - auto instructionMoveRegImm(uint16_t&) -> void; + auto instructionMoveRegImm(u8&) -> void; + auto instructionMoveRegImm(u16&) -> void; auto instructionMoveMemImm(Size) -> void; - auto instructionExchange(uint16_t&, uint16_t&) -> void; + auto instructionExchange(u16&, u16&) -> void; auto instructionExchangeMemReg(Size) -> void; auto instructionLoadEffectiveAddressRegMem() -> void; - auto instructionLoadSegmentMem(uint16_t&) -> void; + auto instructionLoadSegmentMem(u16&) -> void; //instructions-string.cpp auto instructionInString(Size) -> void; @@ -249,7 +249,7 @@ struct V30MZ { auto serialize(serializer&) -> void; //disassembler.cpp - auto disassembleInstruction(uint16 cs, uint16 ip) -> string; + auto disassembleInstruction(n16 cs, n16 ip) -> string; auto disassembleInstruction() -> string; auto disassembleContext() -> string; @@ -259,39 +259,39 @@ struct V30MZ { bool prefix; //set to true for prefix instructions; prevents flushing of Prefix struct } state; - uint8 opcode; - vector prefixes; + n8 opcode; + vector prefixes; struct ModRM { - uint2 mod; - uint3 reg; - uint3 mem; + n2 mod; + n3 reg; + n3 mem; - uint16 segment; - uint16 address; + n16 segment; + n16 address; } modrm; struct Registers { - union { uint16_t ax; struct { uint8_t order_lsb2(al, ah); }; }; - union { uint16_t cx; struct { uint8_t order_lsb2(cl, ch); }; }; - union { uint16_t dx; struct { uint8_t order_lsb2(dl, dh); }; }; - union { uint16_t bx; struct { uint8_t order_lsb2(bl, bh); }; }; - uint16_t sp; - uint16_t bp; - uint16_t si; - uint16_t di; - uint16_t es; - uint16_t cs; - uint16_t ss; - uint16_t ds; - uint16_t ip; - - uint8_t* b[8]{&al, &cl, &dl, &bl, &ah, &ch, &dh, &bh}; - uint16_t* w[8]{&ax, &cx, &dx, &bx, &sp, &bp, &si, &di}; - uint16_t* s[8]{&es, &cs, &ss, &ds, &es, &cs, &ss, &ds}; + union { u16 ax; struct { u8 order_lsb2(al, ah); }; }; + union { u16 cx; struct { u8 order_lsb2(cl, ch); }; }; + union { u16 dx; struct { u8 order_lsb2(dl, dh); }; }; + union { u16 bx; struct { u8 order_lsb2(bl, bh); }; }; + u16 sp; + u16 bp; + u16 si; + u16 di; + u16 es; + u16 cs; + u16 ss; + u16 ds; + u16 ip; + + u8* b[8]{&al, &cl, &dl, &bl, &ah, &ch, &dh, &bh}; + u16* w[8]{&ax, &cx, &dx, &bx, &sp, &bp, &si, &di}; + u16* s[8]{&es, &cs, &ss, &ds, &es, &cs, &ss, &ds}; struct Flags { - uint16 data; + n16 data; BitField<16, 0> c{&data}; //carry BitField<16, 2> p{&data}; //parity BitField<16, 4> h{&data}; //half-carry @@ -303,11 +303,11 @@ struct V30MZ { BitField<16,11> v{&data}; //overflow BitField<16,15> m{&data}; //mode - operator uint() const { return data & 0x8fd5 | 0x7002; } - auto& operator =(uint value) { return data = value, *this; } - auto& operator&=(uint value) { return data &= value, *this; } - auto& operator^=(uint value) { return data ^= value, *this; } - auto& operator|=(uint value) { return data |= value, *this; } + operator u32() const { return data & 0x8fd5 | 0x7002; } + auto& operator =(u32 value) { return data = value, *this; } + auto& operator&=(u32 value) { return data &= value, *this; } + auto& operator^=(u32 value) { return data ^= value, *this; } + auto& operator|=(u32 value) { return data |= value, *this; } } f; } r; }; diff --git a/ares/component/processor/wdc65816/algorithms.cpp b/ares/component/processor/wdc65816/algorithms.cpp index f4eacc34f3..de5ed92ee8 100644 --- a/ares/component/processor/wdc65816/algorithms.cpp +++ b/ares/component/processor/wdc65816/algorithms.cpp @@ -1,5 +1,5 @@ -auto WDC65816::algorithmADC8(uint8 data) -> uint8 { - int result; +auto WDC65816::algorithmADC8(n8 data) -> n8 { + s32 result; if(!DF) { result = A.l + data + CF; @@ -13,14 +13,14 @@ auto WDC65816::algorithmADC8(uint8 data) -> uint8 { VF = ~(A.l ^ data) & (A.l ^ result) & 0x80; if(DF && result > 0x9f) result += 0x60; CF = result > 0xff; - ZF = (uint8)result == 0; + ZF = (n8)result == 0; NF = result & 0x80; return A.l = result; } -auto WDC65816::algorithmADC16(uint16 data) -> uint16 { - int result; +auto WDC65816::algorithmADC16(n16 data) -> n16 { + s32 result; if(!DF) { result = A.w + data + CF; @@ -40,27 +40,27 @@ auto WDC65816::algorithmADC16(uint16 data) -> uint16 { VF = ~(A.w ^ data) & (A.w ^ result) & 0x8000; if(DF && result > 0x9fff) result += 0x6000; CF = result > 0xffff; - ZF = (uint16)result == 0; + ZF = (n16)result == 0; NF = result & 0x8000; return A.w = result; } -auto WDC65816::algorithmAND8(uint8 data) -> uint8 { +auto WDC65816::algorithmAND8(n8 data) -> n8 { A.l &= data; ZF = A.l == 0; NF = A.l & 0x80; return A.l; } -auto WDC65816::algorithmAND16(uint16 data) -> uint16 { +auto WDC65816::algorithmAND16(n16 data) -> n16 { A.w &= data; ZF = A.w == 0; NF = A.w & 0x8000; return A.w; } -auto WDC65816::algorithmASL8(uint8 data) -> uint8 { +auto WDC65816::algorithmASL8(n8 data) -> n8 { CF = data & 0x80; data <<= 1; ZF = data == 0; @@ -68,7 +68,7 @@ auto WDC65816::algorithmASL8(uint8 data) -> uint8 { return data; } -auto WDC65816::algorithmASL16(uint16 data) -> uint16 { +auto WDC65816::algorithmASL16(n16 data) -> n16 { CF = data & 0x8000; data <<= 1; ZF = data == 0; @@ -76,153 +76,153 @@ auto WDC65816::algorithmASL16(uint16 data) -> uint16 { return data; } -auto WDC65816::algorithmBIT8(uint8 data) -> uint8 { +auto WDC65816::algorithmBIT8(n8 data) -> n8 { ZF = (data & A.l) == 0; VF = data & 0x40; NF = data & 0x80; return data; } -auto WDC65816::algorithmBIT16(uint16 data) -> uint16 { +auto WDC65816::algorithmBIT16(n16 data) -> n16 { ZF = (data & A.w) == 0; VF = data & 0x4000; NF = data & 0x8000; return data; } -auto WDC65816::algorithmCMP8(uint8 data) -> uint8 { - int result = A.l - data; +auto WDC65816::algorithmCMP8(n8 data) -> n8 { + s32 result = A.l - data; CF = result >= 0; - ZF = (uint8)result == 0; + ZF = (n8)result == 0; NF = result & 0x80; return result; } -auto WDC65816::algorithmCMP16(uint16 data) -> uint16 { - int result = A.w - data; +auto WDC65816::algorithmCMP16(n16 data) -> n16 { + s32 result = A.w - data; CF = result >= 0; - ZF = (uint16)result == 0; + ZF = (n16)result == 0; NF = result & 0x8000; return result; } -auto WDC65816::algorithmCPX8(uint8 data) -> uint8 { - int result = X.l - data; +auto WDC65816::algorithmCPX8(n8 data) -> n8 { + s32 result = X.l - data; CF = result >= 0; - ZF = (uint8)result == 0; + ZF = (n8)result == 0; NF = result & 0x80; return result; } -auto WDC65816::algorithmCPX16(uint16 data) -> uint16 { - int result = X.w - data; +auto WDC65816::algorithmCPX16(n16 data) -> n16 { + s32 result = X.w - data; CF = result >= 0; - ZF = (uint16)result == 0; + ZF = (n16)result == 0; NF = result & 0x8000; return result; } -auto WDC65816::algorithmCPY8(uint8 data) -> uint8 { - int result = Y.l - data; +auto WDC65816::algorithmCPY8(n8 data) -> n8 { + s32 result = Y.l - data; CF = result >= 0; - ZF = (uint8)result == 0; + ZF = (n8)result == 0; NF = result & 0x80; return result; } -auto WDC65816::algorithmCPY16(uint16 data) -> uint16 { - int result = Y.w - data; +auto WDC65816::algorithmCPY16(n16 data) -> n16 { + s32 result = Y.w - data; CF = result >= 0; - ZF = (uint16)result == 0; + ZF = (n16)result == 0; NF = result & 0x8000; return result; } -auto WDC65816::algorithmDEC8(uint8 data) -> uint8 { +auto WDC65816::algorithmDEC8(n8 data) -> n8 { data--; ZF = data == 0; NF = data & 0x80; return data; } -auto WDC65816::algorithmDEC16(uint16 data) -> uint16 { +auto WDC65816::algorithmDEC16(n16 data) -> n16 { data--; ZF = data == 0; NF = data & 0x8000; return data; } -auto WDC65816::algorithmEOR8(uint8 data) -> uint8 { +auto WDC65816::algorithmEOR8(n8 data) -> n8 { A.l ^= data; ZF = A.l == 0; NF = A.l & 0x80; return A.l; } -auto WDC65816::algorithmEOR16(uint16 data) -> uint16 { +auto WDC65816::algorithmEOR16(n16 data) -> n16 { A.w ^= data; ZF = A.w == 0; NF = A.w & 0x8000; return A.w; } -auto WDC65816::algorithmINC8(uint8 data) -> uint8 { +auto WDC65816::algorithmINC8(n8 data) -> n8 { data++; ZF = data == 0; NF = data & 0x80; return data; } -auto WDC65816::algorithmINC16(uint16 data) -> uint16 { +auto WDC65816::algorithmINC16(n16 data) -> n16 { data++; ZF = data == 0; NF = data & 0x8000; return data; } -auto WDC65816::algorithmLDA8(uint8 data) -> uint8 { +auto WDC65816::algorithmLDA8(n8 data) -> n8 { A.l = data; ZF = A.l == 0; NF = A.l & 0x80; return data; } -auto WDC65816::algorithmLDA16(uint16 data) -> uint16 { +auto WDC65816::algorithmLDA16(n16 data) -> n16 { A.w = data; ZF = A.w == 0; NF = A.w & 0x8000; return data; } -auto WDC65816::algorithmLDX8(uint8 data) -> uint8 { +auto WDC65816::algorithmLDX8(n8 data) -> n8 { X.l = data; ZF = X.l == 0; NF = X.l & 0x80; return data; } -auto WDC65816::algorithmLDX16(uint16 data) -> uint16 { +auto WDC65816::algorithmLDX16(n16 data) -> n16 { X.w = data; ZF = X.w == 0; NF = X.w & 0x8000; return data; } -auto WDC65816::algorithmLDY8(uint8 data) -> uint8 { +auto WDC65816::algorithmLDY8(n8 data) -> n8 { Y.l = data; ZF = Y.l == 0; NF = Y.l & 0x80; return data; } -auto WDC65816::algorithmLDY16(uint16 data) -> uint16 { +auto WDC65816::algorithmLDY16(n16 data) -> n16 { Y.w = data; ZF = Y.w == 0; NF = Y.w & 0x8000; return data; } -auto WDC65816::algorithmLSR8(uint8 data) -> uint8 { +auto WDC65816::algorithmLSR8(n8 data) -> n8 { CF = data & 1; data >>= 1; ZF = data == 0; @@ -230,7 +230,7 @@ auto WDC65816::algorithmLSR8(uint8 data) -> uint8 { return data; } -auto WDC65816::algorithmLSR16(uint16 data) -> uint16 { +auto WDC65816::algorithmLSR16(n16 data) -> n16 { CF = data & 1; data >>= 1; ZF = data == 0; @@ -238,21 +238,21 @@ auto WDC65816::algorithmLSR16(uint16 data) -> uint16 { return data; } -auto WDC65816::algorithmORA8(uint8 data) -> uint8 { +auto WDC65816::algorithmORA8(n8 data) -> n8 { A.l |= data; ZF = A.l == 0; NF = A.l & 0x80; return A.l; } -auto WDC65816::algorithmORA16(uint16 data) -> uint16 { +auto WDC65816::algorithmORA16(n16 data) -> n16 { A.w |= data; ZF = A.w == 0; NF = A.w & 0x8000; return A.w; } -auto WDC65816::algorithmROL8(uint8 data) -> uint8 { +auto WDC65816::algorithmROL8(n8 data) -> n8 { bool carry = CF; CF = data & 0x80; data = data << 1 | carry; @@ -261,7 +261,7 @@ auto WDC65816::algorithmROL8(uint8 data) -> uint8 { return data; } -auto WDC65816::algorithmROL16(uint16 data) -> uint16 { +auto WDC65816::algorithmROL16(n16 data) -> n16 { bool carry = CF; CF = data & 0x8000; data = data << 1 | carry; @@ -270,7 +270,7 @@ auto WDC65816::algorithmROL16(uint16 data) -> uint16 { return data; } -auto WDC65816::algorithmROR8(uint8 data) -> uint8 { +auto WDC65816::algorithmROR8(n8 data) -> n8 { bool carry = CF; CF = data & 1; data = carry << 7 | data >> 1; @@ -279,7 +279,7 @@ auto WDC65816::algorithmROR8(uint8 data) -> uint8 { return data; } -auto WDC65816::algorithmROR16(uint16 data) -> uint16 { +auto WDC65816::algorithmROR16(n16 data) -> n16 { bool carry = CF; CF = data & 1; data = carry << 15 | data >> 1; @@ -288,8 +288,8 @@ auto WDC65816::algorithmROR16(uint16 data) -> uint16 { return data; } -auto WDC65816::algorithmSBC8(uint8 data) -> uint8 { - int result; +auto WDC65816::algorithmSBC8(n8 data) -> n8 { + s32 result; data = ~data; if(!DF) { @@ -304,14 +304,14 @@ auto WDC65816::algorithmSBC8(uint8 data) -> uint8 { VF = ~(A.l ^ data) & (A.l ^ result) & 0x80; if(DF && result <= 0xff) result -= 0x60; CF = result > 0xff; - ZF = (uint8)result == 0; + ZF = (n8)result == 0; NF = result & 0x80; return A.l = result; } -auto WDC65816::algorithmSBC16(uint16 data) -> uint16 { - int result; +auto WDC65816::algorithmSBC16(n16 data) -> n16 { + s32 result; data = ~data; if(!DF) { @@ -332,31 +332,31 @@ auto WDC65816::algorithmSBC16(uint16 data) -> uint16 { VF = ~(A.w ^ data) & (A.w ^ result) & 0x8000; if(DF && result <= 0xffff) result -= 0x6000; CF = result > 0xffff; - ZF = (uint16)result == 0; + ZF = (n16)result == 0; NF = result & 0x8000; return A.w = result; } -auto WDC65816::algorithmTRB8(uint8 data) -> uint8 { +auto WDC65816::algorithmTRB8(n8 data) -> n8 { ZF = (data & A.l) == 0; data &= ~A.l; return data; } -auto WDC65816::algorithmTRB16(uint16 data) -> uint16 { +auto WDC65816::algorithmTRB16(n16 data) -> n16 { ZF = (data & A.w) == 0; data &= ~A.w; return data; } -auto WDC65816::algorithmTSB8(uint8 data) -> uint8 { +auto WDC65816::algorithmTSB8(n8 data) -> n8 { ZF = (data & A.l) == 0; data |= A.l; return data; } -auto WDC65816::algorithmTSB16(uint16 data) -> uint16 { +auto WDC65816::algorithmTSB16(n16 data) -> n16 { ZF = (data & A.w) == 0; data |= A.w; return data; diff --git a/ares/component/processor/wdc65816/disassembler.cpp b/ares/component/processor/wdc65816/disassembler.cpp index 5cce366768..9873d63b30 100644 --- a/ares/component/processor/wdc65816/disassembler.cpp +++ b/ares/component/processor/wdc65816/disassembler.cpp @@ -1,27 +1,27 @@ -auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> string { +auto WDC65816::disassembleInstruction(n24 address, bool e, bool m, bool x) -> string { string s; - uint24 pc = address; + n24 pc = address; string name; string operand; - maybe effective; + maybe effective; - auto read = [&](uint24 address) -> uint8 { + auto read = [&](n24 address) -> n8 { //$00-3f,80-bf:2000-5fff: do not attempt to read I/O registers from the disassembler: //this is because such reads are much more likely to have side effects to emulation. if((address & 0x40ffff) >= 0x2000 && (address & 0x40ffff) <= 0x5fff) return 0x00; return readDisassembler(address); }; - auto readByte = [&](uint24 address) -> uint8 { + auto readByte = [&](n24 address) -> n8 { return read(address); }; - auto readWord = [&](uint24 address) -> uint16 { - uint16 data = readByte(address + 0) << 0; + auto readWord = [&](n24 address) -> n16 { + n16 data = readByte(address + 0) << 0; return data | readByte(address + 1) << 8; }; - auto readLong = [&](uint24 address) -> uint24 { - uint24 data = readByte(address + 0) << 0; + auto readLong = [&](n24 address) -> n24 { + n24 data = readByte(address + 0) << 0; return data | readWord(address + 1) << 8; }; @@ -30,9 +30,9 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> auto operand1 = read(address); address.bit(0,15)++; auto operand2 = read(address); address.bit(0,15)++; - uint8 operandByte = operand0 << 0; - uint16 operandWord = operand0 << 0 | operand1 << 8; - uint24 operandLong = operand0 << 0 | operand1 << 8 | operand2 << 16; + n8 operandByte = operand0 << 0; + n16 operandWord = operand0 << 0 | operand1 << 8; + n24 operandLong = operand0 << 0 | operand1 << 8 | operand2 << 16; auto absolute = [&]() -> string { effective = r.b << 16 | operandWord; @@ -65,17 +65,17 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> }; auto direct = [&]() -> string { - effective = uint16(r.d.w + operandByte); + effective = n16(r.d.w + operandByte); return {"$", hex(operandByte, 2L)}; }; auto directX = [&]() -> string { - effective = uint16(r.d.w + operandByte + r.x.w); + effective = n16(r.d.w + operandByte + r.x.w); return {"$", hex(operandByte, 2L), ",x"}; }; auto directY = [&]() -> string { - effective = uint16(r.d.w + operandByte + r.y.w); + effective = n16(r.d.w + operandByte + r.y.w); return {"$", hex(operandByte, 2L), ",y"}; }; @@ -96,13 +96,13 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> }; auto indexedIndirectX = [&]() -> string { - effective = uint16(r.d.w + operandByte + r.x.w); + effective = n16(r.d.w + operandByte + r.x.w); effective = r.b << 16 | readWord(*effective); return {"($", hex(operandByte, 2L), ",x)"}; }; auto indirect = [&]() -> string { - effective = uint16(r.d.w + operandByte); + effective = n16(r.d.w + operandByte); effective = (r.b << 16) + readWord(*effective); return {"($", hex(operandByte, 2L), ")"}; }; @@ -115,19 +115,19 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> auto indirectX = [&]() -> string { effective = operandWord; - effective = pc.mask(16,23) | uint16(*effective + r.x.w); + effective = pc.mask(16,23) | n16(*effective + r.x.w); effective = pc.mask(16,23) | readWord(*effective); return {"($", hex(operandWord, 4L), ",x)"}; }; auto indirectIndexedY = [&]() -> string { - effective = uint16(r.d.w + operandByte); + effective = n16(r.d.w + operandByte); effective = (r.b << 16) + readWord(*effective) + r.y.w; return {"($", hex(operandByte, 2L), "),y"}; }; auto indirectLong = [&]() -> string { - effective = uint16(r.d.w + operandByte); + effective = n16(r.d.w + operandByte); effective = readLong(*effective); return {"[$", hex(operandByte, 2L), "]"}; }; @@ -138,7 +138,7 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> }; auto indirectLongY = [&]() -> string { - effective = uint16(r.d.w + operandByte); + effective = n16(r.d.w + operandByte); effective = readLong(*effective) + r.y.w; return {"[$", hex(operandByte, 2L), "],y"}; }; @@ -148,22 +148,22 @@ auto WDC65816::disassembleInstruction(uint24 address, bool e, bool m, bool x) -> }; auto relative = [&]() -> string { - effective = pc.mask(16,23) | uint16(pc + 2 + (int8)operandByte); + effective = pc.mask(16,23) | n16(pc + 2 + (i8)operandByte); return {"$", hex(*effective, 4L)}; }; auto relativeWord = [&]() -> string { - effective = pc.mask(16,23) | uint16(pc + 3 + (int16)operandWord); + effective = pc.mask(16,23) | n16(pc + 3 + (i16)operandWord); return {"$", hex(*effective, 4L)}; }; auto stack = [&]() -> string { - effective = uint16(r.s.w + operandByte); + effective = n16(r.s.w + operandByte); return {"$", hex(operandByte, 2L), ",s"}; }; auto stackIndirect = [&]() -> string { - effective = uint16(operandByte + r.s.w); + effective = n16(operandByte + r.s.w); effective = (r.b << 16) + readWord(*effective) + r.y.w; return {"($", hex(operandByte, 2L), ",s),y"}; }; diff --git a/ares/component/processor/wdc65816/instructions-other.cpp b/ares/component/processor/wdc65816/instructions-other.cpp index c7290eaa63..4288778ca9 100644 --- a/ares/component/processor/wdc65816/instructions-other.cpp +++ b/ares/component/processor/wdc65816/instructions-other.cpp @@ -25,7 +25,7 @@ L idle(); NF = A.l & 0x80; } -auto WDC65816::instructionBlockMove8(int adjust) -> void { +auto WDC65816::instructionBlockMove8(s32 adjust) -> void { U.b = fetch(); V.b = fetch(); B = U.b; @@ -38,7 +38,7 @@ L idle(); if(A.w--) PC.w -= 3; } -auto WDC65816::instructionBlockMove16(int adjust) -> void { +auto WDC65816::instructionBlockMove16(s32 adjust) -> void { U.b = fetch(); V.b = fetch(); B = U.b; @@ -240,7 +240,7 @@ auto WDC65816::instructionPushEffectiveRelativeAddress() -> void { V.l = fetch(); V.h = fetch(); idle(); - W.w = PC.d + (int16)V.w; + W.w = PC.d + (i16)V.w; pushN(W.h); L pushN(W.l); E S.h = 0x01; diff --git a/ares/component/processor/wdc65816/instructions-pc.cpp b/ares/component/processor/wdc65816/instructions-pc.cpp index beb6f7c1d3..3afb6a9490 100644 --- a/ares/component/processor/wdc65816/instructions-pc.cpp +++ b/ares/component/processor/wdc65816/instructions-pc.cpp @@ -3,7 +3,7 @@ auto WDC65816::instructionBranch(bool take) -> void { L fetch(); } else { U.l = fetch(); - V.w = PC.d + (int8)U.l; + V.w = PC.d + (i8)U.l; idle6(V.w); L idle(); PC.w = V.w; @@ -14,7 +14,7 @@ L idle(); auto WDC65816::instructionBranchLong() -> void { U.l = fetch(); U.h = fetch(); - V.w = PC.d + (int16)U.w; + V.w = PC.d + (i16)U.w; L idle(); PC.w = V.w; idleBranch(); @@ -38,8 +38,8 @@ L V.b = fetch(); auto WDC65816::instructionJumpIndirect() -> void { V.l = fetch(); V.h = fetch(); - W.l = read(uint16(V.w + 0)); -L W.h = read(uint16(V.w + 1)); + W.l = read(n16(V.w + 0)); +L W.h = read(n16(V.w + 1)); PC.w = W.w; idleJump(); } @@ -48,8 +48,8 @@ auto WDC65816::instructionJumpIndexedIndirect() -> void { V.l = fetch(); V.h = fetch(); idle(); - W.l = read(PC.b << 16 | uint16(V.w + X.w + 0)); -L W.h = read(PC.b << 16 | uint16(V.w + X.w + 1)); + W.l = read(PC.b << 16 | n16(V.w + X.w + 0)); +L W.h = read(PC.b << 16 | n16(V.w + X.w + 1)); PC.w = W.w; idleJump(); } @@ -57,9 +57,9 @@ L W.h = read(PC.b << 16 | uint16(V.w + X.w + 1)); auto WDC65816::instructionJumpIndirectLong() -> void { U.l = fetch(); U.h = fetch(); - V.l = read(uint16(U.w + 0)); - V.h = read(uint16(U.w + 1)); -L V.b = read(uint16(U.w + 2)); + V.l = read(n16(U.w + 0)); + V.h = read(n16(U.w + 1)); +L V.b = read(n16(U.w + 2)); PC.d = V.d; idleJump(); } @@ -95,8 +95,8 @@ auto WDC65816::instructionCallIndexedIndirect() -> void { pushN(PC.l); V.h = fetch(); idle(); - W.l = read(PC.b << 16 | uint16(V.w + X.w + 0)); -L W.h = read(PC.b << 16 | uint16(V.w + X.w + 1)); + W.l = read(PC.b << 16 | n16(V.w + X.w + 0)); +L W.h = read(PC.b << 16 | n16(V.w + X.w + 1)); PC.w = W.w; E S.h = 0x01; idleJump(); diff --git a/ares/component/processor/wdc65816/memory.cpp b/ares/component/processor/wdc65816/memory.cpp index e7935a8f89..6871c4b218 100644 --- a/ares/component/processor/wdc65816/memory.cpp +++ b/ares/component/processor/wdc65816/memory.cpp @@ -19,62 +19,62 @@ inline auto WDC65816::idle2() -> void { if(D.l) idle(); } -inline auto WDC65816::idle4(uint16 x, uint16 y) -> void { +inline auto WDC65816::idle4(n16 x, n16 y) -> void { if(!XF || x >> 8 != y >> 8) idle(); } -inline auto WDC65816::idle6(uint16 address) -> void { +inline auto WDC65816::idle6(n16 address) -> void { if(EF && PC.h != address >> 8) idle(); } -inline auto WDC65816::fetch() -> uint8 { +inline auto WDC65816::fetch() -> n8 { return read(PC.b << 16 | PC.w++); } -inline auto WDC65816::pull() -> uint8 { +inline auto WDC65816::pull() -> n8 { EF ? (void)S.l++ : (void)S.w++; return read(S.w); } -auto WDC65816::push(uint8 data) -> void { +auto WDC65816::push(n8 data) -> void { write(S.w, data); EF ? (void)S.l-- : (void)S.w--; } -inline auto WDC65816::pullN() -> uint8 { +inline auto WDC65816::pullN() -> n8 { return read(++S.w); } -inline auto WDC65816::pushN(uint8 data) -> void { +inline auto WDC65816::pushN(n8 data) -> void { write(S.w--, data); } -inline auto WDC65816::readDirect(uint address) -> uint8 { - if(EF && !D.l) return read(D.w | uint8(address)); - return read(uint16(D.w + address)); +inline auto WDC65816::readDirect(u32 address) -> n8 { + if(EF && !D.l) return read(D.w | n8(address)); + return read(n16(D.w + address)); } -inline auto WDC65816::writeDirect(uint address, uint8 data) -> void { - if(EF && !D.l) return write(D.w | uint8(address), data); - write(uint16(D.w + address), data); +inline auto WDC65816::writeDirect(u32 address, n8 data) -> void { + if(EF && !D.l) return write(D.w | n8(address), data); + write(n16(D.w + address), data); } -inline auto WDC65816::readDirectN(uint address) -> uint8 { - return read(uint16(D.w + address)); +inline auto WDC65816::readDirectN(u32 address) -> n8 { + return read(n16(D.w + address)); } -inline auto WDC65816::readBank(uint address) -> uint8 { +inline auto WDC65816::readBank(u32 address) -> n8 { return read((B << 16) + address); } -inline auto WDC65816::writeBank(uint address, uint8 data) -> void { +inline auto WDC65816::writeBank(u32 address, n8 data) -> void { write((B << 16) + address, data); } -inline auto WDC65816::readStack(uint address) -> uint8 { - return read(uint16(S.w + address)); +inline auto WDC65816::readStack(u32 address) -> n8 { + return read(n16(S.w + address)); } -inline auto WDC65816::writeStack(uint address, uint8 data) -> void { - write(uint16(S.w + address), data); +inline auto WDC65816::writeStack(u32 address, n8 data) -> void { + write(n16(S.w + address), data); } diff --git a/ares/component/processor/wdc65816/wdc65816.hpp b/ares/component/processor/wdc65816/wdc65816.hpp index 470673a082..bc70d8d7a3 100644 --- a/ares/component/processor/wdc65816/wdc65816.hpp +++ b/ares/component/processor/wdc65816/wdc65816.hpp @@ -10,40 +10,40 @@ struct WDC65816 { virtual auto idle() -> void = 0; virtual auto idleBranch() -> void {} virtual auto idleJump() -> void {} - virtual auto read(uint24 addr) -> uint8 = 0; - virtual auto write(uint24 addr, uint8 data) -> void = 0; + virtual auto read(n24 address) -> n8 = 0; + virtual auto write(n24 address, n8 data) -> void = 0; virtual auto lastCycle() -> void = 0; virtual auto interruptPending() const -> bool = 0; virtual auto interrupt() -> void; virtual auto synchronizing() const -> bool = 0; - virtual auto readDisassembler(uint24 addr) -> uint8 { return 0; } + virtual auto readDisassembler(n24 address) -> n8 { return 0; } auto irq() const -> bool { return r.irq; } auto irq(bool line) -> void { r.irq = line; } - using r8 = uint8; + using r8 = n8; struct r16 { r16() {} - r16(uint data) : w(data) {} + r16(n32 data) : w(data) {} r16(const r16& data) : w(data.w) {} - auto& operator=(uint data) { w = data; return *this; } + auto& operator=(u32 data) { w = data; return *this; } auto& operator=(const r16& data) { w = data.w; return *this; } - uint16 w; + n16 w; BitRange<16,0, 7> l{&w}; BitRange<16,8,15> h{&w}; }; struct r24 { r24() {} - r24(uint data) : d(data) {} + r24(u32 data) : d(data) {} r24(const r24& data) : d(data.d) {} - auto& operator=(uint data) { d = data; return *this; } + auto& operator=(u32 data) { d = data; return *this; } auto& operator=(const r24& data) { d = data.d; return *this; } - uint24 d; + n24 d; BitRange<24, 0, 7> l{&d}; BitRange<24, 8,15> h{&d}; BitRange<24,16,23> b{&d}; @@ -56,65 +56,65 @@ struct WDC65816 { //memory.cpp auto idleIRQ() -> void; auto idle2() -> void; - auto idle4(uint16 x, uint16 y) -> void; - auto idle6(uint16 address) -> void; - auto fetch() -> uint8; - auto pull() -> uint8; - auto push(uint8 data) -> void; - auto pullN() -> uint8; - auto pushN(uint8 data) -> void; - auto readDirect(uint address) -> uint8; - auto writeDirect(uint address, uint8 data) -> void; - auto readDirectN(uint address) -> uint8; - auto readBank(uint address) -> uint8; - auto writeBank(uint address, uint8 data) -> void; - auto readStack(uint address) -> uint8; - auto writeStack(uint address, uint8 data) -> void; + auto idle4(n16 x, n16 y) -> void; + auto idle6(n16 address) -> void; + auto fetch() -> n8; + auto pull() -> n8; + auto push(n8 data) -> void; + auto pullN() -> n8; + auto pushN(n8 data) -> void; + auto readDirect(u32 address) -> n8; + auto writeDirect(u32 address, n8 data) -> void; + auto readDirectN(u32 address) -> n8; + auto readBank(u32 address) -> n8; + auto writeBank(u32 address, n8 data) -> void; + auto readStack(u32 address) -> n8; + auto writeStack(u32 address, n8 data) -> void; //algorithms.cpp - using alu8 = auto (WDC65816::*)( uint8) -> uint8; - using alu16 = auto (WDC65816::*)(uint16) -> uint16; + using alu8 = auto (WDC65816::*)(n8 ) -> n8; + using alu16 = auto (WDC65816::*)(n16) -> n16; - auto algorithmADC8(uint8) -> uint8; - auto algorithmADC16(uint16) -> uint16; - auto algorithmAND8(uint8) -> uint8; - auto algorithmAND16(uint16) -> uint16; - auto algorithmASL8(uint8) -> uint8; - auto algorithmASL16(uint16) -> uint16; - auto algorithmBIT8(uint8) -> uint8; - auto algorithmBIT16(uint16) -> uint16; - auto algorithmCMP8(uint8) -> uint8; - auto algorithmCMP16(uint16) -> uint16; - auto algorithmCPX8(uint8) -> uint8; - auto algorithmCPX16(uint16) -> uint16; - auto algorithmCPY8(uint8) -> uint8; - auto algorithmCPY16(uint16) -> uint16; - auto algorithmDEC8(uint8) -> uint8; - auto algorithmDEC16(uint16) -> uint16; - auto algorithmEOR8(uint8) -> uint8; - auto algorithmEOR16(uint16) -> uint16; - auto algorithmINC8(uint8) -> uint8; - auto algorithmINC16(uint16) -> uint16; - auto algorithmLDA8(uint8) -> uint8; - auto algorithmLDA16(uint16) -> uint16; - auto algorithmLDX8(uint8) -> uint8; - auto algorithmLDX16(uint16) -> uint16; - auto algorithmLDY8(uint8) -> uint8; - auto algorithmLDY16(uint16) -> uint16; - auto algorithmLSR8(uint8) -> uint8; - auto algorithmLSR16(uint16) -> uint16; - auto algorithmORA8(uint8) -> uint8; - auto algorithmORA16(uint16) -> uint16; - auto algorithmROL8(uint8) -> uint8; - auto algorithmROL16(uint16) -> uint16; - auto algorithmROR8(uint8) -> uint8; - auto algorithmROR16(uint16) -> uint16; - auto algorithmSBC8(uint8) -> uint8; - auto algorithmSBC16(uint16) -> uint16; - auto algorithmTRB8(uint8) -> uint8; - auto algorithmTRB16(uint16) -> uint16; - auto algorithmTSB8(uint8) -> uint8; - auto algorithmTSB16(uint16) -> uint16; + auto algorithmADC8(n8) -> n8; + auto algorithmADC16(n16) -> n16; + auto algorithmAND8(n8) -> n8; + auto algorithmAND16(n16) -> n16; + auto algorithmASL8(n8) -> n8; + auto algorithmASL16(n16) -> n16; + auto algorithmBIT8(n8) -> n8; + auto algorithmBIT16(n16) -> n16; + auto algorithmCMP8(n8) -> n8; + auto algorithmCMP16(n16) -> n16; + auto algorithmCPX8(n8) -> n8; + auto algorithmCPX16(n16) -> n16; + auto algorithmCPY8(n8) -> n8; + auto algorithmCPY16(n16) -> n16; + auto algorithmDEC8(n8) -> n8; + auto algorithmDEC16(n16) -> n16; + auto algorithmEOR8(n8) -> n8; + auto algorithmEOR16(n16) -> n16; + auto algorithmINC8(n8) -> n8; + auto algorithmINC16(n16) -> n16; + auto algorithmLDA8(n8) -> n8; + auto algorithmLDA16(n16) -> n16; + auto algorithmLDX8(n8) -> n8; + auto algorithmLDX16(n16) -> n16; + auto algorithmLDY8(n8) -> n8; + auto algorithmLDY16(n16) -> n16; + auto algorithmLSR8(n8) -> n8; + auto algorithmLSR16(n16) -> n16; + auto algorithmORA8(n8) -> n8; + auto algorithmORA16(n16) -> n16; + auto algorithmROL8(n8) -> n8; + auto algorithmROL16(n16) -> n16; + auto algorithmROR8(n8) -> n8; + auto algorithmROR16(n16) -> n16; + auto algorithmSBC8(n8) -> n8; + auto algorithmSBC16(n16) -> n16; + auto algorithmTRB8(n8) -> n8; + auto algorithmTRB16(n16) -> n16; + auto algorithmTSB8(n8) -> n8; + auto algorithmTSB16(n16) -> n16; //instructions-read.cpp auto instructionImmediateRead8(alu8) -> void; @@ -199,8 +199,8 @@ struct WDC65816 { auto instructionNoOperation() -> void; auto instructionPrefix() -> void; auto instructionExchangeBA() -> void; - auto instructionBlockMove8(int) -> void; - auto instructionBlockMove16(int) -> void; + auto instructionBlockMove8(s32) -> void; + auto instructionBlockMove16(s32) -> void; auto instructionInterrupt(r16) -> void; auto instructionStop() -> void; auto instructionWait() -> void; @@ -234,7 +234,7 @@ struct WDC65816 { auto serialize(serializer&) -> void; //disassembler.cpp - noinline auto disassembleInstruction(uint24 address, bool e, bool m, bool x) -> string; + noinline auto disassembleInstruction(n24 address, bool e, bool m, bool x) -> string; noinline auto disassembleInstruction() -> string; noinline auto disassembleContext(maybe e = {}) -> string; @@ -248,11 +248,11 @@ struct WDC65816 { bool v = 0; //overflow bool n = 0; //negative - operator uint() const { + operator u32() const { return c << 0 | z << 1 | i << 2 | d << 3 | x << 4 | m << 5 | v << 6 | n << 7; } - auto& operator=(uint8 data) { + auto& operator=(n8 data) { c = data.bit(0); z = data.bit(1); i = data.bit(2); @@ -281,9 +281,9 @@ struct WDC65816 { bool wai = 0; //raised during wai, cleared after interrupt triggered bool stp = 0; //raised during stp, never cleared - uint16 vector; //interrupt vector address - uint24 mar; //memory address register - uint8 mdr; //memory data register + n16 vector; //interrupt vector address + n24 mar; //memory address register + n8 mdr; //memory data register r24 u; //temporary register r24 v; //temporary register diff --git a/ares/component/processor/z80/algorithms.cpp b/ares/component/processor/z80/algorithms.cpp index 9b388777a9..9f44b91402 100644 --- a/ares/component/processor/z80/algorithms.cpp +++ b/ares/component/processor/z80/algorithms.cpp @@ -1,20 +1,20 @@ -auto Z80::ADD(uint8 x, uint8 y, bool c) -> uint8 { - uint9 z = x + y + c; +auto Z80::ADD(n8 x, n8 y, bool c) -> n8 { + n9 z = x + y + c; CF = z.bit(8); NF = 0; - VF = uint8(~(x ^ y) & (x ^ z)).bit(7); + VF = n8(~(x ^ y) & (x ^ z)).bit(7); XF = z.bit(3); - HF = uint8(x ^ y ^ z).bit(4); + HF = n8(x ^ y ^ z).bit(4); YF = z.bit(5); - ZF = uint8(z) == 0; + ZF = n8(z) == 0; SF = z.bit(7); return z; } -auto Z80::AND(uint8 x, uint8 y) -> uint8 { - uint8 z = x & y; +auto Z80::AND(n8 x, n8 y) -> n8 { + n8 z = x & y; CF = 0; NF = 0; @@ -28,8 +28,8 @@ auto Z80::AND(uint8 x, uint8 y) -> uint8 { return z; } -auto Z80::BIT(uint3 bit, uint8 x) -> uint8 { - uint8 z = x & 1 << bit; +auto Z80::BIT(n3 bit, n8 x) -> n8 { + n8 z = x & 1 << bit; NF = 0; PF = parity(z); @@ -42,21 +42,21 @@ auto Z80::BIT(uint3 bit, uint8 x) -> uint8 { return x; } -auto Z80::CP(uint8 x, uint8 y) -> void { - uint9 z = x - y; +auto Z80::CP(n8 x, n8 y) -> void { + n9 z = x - y; CF = z.bit(8); NF = 1; - VF = uint8((x ^ y) & (x ^ z)).bit(7); + VF = n8((x ^ y) & (x ^ z)).bit(7); XF = y.bit(3); - HF = uint8(x ^ y ^ z).bit(4); + HF = n8(x ^ y ^ z).bit(4); YF = y.bit(5); - ZF = uint8(z) == 0; + ZF = n8(z) == 0; SF = z.bit(7); } -auto Z80::DEC(uint8 x) -> uint8 { - uint8 z = x - 1; +auto Z80::DEC(n8 x) -> n8 { + n8 z = x - 1; NF = 1; VF = z == 0x7f; @@ -69,7 +69,7 @@ auto Z80::DEC(uint8 x) -> uint8 { return z; } -auto Z80::IN(uint8 x) -> uint8 { +auto Z80::IN(n8 x) -> n8 { NF = 0; PF = parity(x); XF = x.bit(3); @@ -81,8 +81,8 @@ auto Z80::IN(uint8 x) -> uint8 { return x; } -auto Z80::INC(uint8 x) -> uint8 { - uint8 z = x + 1; +auto Z80::INC(n8 x) -> n8 { + n8 z = x + 1; NF = 0; VF = z == 0x80; @@ -95,8 +95,8 @@ auto Z80::INC(uint8 x) -> uint8 { return z; } -auto Z80::OR(uint8 x, uint8 y) -> uint8 { - uint8 z = x | y; +auto Z80::OR(n8 x, n8 y) -> n8 { + n8 z = x | y; CF = 0; NF = 0; @@ -110,12 +110,12 @@ auto Z80::OR(uint8 x, uint8 y) -> uint8 { return z; } -auto Z80::RES(uint3 bit, uint8 x) -> uint8 { +auto Z80::RES(n3 bit, n8 x) -> n8 { x &= ~(1 << bit); return x; } -auto Z80::RL(uint8 x) -> uint8 { +auto Z80::RL(n8 x) -> n8 { bool c = x.bit(7); x = x << 1 | CF; @@ -131,7 +131,7 @@ auto Z80::RL(uint8 x) -> uint8 { return x; } -auto Z80::RLC(uint8 x) -> uint8 { +auto Z80::RLC(n8 x) -> n8 { x = x << 1 | x >> 7; CF = x.bit(0); @@ -146,7 +146,7 @@ auto Z80::RLC(uint8 x) -> uint8 { return x; } -auto Z80::RR(uint8 x) -> uint8 { +auto Z80::RR(n8 x) -> n8 { bool c = x.bit(0); x = x >> 1 | CF << 7; @@ -162,7 +162,7 @@ auto Z80::RR(uint8 x) -> uint8 { return x; } -auto Z80::RRC(uint8 x) -> uint8 { +auto Z80::RRC(n8 x) -> n8 { x = x >> 1 | x << 7; CF = x.bit(7); @@ -177,12 +177,12 @@ auto Z80::RRC(uint8 x) -> uint8 { return x; } -auto Z80::SET(uint3 bit, uint8 x) -> uint8 { +auto Z80::SET(n3 bit, n8 x) -> n8 { x |= (1 << bit); return x; } -auto Z80::SLA(uint8 x) -> uint8 { +auto Z80::SLA(n8 x) -> n8 { bool c = x.bit(7); x = x << 1; @@ -198,7 +198,7 @@ auto Z80::SLA(uint8 x) -> uint8 { return x; } -auto Z80::SLL(uint8 x) -> uint8 { +auto Z80::SLL(n8 x) -> n8 { bool c = x.bit(7); x = x << 1 | 1; @@ -214,9 +214,9 @@ auto Z80::SLL(uint8 x) -> uint8 { return x; } -auto Z80::SRA(uint8 x) -> uint8 { +auto Z80::SRA(n8 x) -> n8 { bool c = x.bit(0); - x = (int8)x >> 1; + x = (i8)x >> 1; CF = c; NF = 0; @@ -230,7 +230,7 @@ auto Z80::SRA(uint8 x) -> uint8 { return x; } -auto Z80::SRL(uint8 x) -> uint8 { +auto Z80::SRL(n8 x) -> n8 { bool c = x.bit(0); x = x >> 1; @@ -246,23 +246,23 @@ auto Z80::SRL(uint8 x) -> uint8 { return x; } -auto Z80::SUB(uint8 x, uint8 y, bool c) -> uint8 { - uint9 z = x - y - c; +auto Z80::SUB(n8 x, n8 y, bool c) -> n8 { + n9 z = x - y - c; CF = z.bit(8); NF = 1; - VF = uint8((x ^ y) & (x ^ z)).bit(7); + VF = n8((x ^ y) & (x ^ z)).bit(7); XF = z.bit(3); - HF = uint8(x ^ y ^ z).bit(4); + HF = n8(x ^ y ^ z).bit(4); YF = z.bit(5); - ZF = uint8(z) == 0; + ZF = n8(z) == 0; SF = z.bit(7); return z; } -auto Z80::XOR(uint8 x, uint8 y) -> uint8 { - uint8 z = x ^ y; +auto Z80::XOR(n8 x, n8 y) -> n8 { + n8 z = x ^ y; CF = 0; NF = 0; diff --git a/ares/component/processor/z80/disassembler.cpp b/ares/component/processor/z80/disassembler.cpp index 92492e5d57..a9acfd6339 100644 --- a/ares/component/processor/z80/disassembler.cpp +++ b/ares/component/processor/z80/disassembler.cpp @@ -1,8 +1,8 @@ -auto Z80::disassembleInstruction(maybe _pc) -> string { +auto Z80::disassembleInstruction(maybe _pc) -> string { auto pc = _pc ? *_pc : r.pc; string s, output; - uint8 prefix = 0x00; + n8 prefix = 0x00; auto code = bus->read(pc++); if(code == 0xdd || code == 0xfd) { prefix = code; @@ -21,7 +21,7 @@ auto Z80::disassembleInstruction(maybe _pc) -> string { } if(code == 0xcb && prefix) { - auto d = (int8)bus->read(pc++); + auto d = (i8)bus->read(pc++); code = bus->read(pc++); output = disassembleCBd(pc, prefix, d, code); } else if(code == 0xcb) { @@ -48,7 +48,7 @@ auto Z80::disassembleContext() -> string { s.append(" IX:", hex(r.ix.word, 4L)); s.append(" IY:", hex(r.iy.word, 4L)); s.append(" SP:", hex(r.sp, 4L)); - s.append(" IFF:", (uint1)r.iff1, (uint1)r.iff2); + s.append(" IFF:", (n1)r.iff1, (n1)r.iff2); s.append(" IM:", r.im); return s; @@ -96,24 +96,24 @@ auto Z80::disassembleContext() -> string { #define IHL string{"(", HL, displace(), ")"} #define ISP "(sp)" -auto Z80::disassemble(uint16 pc, uint8 prefix, uint8 code) -> string { +auto Z80::disassemble(n16 pc, n8 prefix, n8 code) -> string { auto byte = [&] { return bus->read(pc++); }; auto word = [&] { - uint16 data = byte() << 0; + n16 data = byte() << 0; return data | byte() << 8; }; auto branch = [&] { auto d = byte(); - return pc + (int8)d; + return pc + (i8)d; }; auto displace = [&] { if(!prefix) return string{}; - auto d = (int8)byte(); + auto d = (i8)byte(); return d >= 0 ? string{"+$", hex(d, 2L)} : string{"-$", hex(-d, 2L)}; }; @@ -379,29 +379,29 @@ auto Z80::disassemble(uint16 pc, uint8 prefix, uint8 code) -> string { unreachable; } -auto Z80::disassembleCB(uint16 pc, uint8 prefix, uint8 code) -> string { +auto Z80::disassembleCB(n16 pc, n8 prefix, n8 code) -> string { auto byte = [&] { return bus->read(pc++); }; auto word = [&] { - uint16 data = byte() << 0; + n16 data = byte() << 0; return data | byte() << 8; }; auto branch = [&] { auto d = byte(); - return pc + (int8)d; + return pc + (i8)d; }; auto displace = [&] { if(!prefix) return string{}; - auto d = (int8)byte(); + auto d = (i8)byte(); return d >= 0 ? string{"+$", hex(d, 2L)} : string{"-$", hex(-d, 2L)}; }; if(prefix) { - auto d = (int8)code; + auto d = (i8)code; string ds = d >= 0 ? string{"+$", hex(d, 2L)} : string{"-$", hex(-d, 2L)}; return {"rlc (", HL, ds, ")"}; } @@ -668,7 +668,7 @@ auto Z80::disassembleCB(uint16 pc, uint8 prefix, uint8 code) -> string { unreachable; } -auto Z80::disassembleCBd(uint16 pc, uint8 prefix, int8 d, uint8 code) -> string { +auto Z80::disassembleCBd(n16 pc, n8 prefix, i8 d, n8 code) -> string { auto displace = [&] { return d >= 0 ? string{"+$", hex(d, 2L)} : string{"-$", hex(-d, 2L)}; }; @@ -935,24 +935,24 @@ auto Z80::disassembleCBd(uint16 pc, uint8 prefix, int8 d, uint8 code) -> string unreachable; } -auto Z80::disassembleED(uint16 pc, uint8 prefix, uint8 code) -> string { +auto Z80::disassembleED(n16 pc, n8 prefix, n8 code) -> string { auto byte = [&] { return bus->read(pc++); }; auto word = [&] { - uint16 data = byte() << 0; + n16 data = byte() << 0; return data | byte() << 8; }; auto branch = [&] { auto d = byte(); - return pc + (int8)d; + return pc + (i8)d; }; auto displace = [&] { if(!prefix) return string{}; - auto d = (int8)byte(); + auto d = (i8)byte(); return d >= 0 ? string{"+$", hex(d, 2L)} : string{"-$", hex(-d, 2L)}; }; diff --git a/ares/component/processor/z80/instruction.cpp b/ares/component/processor/z80/instruction.cpp index 4d63dcfcc3..77f1b20325 100644 --- a/ares/component/processor/z80/instruction.cpp +++ b/ares/component/processor/z80/instruction.cpp @@ -11,7 +11,7 @@ auto Z80::instruction() -> void { return wait(1); } - uint8 code; + n8 code; while(true) { R.bit(0,6)++; code = opcode(); @@ -21,7 +21,7 @@ auto Z80::instruction() -> void { } if(code == 0xcb && prefix != Prefix::hl) { - WZ = HL + (int8)operand(); + WZ = HL + (i8)operand(); wait(1); //R is not incremented here instructionCBd(WZ, opcode()); @@ -40,7 +40,7 @@ auto Z80::instruction() -> void { #define op(id, name, ...) case id: return instruction##name(__VA_ARGS__); -auto Z80::instruction(uint8 code) -> void { +auto Z80::instruction(n8 code) -> void { switch(code) { op(0x00, NOP) op(0x01, LD_rr_nn, BC) @@ -301,7 +301,7 @@ auto Z80::instruction(uint8 code) -> void { } } -auto Z80::instructionCB(uint8 code) -> void { +auto Z80::instructionCB(n8 code) -> void { switch(code) { op(0x00, RLC_r, B) op(0x01, RLC_r, C) @@ -562,8 +562,8 @@ auto Z80::instructionCB(uint8 code) -> void { } } -auto Z80::instructionCBd(uint16 addr, uint8 code) -> void { - uint8 _; +auto Z80::instructionCBd(n16 addr, n8 code) -> void { + n8 _; switch(code) { op(0x00, RLC_irr_r, addr, B) @@ -825,7 +825,7 @@ auto Z80::instructionCBd(uint16 addr, uint8 code) -> void { } } -auto Z80::instructionED(uint8 code) -> void { +auto Z80::instructionED(n8 code) -> void { switch(code) { op(0x40, IN_r_ic, B) op(0x41, OUT_ic_r, B) diff --git a/ares/component/processor/z80/instructions.cpp b/ares/component/processor/z80/instructions.cpp index fbf92a5d9e..2012821ca7 100644 --- a/ares/component/processor/z80/instructions.cpp +++ b/ares/component/processor/z80/instructions.cpp @@ -10,7 +10,7 @@ // nn = operand-word // r = register -auto Z80::instructionADC_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionADC_a_irr(n16& x) -> void { Q = 1; A = ADD(A, read(displace(x)), CF); } @@ -18,11 +18,11 @@ auto Z80::instructionADC_a_n() -> void { Q = 1; A = ADD(A, operand(), CF); } -auto Z80::instructionADC_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionADC_a_r(n8& x) -> void { Q = 1; A = ADD(A, x, CF); } -auto Z80::instructionADC_hl_rr(uint16& x) -> void { Q = 1; +auto Z80::instructionADC_hl_rr(n16& x) -> void { Q = 1; WZ = HL + 1; wait(4); auto lo = ADD(HL >> 0, x >> 0, CF); @@ -32,7 +32,7 @@ auto Z80::instructionADC_hl_rr(uint16& x) -> void { Q = 1; ZF = HL == 0; } -auto Z80::instructionADD_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionADD_a_irr(n16& x) -> void { Q = 1; A = ADD(A, read(displace(x))); } @@ -40,11 +40,11 @@ auto Z80::instructionADD_a_n() -> void { Q = 1; A = ADD(A, operand()); } -auto Z80::instructionADD_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionADD_a_r(n8& x) -> void { Q = 1; A = ADD(A, x); } -auto Z80::instructionADD_hl_rr(uint16& x) -> void { Q = 1; +auto Z80::instructionADD_hl_rr(n16& x) -> void { Q = 1; WZ = HL + 1; bool vf = VF, zf = ZF, sf = SF; wait(4); @@ -55,7 +55,7 @@ auto Z80::instructionADD_hl_rr(uint16& x) -> void { Q = 1; VF = vf, ZF = zf, SF = sf; //restore unaffected flags } -auto Z80::instructionAND_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionAND_a_irr(n16& x) -> void { Q = 1; A = AND(A, read(displace(x))); } @@ -63,23 +63,23 @@ auto Z80::instructionAND_a_n() -> void { Q = 1; A = AND(A, operand()); } -auto Z80::instructionAND_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionAND_a_r(n8& x) -> void { Q = 1; A = AND(A, x); } -auto Z80::instructionBIT_o_irr(uint3 bit, uint16& addr) -> void { Q = 1; +auto Z80::instructionBIT_o_irr(n3 bit, n16& addr) -> void { Q = 1; BIT(bit, read(addr)); XF = WZH.bit(3); YF = WZH.bit(5); } -auto Z80::instructionBIT_o_irr_r(uint3 bit, uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionBIT_o_irr_r(n3 bit, n16& addr, n8& x) -> void { Q = 1; x = BIT(bit, read(addr)); XF = WZH.bit(3); YF = WZH.bit(5); } -auto Z80::instructionBIT_o_r(uint3 bit, uint8& x) -> void { Q = 1; +auto Z80::instructionBIT_o_r(n3 bit, n8& x) -> void { Q = 1; BIT(bit, x); } @@ -108,7 +108,7 @@ auto Z80::instructionCCF() -> void { Q = 1; } -auto Z80::instructionCP_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionCP_a_irr(n16& x) -> void { Q = 1; CP(A, read(displace(x))); } @@ -116,20 +116,20 @@ auto Z80::instructionCP_a_n() -> void { Q = 1; CP(A, operand()); } -auto Z80::instructionCP_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionCP_a_r(n8& x) -> void { Q = 1; CP(A, x); } auto Z80::instructionCPD() -> void { Q = 1; WZ--; - uint8 data = read(_HL--); + n8 data = read(_HL--); wait(5); - uint8 n = A - data; + n8 n = A - data; NF = 1; VF = --BC != 0; - HF = uint8(A ^ data ^ n).bit(4); - XF = uint8(n - HF).bit(3); - YF = uint8(n - HF).bit(1); + HF = n8(A ^ data ^ n).bit(4); + XF = n8(n - HF).bit(3); + YF = n8(n - HF).bit(1); ZF = n == 0; SF = n.bit(7); } @@ -144,14 +144,14 @@ auto Z80::instructionCPDR() -> void { Q = 1; auto Z80::instructionCPI() -> void { Q = 1; WZ++; - uint8 data = read(_HL++); + n8 data = read(_HL++); wait(5); - uint8 n = A - data; + n8 n = A - data; NF = 1; VF = --BC != 0; - HF = uint8(A ^ data ^ n).bit(4); - XF = uint8(n - HF).bit(3); - YF = uint8(n - HF).bit(1); + HF = n8(A ^ data ^ n).bit(4); + XF = n8(n - HF).bit(3); + YF = n8(n - HF).bit(1); ZF = n == 0; SF = n.bit(7); } @@ -180,24 +180,24 @@ auto Z80::instructionDAA() -> void { Q = 1; PF = parity(A); XF = A.bit(3); - HF = uint8(A ^ a).bit(4); + HF = n8(A ^ a).bit(4); YF = A.bit(5); ZF = A == 0; SF = A.bit(7); } -auto Z80::instructionDEC_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionDEC_irr(n16& x) -> void { Q = 1; auto addr = displace(x); auto data = read(addr); wait(1); write(addr, DEC(data)); } -auto Z80::instructionDEC_r(uint8& x) -> void { Q = 1; +auto Z80::instructionDEC_r(n8& x) -> void { Q = 1; x = DEC(x); } -auto Z80::instructionDEC_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionDEC_rr(n16& x) -> void { Q = 0; wait(2); x--; } @@ -209,7 +209,7 @@ auto Z80::instructionDI() -> void { Q = 0; auto Z80::instructionDJNZ_e() -> void { Q = 0; wait(1); - auto displacement = (int8)operand(); + auto displacement = (i8)operand(); if(!--B) return; wait(5); WZ = PC + displacement; @@ -220,7 +220,7 @@ auto Z80::instructionEI() -> void { Q = 0; EI = 1; //raise IFF1, IFF2 after the next instruction } -auto Z80::instructionEX_irr_rr(uint16& x, uint16& y) -> void { Q = 0; +auto Z80::instructionEX_irr_rr(n16& x, n16& y) -> void { Q = 0; WZL = read(x + 0); WZH = read(x + 1); write(x + 0, y >> 0); @@ -228,7 +228,7 @@ auto Z80::instructionEX_irr_rr(uint16& x, uint16& y) -> void { Q = 0; y = WZ; } -auto Z80::instructionEX_rr_rr(uint16& x, uint16& y) -> void { Q = 0; +auto Z80::instructionEX_rr_rr(n16& x, n16& y) -> void { Q = 0; swap(x, y); } @@ -242,7 +242,7 @@ auto Z80::instructionHALT() -> void { Q = 0; HALT = 1; } -auto Z80::instructionIM_o(uint2 code) -> void { Q = 0; +auto Z80::instructionIM_o(n2 code) -> void { Q = 0; wait(4); IM = code; } @@ -253,7 +253,7 @@ auto Z80::instructionIN_a_in() -> void { Q = 0; A = in(WZ++); } -auto Z80::instructionIN_r_ic(uint8& x) -> void { Q = 1; +auto Z80::instructionIN_r_ic(n8& x) -> void { Q = 1; x = IN(in(BC)); WZ = BC + 1; } @@ -263,18 +263,18 @@ auto Z80::instructionIN_ic() -> void { Q = 1; WZ = BC + 1; } -auto Z80::instructionINC_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionINC_irr(n16& x) -> void { Q = 1; auto addr = displace(x); auto data = read(addr); wait(1); write(addr, INC(data)); } -auto Z80::instructionINC_r(uint8& x) -> void { Q = 1; +auto Z80::instructionINC_r(n8& x) -> void { Q = 1; x = INC(x); } -auto Z80::instructionINC_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionINC_rr(n16& x) -> void { Q = 0; wait(2); x++; } @@ -285,9 +285,9 @@ auto Z80::instructionIND() -> void { Q = 1; wait(1); auto data = in(BC); write(_HL--, data); - CF = uint9(uint8(C - 1) + data).bit(8); + CF = n9(n8(C - 1) + data).bit(8); NF = data.bit(7); - PF = parity(uint8(C - 1) + data & 7 ^ B); + PF = parity(n8(C - 1) + data & 7 ^ B); XF = B.bit(3); HF = CF; YF = B.bit(5); @@ -308,9 +308,9 @@ auto Z80::instructionINI() -> void { Q = 1; wait(1); auto data = in(BC); write(_HL++, data); - CF = uint9(uint8(C + 1) + data).bit(8); + CF = n9(n8(C + 1) + data).bit(8); NF = data.bit(7); - PF = parity(uint8(C + 1) + data & 7 ^ B); + PF = parity(n8(C + 1) + data & 7 ^ B); XF = B.bit(3); HF = CF; YF = B.bit(5); @@ -330,12 +330,12 @@ auto Z80::instructionJP_c_nn(bool c) -> void { Q = 0; if(c) PC = WZ; } -auto Z80::instructionJP_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionJP_rr(n16& x) -> void { Q = 0; PC = x; } auto Z80::instructionJR_c_e(bool c) -> void { Q = 0; - auto displacement = (int8)operand(); + auto displacement = (i8)operand(); if(!c) return; wait(5); WZ = PC + displacement; @@ -347,7 +347,7 @@ auto Z80::instructionLD_a_inn() -> void { Q = 0; A = read(WZ++); } -auto Z80::instructionLD_a_irr(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_a_irr(n16& x) -> void { Q = 0; WZ = x; A = read(displace(WZ)); WZ++; @@ -359,49 +359,49 @@ auto Z80::instructionLD_inn_a() -> void { Q = 0; WZH = A; } -auto Z80::instructionLD_inn_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_inn_rr(n16& x) -> void { Q = 0; WZ = operands(); write(WZ + 0, x >> 0); write(WZ + 1, x >> 8); WZ++; } -auto Z80::instructionLD_irr_a(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_irr_a(n16& x) -> void { Q = 0; WZ = x; write(displace(WZ), A); WZL++; WZH = A; } -auto Z80::instructionLD_irr_n(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_irr_n(n16& x) -> void { Q = 0; auto addr = displace(x); write(addr, operand()); } -auto Z80::instructionLD_irr_r(uint16& x, uint8& y) -> void { Q = 0; +auto Z80::instructionLD_irr_r(n16& x, n8& y) -> void { Q = 0; write(displace(x), y); } -auto Z80::instructionLD_r_n(uint8& x) -> void { Q = 0; +auto Z80::instructionLD_r_n(n8& x) -> void { Q = 0; x = operand(); } -auto Z80::instructionLD_r_irr(uint8& x, uint16& y) -> void { Q = 0; +auto Z80::instructionLD_r_irr(n8& x, n16& y) -> void { Q = 0; x = read(displace(y)); } -auto Z80::instructionLD_r_r(uint8& x, uint8& y) -> void { Q = 0; +auto Z80::instructionLD_r_r(n8& x, n8& y) -> void { Q = 0; x = y; } //LD to/from I/R requires an extra T-cycle -auto Z80::instructionLD_r_r1(uint8& x, uint8& y) -> void { Q = 0; +auto Z80::instructionLD_r_r1(n8& x, n8& y) -> void { Q = 0; wait(1); x = y; } //LD from I/R sets status flags -auto Z80::instructionLD_r_r2(uint8& x, uint8& y) -> void { Q = 1; +auto Z80::instructionLD_r_r2(n8& x, n8& y) -> void { Q = 1; wait(1); x = y; NF = 0; @@ -414,17 +414,17 @@ auto Z80::instructionLD_r_r2(uint8& x, uint8& y) -> void { Q = 1; P = mosfet == MOSFET::NMOS; } -auto Z80::instructionLD_rr_inn(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_rr_inn(n16& x) -> void { Q = 0; auto addr = operands(); x.byte(0) = read(addr + 0); x.byte(1) = read(addr + 1); } -auto Z80::instructionLD_rr_nn(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_rr_nn(n16& x) -> void { Q = 0; x = operands(); } -auto Z80::instructionLD_sp_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionLD_sp_rr(n16& x) -> void { Q = 0; wait(2); SP = x; } @@ -435,9 +435,9 @@ auto Z80::instructionLDD() -> void { Q = 1; wait(2); NF = 0; VF = --BC != 0; - XF = uint8(A + data).bit(3); + XF = n8(A + data).bit(3); HF = 0; - YF = uint8(A + data).bit(1); + YF = n8(A + data).bit(1); } auto Z80::instructionLDDR() -> void { Q = 1; @@ -454,9 +454,9 @@ auto Z80::instructionLDI() -> void { Q = 1; wait(2); NF = 0; VF = --BC != 0; - XF = uint8(A + data).bit(3); + XF = n8(A + data).bit(3); HF = 0; - YF = uint8(A + data).bit(1); + YF = n8(A + data).bit(1); } auto Z80::instructionLDIR() -> void { Q = 1; @@ -474,7 +474,7 @@ auto Z80::instructionNEG() -> void { Q = 1; auto Z80::instructionNOP() -> void { Q = 0; } -auto Z80::instructionOR_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionOR_a_irr(n16& x) -> void { Q = 1; A = OR(A, read(displace(x))); } @@ -482,7 +482,7 @@ auto Z80::instructionOR_a_n() -> void { Q = 1; A = OR(A, operand()); } -auto Z80::instructionOR_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionOR_a_r(n8& x) -> void { Q = 1; A = OR(A, x); } @@ -500,7 +500,7 @@ auto Z80::instructionOTIR() -> void { Q = 1; PC -= 2; } -auto Z80::instructionOUT_ic_r(uint8& x) -> void { Q = 0; +auto Z80::instructionOUT_ic_r(n8& x) -> void { Q = 0; out(BC, x); WZ = BC + 1; } @@ -523,7 +523,7 @@ auto Z80::instructionOUTD() -> void { Q = 1; out(BC, data); B--; WZ = BC - 1; - CF = uint9(L + data).bit(8); + CF = n9(L + data).bit(8); NF = data.bit(7); PF = parity(L + data & 7 ^ B); XF = B.bit(3); @@ -539,7 +539,7 @@ auto Z80::instructionOUTI() -> void { Q = 1; out(BC, data); B--; WZ = BC + 1; - CF = uint9(L + data).bit(8); + CF = n9(L + data).bit(8); NF = data.bit(7); PF = parity(L + data & 7 ^ B); XF = B.bit(3); @@ -550,24 +550,24 @@ auto Z80::instructionOUTI() -> void { Q = 1; } //note: even though "pop af" affects flags, it does not set Q -auto Z80::instructionPOP_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionPOP_rr(n16& x) -> void { Q = 0; x = pop(); } -auto Z80::instructionPUSH_rr(uint16& x) -> void { Q = 0; +auto Z80::instructionPUSH_rr(n16& x) -> void { Q = 0; wait(1); push(x); } -auto Z80::instructionRES_o_irr(uint3 bit, uint16& addr) -> void { Q = 1; +auto Z80::instructionRES_o_irr(n3 bit, n16& addr) -> void { Q = 1; write(addr, RES(bit, read(addr))); } -auto Z80::instructionRES_o_irr_r(uint3 bit, uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionRES_o_irr_r(n3 bit, n16& addr, n8& x) -> void { Q = 1; write(addr, x = RES(bit, read(addr))); } -auto Z80::instructionRES_o_r(uint3 bit, uint8& x) -> void { Q = 1; +auto Z80::instructionRES_o_r(n3 bit, n8& x) -> void { Q = 1; x = RES(bit, x); } @@ -596,15 +596,15 @@ auto Z80::instructionRETN() -> void { Q = 0; IFF1 = IFF2; } -auto Z80::instructionRL_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionRL_irr(n16& addr) -> void { Q = 1; write(addr, RL(read(addr))); } -auto Z80::instructionRL_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionRL_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = RL(read(addr))); } -auto Z80::instructionRL_r(uint8& x) -> void { Q = 1; +auto Z80::instructionRL_r(n8& x) -> void { Q = 1; x = RL(x); } @@ -619,15 +619,15 @@ auto Z80::instructionRLA() -> void { Q = 1; YF = A.bit(5); } -auto Z80::instructionRLC_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionRLC_irr(n16& addr) -> void { Q = 1; write(addr, RLC(read(addr))); } -auto Z80::instructionRLC_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionRLC_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = RLC(read(addr))); } -auto Z80::instructionRLC_r(uint8& x) -> void { Q = 1; +auto Z80::instructionRLC_r(n8& x) -> void { Q = 1; x = RLC(x); } @@ -659,15 +659,15 @@ auto Z80::instructionRLD() -> void { Q = 1; SF = A.bit(7); } -auto Z80::instructionRR_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionRR_irr(n16& addr) -> void { Q = 1; write(addr, RR(read(addr))); } -auto Z80::instructionRR_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionRR_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = RR(read(addr))); } -auto Z80::instructionRR_r(uint8& x) -> void { Q = 1; +auto Z80::instructionRR_r(n8& x) -> void { Q = 1; x = RR(x); } @@ -682,15 +682,15 @@ auto Z80::instructionRRA() -> void { Q = 1; YF = A.bit(5); } -auto Z80::instructionRRC_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionRRC_irr(n16& addr) -> void { Q = 1; write(addr, RRC(read(addr))); } -auto Z80::instructionRRC_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionRRC_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = RRC(read(addr))); } -auto Z80::instructionRRC_r(uint8& x) -> void { Q = 1; +auto Z80::instructionRRC_r(n8& x) -> void { Q = 1; x = RRC(x); } @@ -722,14 +722,14 @@ auto Z80::instructionRRD() -> void { Q = 1; SF = A.bit(7); } -auto Z80::instructionRST_o(uint3 vector) -> void { Q = 0; +auto Z80::instructionRST_o(n3 vector) -> void { Q = 0; wait(1); push(PC); WZ = vector << 3; PC = WZ; } -auto Z80::instructionSBC_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionSBC_a_irr(n16& x) -> void { Q = 1; A = SUB(A, read(displace(x)), CF); } @@ -737,11 +737,11 @@ auto Z80::instructionSBC_a_n() -> void { Q = 1; A = SUB(A, operand(), CF); } -auto Z80::instructionSBC_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSBC_a_r(n8& x) -> void { Q = 1; A = SUB(A, x, CF); } -auto Z80::instructionSBC_hl_rr(uint16& x) -> void { Q = 1; +auto Z80::instructionSBC_hl_rr(n16& x) -> void { Q = 1; WZ = HL + 1; wait(4); auto lo = SUB(HL >> 0, x >> 0, CF); @@ -761,67 +761,67 @@ auto Z80::instructionSCF() -> void { Q = 1; } -auto Z80::instructionSET_o_irr(uint3 bit, uint16& addr) -> void { Q = 1; +auto Z80::instructionSET_o_irr(n3 bit, n16& addr) -> void { Q = 1; write(addr, SET(bit, read(addr))); } -auto Z80::instructionSET_o_irr_r(uint3 bit, uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionSET_o_irr_r(n3 bit, n16& addr, n8& x) -> void { Q = 1; write(addr, x = SET(bit, read(addr))); } -auto Z80::instructionSET_o_r(uint3 bit, uint8& x) -> void { Q = 1; +auto Z80::instructionSET_o_r(n3 bit, n8& x) -> void { Q = 1; x = SET(bit, x); } -auto Z80::instructionSLA_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionSLA_irr(n16& addr) -> void { Q = 1; write(addr, SLA(read(addr))); } -auto Z80::instructionSLA_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionSLA_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = SLA(read(addr))); } -auto Z80::instructionSLA_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSLA_r(n8& x) -> void { Q = 1; x = SLA(x); } -auto Z80::instructionSLL_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionSLL_irr(n16& addr) -> void { Q = 1; write(addr, SLL(read(addr))); } -auto Z80::instructionSLL_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionSLL_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = SLL(read(addr))); } -auto Z80::instructionSLL_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSLL_r(n8& x) -> void { Q = 1; x = SLL(x); } -auto Z80::instructionSRA_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionSRA_irr(n16& addr) -> void { Q = 1; write(addr, SRA(read(addr))); } -auto Z80::instructionSRA_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionSRA_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = SRA(read(addr))); } -auto Z80::instructionSRA_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSRA_r(n8& x) -> void { Q = 1; x = SRA(x); } -auto Z80::instructionSRL_irr(uint16& addr) -> void { Q = 1; +auto Z80::instructionSRL_irr(n16& addr) -> void { Q = 1; write(addr, SRL(read(addr))); } -auto Z80::instructionSRL_irr_r(uint16& addr, uint8& x) -> void { Q = 1; +auto Z80::instructionSRL_irr_r(n16& addr, n8& x) -> void { Q = 1; write(addr, x = SRL(read(addr))); } -auto Z80::instructionSRL_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSRL_r(n8& x) -> void { Q = 1; x = SRL(x); } -auto Z80::instructionSUB_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionSUB_a_irr(n16& x) -> void { Q = 1; A = SUB(A, read(displace(x))); } @@ -829,11 +829,11 @@ auto Z80::instructionSUB_a_n() -> void { Q = 1; A = SUB(A, operand()); } -auto Z80::instructionSUB_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionSUB_a_r(n8& x) -> void { Q = 1; A = SUB(A, x); } -auto Z80::instructionXOR_a_irr(uint16& x) -> void { Q = 1; +auto Z80::instructionXOR_a_irr(n16& x) -> void { Q = 1; A = XOR(A, read(displace(x))); } @@ -841,6 +841,6 @@ auto Z80::instructionXOR_a_n() -> void { Q = 1; A = XOR(A, operand()); } -auto Z80::instructionXOR_a_r(uint8& x) -> void { Q = 1; +auto Z80::instructionXOR_a_r(n8& x) -> void { Q = 1; A = XOR(A, x); } diff --git a/ares/component/processor/z80/memory.cpp b/ares/component/processor/z80/memory.cpp index 3b056fd497..b83c158cc7 100644 --- a/ares/component/processor/z80/memory.cpp +++ b/ares/component/processor/z80/memory.cpp @@ -7,65 +7,65 @@ auto Z80::yield() -> void { } } -auto Z80::wait(uint clocks) -> void { +auto Z80::wait(u32 clocks) -> void { yield(); step(clocks); } -auto Z80::opcode() -> uint8 { +auto Z80::opcode() -> n8 { yield(); step(4); return bus->read(r.pc++); } -auto Z80::operand() -> uint8 { +auto Z80::operand() -> n8 { yield(); step(3); return bus->read(r.pc++); } -auto Z80::operands() -> uint16 { - uint16 data = operand() << 0; +auto Z80::operands() -> n16 { + n16 data = operand() << 0; return data | operand() << 8; } -auto Z80::push(uint16 x) -> void { +auto Z80::push(n16 x) -> void { write(--SP, x >> 8); write(--SP, x >> 0); } -auto Z80::pop() -> uint16 { - uint16 data = read(SP++) << 0; +auto Z80::pop() -> n16 { + n16 data = read(SP++) << 0; return data | read(SP++) << 8; } -auto Z80::displace(uint16& x) -> uint16 { +auto Z80::displace(n16& x) -> n16 { if(&x != &r.ix.word && &x != &r.iy.word) return x; auto d = operand(); wait(5); - WZ = x + (int8)d; + WZ = x + (i8)d; return WZ; } -auto Z80::read(uint16 address) -> uint8 { +auto Z80::read(n16 address) -> n8 { yield(); step(3); return bus->read(address); } -auto Z80::write(uint16 address, uint8 data) -> void { +auto Z80::write(n16 address, n8 data) -> void { yield(); step(3); return bus->write(address, data); } -auto Z80::in(uint16 address) -> uint8 { +auto Z80::in(n16 address) -> n8 { yield(); step(4); return bus->in(address); } -auto Z80::out(uint16 address, uint8 data) -> void { +auto Z80::out(n16 address, n8 data) -> void { yield(); step(4); return bus->out(address, data); diff --git a/ares/component/processor/z80/serialization.cpp b/ares/component/processor/z80/serialization.cpp index 6f128ce943..767e702806 100644 --- a/ares/component/processor/z80/serialization.cpp +++ b/ares/component/processor/z80/serialization.cpp @@ -1,6 +1,6 @@ auto Z80::serialize(serializer& s) -> void { - s((uint&)mosfet); - s((uint&)prefix); + s((u32&)mosfet); + s((u32&)prefix); s(r.af.word); s(r.bc.word); s(r.de.word); diff --git a/ares/component/processor/z80/z80.cpp b/ares/component/processor/z80/z80.cpp index f50099ef40..d65cd1f2a6 100644 --- a/ares/component/processor/z80/z80.cpp +++ b/ares/component/processor/z80/z80.cpp @@ -23,14 +23,14 @@ auto Z80::power(MOSFET mosfet) -> void { IM = 1; } -auto Z80::irq(bool maskable, uint16 pc, uint8 extbus) -> bool { +auto Z80::irq(bool maskable, n16 pc, n8 extbus) -> bool { if(maskable && !IFF1) return false; wait(7); R.bit(0,6)++; push(PC); - switch(maskable ? IM : (uint2)1) { + switch(maskable ? IM : (n2)1) { case 0: { //external data bus ($ff = RST $38) @@ -46,7 +46,7 @@ auto Z80::irq(bool maskable, uint16 pc, uint8 extbus) -> bool { case 2: { //vector table with external data bus - uint16 addr = I << 8 | extbus; + n16 addr = I << 8 | extbus; WZL = read(addr + 0); WZH = read(addr + 1); break; @@ -64,7 +64,7 @@ auto Z80::irq(bool maskable, uint16 pc, uint8 extbus) -> bool { return true; } -auto Z80::parity(uint8 value) const -> bool { +auto Z80::parity(n8 value) const -> bool { value ^= value >> 4; value ^= value >> 2; value ^= value >> 1; diff --git a/ares/component/processor/z80/z80.hpp b/ares/component/processor/z80/z80.hpp index 87a3040598..e8f27ef2a2 100644 --- a/ares/component/processor/z80/z80.hpp +++ b/ares/component/processor/z80/z80.hpp @@ -12,11 +12,11 @@ struct Z80 { virtual auto request(bool value) -> void { _requested = value; } virtual auto grant(bool value) -> void { _granted = value; } - virtual auto read(uint16 address) -> uint8 = 0; - virtual auto write(uint16 address, uint8 data) -> void = 0; + virtual auto read(n16 address) -> n8 = 0; + virtual auto write(n16 address, n8 data) -> void = 0; - virtual auto in(uint16 address) -> uint8 = 0; - virtual auto out(uint16 address, uint8 data) -> void = 0; + virtual auto in(n16 address) -> n8 = 0; + virtual auto out(n16 address, n8 data) -> void = 0; //serialization.cpp virtual auto serialize(serializer&) -> void; @@ -26,220 +26,220 @@ struct Z80 { bool _granted; }; - virtual auto step(uint clocks) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; virtual auto synchronizing() const -> bool = 0; //CMOS: out (c) writes 0x00 //NMOS: out (c) writes 0xff; // if an interrupt fires during "ld a,i" or "ld a,r", PF is cleared - enum class MOSFET : uint { CMOS, NMOS }; + enum class MOSFET : u32 { CMOS, NMOS }; //z80.cpp auto power(MOSFET = MOSFET::NMOS) -> void; - auto irq(bool maskable, uint16 vector = 0x0000, uint8 extbus = 0xff) -> bool; - auto parity(uint8) const -> bool; + auto irq(bool maskable, n16 vector = 0x0000, n8 extbus = 0xff) -> bool; + auto parity(n8) const -> bool; //memory.cpp auto yield() -> void; - auto wait(uint clocks = 1) -> void; - auto opcode() -> uint8; - auto operand() -> uint8; - auto operands() -> uint16; - auto push(uint16) -> void; - auto pop() -> uint16; - auto displace(uint16&) -> uint16; - auto read(uint16 address) -> uint8; - auto write(uint16 address, uint8 data) -> void; - auto in(uint16 address) -> uint8; - auto out(uint16 address, uint8 data) -> void; + auto wait(u32 clocks = 1) -> void; + auto opcode() -> n8; + auto operand() -> n8; + auto operands() -> n16; + auto push(n16) -> void; + auto pop() -> n16; + auto displace(n16&) -> n16; + auto read(n16 address) -> n8; + auto write(n16 address, n8 data) -> void; + auto in(n16 address) -> n8; + auto out(n16 address, n8 data) -> void; //instruction.cpp auto instruction() -> void; - auto instruction(uint8 code) -> void; - auto instructionCB(uint8 code) -> void; - auto instructionCBd(uint16 addr, uint8 code) -> void; - auto instructionED(uint8 code) -> void; + auto instruction(n8 code) -> void; + auto instructionCB(n8 code) -> void; + auto instructionCBd(n16 address, n8 code) -> void; + auto instructionED(n8 code) -> void; //algorithms.cpp - auto ADD(uint8, uint8, bool = false) -> uint8; - auto AND(uint8, uint8) -> uint8; - auto BIT(uint3, uint8) -> uint8; - auto CP (uint8, uint8) -> void; - auto DEC(uint8) -> uint8; - auto IN (uint8) -> uint8; - auto INC(uint8) -> uint8; - auto OR (uint8, uint8) -> uint8; - auto RES(uint3, uint8) -> uint8; - auto RL (uint8) -> uint8; - auto RLC(uint8) -> uint8; - auto RR (uint8) -> uint8; - auto RRC(uint8) -> uint8; - auto SET(uint3, uint8) -> uint8; - auto SLA(uint8) -> uint8; - auto SLL(uint8) -> uint8; - auto SRA(uint8) -> uint8; - auto SRL(uint8) -> uint8; - auto SUB(uint8, uint8, bool = false) -> uint8; - auto XOR(uint8, uint8) -> uint8; + auto ADD(n8, n8, bool = false) -> n8; + auto AND(n8, n8) -> n8; + auto BIT(n3, n8) -> n8; + auto CP (n8, n8) -> void; + auto DEC(n8) -> n8; + auto IN (n8) -> n8; + auto INC(n8) -> n8; + auto OR (n8, n8) -> n8; + auto RES(n3, n8) -> n8; + auto RL (n8) -> n8; + auto RLC(n8) -> n8; + auto RR (n8) -> n8; + auto RRC(n8) -> n8; + auto SET(n3, n8) -> n8; + auto SLA(n8) -> n8; + auto SLL(n8) -> n8; + auto SRA(n8) -> n8; + auto SRL(n8) -> n8; + auto SUB(n8, n8, bool = false) -> n8; + auto XOR(n8, n8) -> n8; //instructions.cpp - auto instructionADC_a_irr(uint16&) -> void; + auto instructionADC_a_irr(n16&) -> void; auto instructionADC_a_n() -> void; - auto instructionADC_a_r(uint8&) -> void; - auto instructionADC_hl_rr(uint16&) -> void; - auto instructionADD_a_irr(uint16&) -> void; + auto instructionADC_a_r(n8&) -> void; + auto instructionADC_hl_rr(n16&) -> void; + auto instructionADD_a_irr(n16&) -> void; auto instructionADD_a_n() -> void; - auto instructionADD_a_r(uint8&) -> void; - auto instructionADD_hl_rr(uint16&) -> void; - auto instructionAND_a_irr(uint16&) -> void; + auto instructionADD_a_r(n8&) -> void; + auto instructionADD_hl_rr(n16&) -> void; + auto instructionAND_a_irr(n16&) -> void; auto instructionAND_a_n() -> void; - auto instructionAND_a_r(uint8&) -> void; - auto instructionBIT_o_irr(uint3, uint16&) -> void; - auto instructionBIT_o_irr_r(uint3, uint16&, uint8&) -> void; - auto instructionBIT_o_r(uint3, uint8&) -> void; + auto instructionAND_a_r(n8&) -> void; + auto instructionBIT_o_irr(n3, n16&) -> void; + auto instructionBIT_o_irr_r(n3, n16&, n8&) -> void; + auto instructionBIT_o_r(n3, n8&) -> void; auto instructionCALL_c_nn(bool c) -> void; auto instructionCALL_nn() -> void; auto instructionCCF() -> void; - auto instructionCP_a_irr(uint16& x) -> void; + auto instructionCP_a_irr(n16& x) -> void; auto instructionCP_a_n() -> void; - auto instructionCP_a_r(uint8& x) -> void; + auto instructionCP_a_r(n8& x) -> void; auto instructionCPD() -> void; auto instructionCPDR() -> void; auto instructionCPI() -> void; auto instructionCPIR() -> void; auto instructionCPL() -> void; auto instructionDAA() -> void; - auto instructionDEC_irr(uint16&) -> void; - auto instructionDEC_r(uint8&) -> void; - auto instructionDEC_rr(uint16&) -> void; + auto instructionDEC_irr(n16&) -> void; + auto instructionDEC_r(n8&) -> void; + auto instructionDEC_rr(n16&) -> void; auto instructionDI() -> void; auto instructionDJNZ_e() -> void; auto instructionEI() -> void; - auto instructionEX_irr_rr(uint16&, uint16&) -> void; - auto instructionEX_rr_rr(uint16&, uint16&) -> void; + auto instructionEX_irr_rr(n16&, n16&) -> void; + auto instructionEX_rr_rr(n16&, n16&) -> void; auto instructionEXX() -> void; auto instructionHALT() -> void; - auto instructionIM_o(uint2) -> void; + auto instructionIM_o(n2) -> void; auto instructionIN_a_in() -> void; - auto instructionIN_r_ic(uint8&) -> void; + auto instructionIN_r_ic(n8&) -> void; auto instructionIN_ic() -> void; - auto instructionINC_irr(uint16&) -> void; - auto instructionINC_r(uint8&) -> void; - auto instructionINC_rr(uint16&) -> void; + auto instructionINC_irr(n16&) -> void; + auto instructionINC_r(n8&) -> void; + auto instructionINC_rr(n16&) -> void; auto instructionIND() -> void; auto instructionINDR() -> void; auto instructionINI() -> void; auto instructionINIR() -> void; auto instructionJP_c_nn(bool) -> void; - auto instructionJP_rr(uint16&) -> void; + auto instructionJP_rr(n16&) -> void; auto instructionJR_c_e(bool) -> void; auto instructionLD_a_inn() -> void; - auto instructionLD_a_irr(uint16& x) -> void; + auto instructionLD_a_irr(n16& x) -> void; auto instructionLD_inn_a() -> void; - auto instructionLD_inn_rr(uint16&) -> void; - auto instructionLD_irr_a(uint16&) -> void; - auto instructionLD_irr_n(uint16&) -> void; - auto instructionLD_irr_r(uint16&, uint8&) -> void; - auto instructionLD_r_n(uint8&) -> void; - auto instructionLD_r_irr(uint8&, uint16&) -> void; - auto instructionLD_r_r(uint8&, uint8&) -> void; - auto instructionLD_r_r1(uint8&, uint8&) -> void; - auto instructionLD_r_r2(uint8&, uint8&) -> void; - auto instructionLD_rr_inn(uint16&) -> void; - auto instructionLD_rr_nn(uint16&) -> void; - auto instructionLD_sp_rr(uint16&) -> void; + auto instructionLD_inn_rr(n16&) -> void; + auto instructionLD_irr_a(n16&) -> void; + auto instructionLD_irr_n(n16&) -> void; + auto instructionLD_irr_r(n16&, n8&) -> void; + auto instructionLD_r_n(n8&) -> void; + auto instructionLD_r_irr(n8&, n16&) -> void; + auto instructionLD_r_r(n8&, n8&) -> void; + auto instructionLD_r_r1(n8&, n8&) -> void; + auto instructionLD_r_r2(n8&, n8&) -> void; + auto instructionLD_rr_inn(n16&) -> void; + auto instructionLD_rr_nn(n16&) -> void; + auto instructionLD_sp_rr(n16&) -> void; auto instructionLDD() -> void; auto instructionLDDR() -> void; auto instructionLDI() -> void; auto instructionLDIR() -> void; auto instructionNEG() -> void; auto instructionNOP() -> void; - auto instructionOR_a_irr(uint16&) -> void; + auto instructionOR_a_irr(n16&) -> void; auto instructionOR_a_n() -> void; - auto instructionOR_a_r(uint8&) -> void; + auto instructionOR_a_r(n8&) -> void; auto instructionOTDR() -> void; auto instructionOTIR() -> void; - auto instructionOUT_ic_r(uint8&) -> void; + auto instructionOUT_ic_r(n8&) -> void; auto instructionOUT_ic() -> void; auto instructionOUT_in_a() -> void; auto instructionOUTD() -> void; auto instructionOUTI() -> void; - auto instructionPOP_rr(uint16&) -> void; - auto instructionPUSH_rr(uint16&) -> void; - auto instructionRES_o_irr(uint3, uint16&) -> void; - auto instructionRES_o_irr_r(uint3, uint16&, uint8&) -> void; - auto instructionRES_o_r(uint3, uint8&) -> void; + auto instructionPOP_rr(n16&) -> void; + auto instructionPUSH_rr(n16&) -> void; + auto instructionRES_o_irr(n3, n16&) -> void; + auto instructionRES_o_irr_r(n3, n16&, n8&) -> void; + auto instructionRES_o_r(n3, n8&) -> void; auto instructionRET() -> void; auto instructionRET_c(bool c) -> void; auto instructionRETI() -> void; auto instructionRETN() -> void; - auto instructionRL_irr(uint16&) -> void; - auto instructionRL_irr_r(uint16&, uint8&) -> void; - auto instructionRL_r(uint8&) -> void; + auto instructionRL_irr(n16&) -> void; + auto instructionRL_irr_r(n16&, n8&) -> void; + auto instructionRL_r(n8&) -> void; auto instructionRLA() -> void; - auto instructionRLC_irr(uint16&) -> void; - auto instructionRLC_irr_r(uint16&, uint8&) -> void; - auto instructionRLC_r(uint8&) -> void; + auto instructionRLC_irr(n16&) -> void; + auto instructionRLC_irr_r(n16&, n8&) -> void; + auto instructionRLC_r(n8&) -> void; auto instructionRLCA() -> void; auto instructionRLD() -> void; - auto instructionRR_irr(uint16&) -> void; - auto instructionRR_irr_r(uint16&, uint8&) -> void; - auto instructionRR_r(uint8&) -> void; + auto instructionRR_irr(n16&) -> void; + auto instructionRR_irr_r(n16&, n8&) -> void; + auto instructionRR_r(n8&) -> void; auto instructionRRA() -> void; - auto instructionRRC_irr(uint16&) -> void; - auto instructionRRC_irr_r(uint16&, uint8&) -> void; - auto instructionRRC_r(uint8&) -> void; + auto instructionRRC_irr(n16&) -> void; + auto instructionRRC_irr_r(n16&, n8&) -> void; + auto instructionRRC_r(n8&) -> void; auto instructionRRCA() -> void; auto instructionRRD() -> void; - auto instructionRST_o(uint3) -> void; - auto instructionSBC_a_irr(uint16&) -> void; + auto instructionRST_o(n3) -> void; + auto instructionSBC_a_irr(n16&) -> void; auto instructionSBC_a_n() -> void; - auto instructionSBC_a_r(uint8&) -> void; - auto instructionSBC_hl_rr(uint16&) -> void; + auto instructionSBC_a_r(n8&) -> void; + auto instructionSBC_hl_rr(n16&) -> void; auto instructionSCF() -> void; - auto instructionSET_o_irr(uint3, uint16&) -> void; - auto instructionSET_o_irr_r(uint3, uint16&, uint8&) -> void; - auto instructionSET_o_r(uint3, uint8&) -> void; - auto instructionSLA_irr(uint16&) -> void; - auto instructionSLA_irr_r(uint16&, uint8&) -> void; - auto instructionSLA_r(uint8&) -> void; - auto instructionSLL_irr(uint16&) -> void; - auto instructionSLL_irr_r(uint16&, uint8&) -> void; - auto instructionSLL_r(uint8&) -> void; - auto instructionSRA_irr(uint16&) -> void; - auto instructionSRA_irr_r(uint16&, uint8&) -> void; - auto instructionSRA_r(uint8&) -> void; - auto instructionSRL_irr(uint16&) -> void; - auto instructionSRL_irr_r(uint16&, uint8&) -> void; - auto instructionSRL_r(uint8&) -> void; - auto instructionSUB_a_irr(uint16&) -> void; + auto instructionSET_o_irr(n3, n16&) -> void; + auto instructionSET_o_irr_r(n3, n16&, n8&) -> void; + auto instructionSET_o_r(n3, n8&) -> void; + auto instructionSLA_irr(n16&) -> void; + auto instructionSLA_irr_r(n16&, n8&) -> void; + auto instructionSLA_r(n8&) -> void; + auto instructionSLL_irr(n16&) -> void; + auto instructionSLL_irr_r(n16&, n8&) -> void; + auto instructionSLL_r(n8&) -> void; + auto instructionSRA_irr(n16&) -> void; + auto instructionSRA_irr_r(n16&, n8&) -> void; + auto instructionSRA_r(n8&) -> void; + auto instructionSRL_irr(n16&) -> void; + auto instructionSRL_irr_r(n16&, n8&) -> void; + auto instructionSRL_r(n8&) -> void; + auto instructionSUB_a_irr(n16&) -> void; auto instructionSUB_a_n() -> void; - auto instructionSUB_a_r(uint8&) -> void; - auto instructionXOR_a_irr(uint16&) -> void; + auto instructionSUB_a_r(n8&) -> void; + auto instructionXOR_a_irr(n16&) -> void; auto instructionXOR_a_n() -> void; - auto instructionXOR_a_r(uint8&) -> void; + auto instructionXOR_a_r(n8&) -> void; //serialization.cpp auto serialize(serializer&) -> void; //disassembler.cpp - noinline auto disassembleInstruction(maybe pc = {}) -> string; + noinline auto disassembleInstruction(maybe pc = {}) -> string; noinline auto disassembleContext() -> string; - auto disassemble(uint16 pc, uint8 prefix, uint8 code) -> string; - auto disassembleCB(uint16 pc, uint8 prefix, uint8 code) -> string; - auto disassembleCBd(uint16 pc, uint8 prefix, int8 d, uint8 code) -> string; - auto disassembleED(uint16 pc, uint8 prefix, uint8 code) -> string; + auto disassemble(n16 pc, n8 prefix, n8 code) -> string; + auto disassembleCB(n16 pc, n8 prefix, n8 code) -> string; + auto disassembleCBd(n16 pc, n8 prefix, i8 d, n8 code) -> string; + auto disassembleED(n16 pc, n8 prefix, n8 code) -> string; MOSFET mosfet = MOSFET::NMOS; - enum class Prefix : uint { hl, ix, iy } prefix = Prefix::hl; + enum class Prefix : u32 { hl, ix, iy } prefix = Prefix::hl; struct Registers { union Pair { Pair() : word(0) {} - uint16 word; - struct Byte { uint8 order_msb2(hi, lo); } byte; + n16 word; + struct Byte { n8 order_msb2(hi, lo); } byte; }; Pair af, af_; @@ -250,16 +250,16 @@ struct Z80 { Pair iy; Pair ir; Pair wz; - uint16 sp; - uint16 pc; + n16 sp; + n16 pc; - boolean ei; //"ei" executed last - boolean p; //"ld a,i" or "ld a,r" executed last - boolean q; //opcode that updated flag registers executed last - boolean halt; //HALT instruction executed - boolean iff1; //interrupt flip-flop 1 - boolean iff2; //interrupt flip-flop 2 - uint2 im; //interrupt mode (0-2) + b1 ei; //"ei" executed last + b1 p; //"ld a,i" or "ld a,r" executed last + b1 q; //opcode that updated flag registers executed last + b1 halt; //HALT instruction executed + b1 iff1; //interrupt flip-flop 1 + b1 iff2; //interrupt flip-flop 2 + n2 im; //interrupt mode (0-2) } r; Bus* bus = nullptr; diff --git a/ares/component/video/tms9918/background.cpp b/ares/component/video/tms9918/background.cpp index f86755bbc0..c125400997 100644 --- a/ares/component/video/tms9918/background.cpp +++ b/ares/component/video/tms9918/background.cpp @@ -1,4 +1,4 @@ -auto TMS9918::background(uint8 hoffset, uint8 voffset) -> void { +auto TMS9918::background(n8 hoffset, n8 voffset) -> void { if(!io.displayEnable) { output.color = io.colorBackground; return; @@ -13,28 +13,28 @@ auto TMS9918::background(uint8 hoffset, uint8 voffset) -> void { } } -auto TMS9918::text1(uint8 hoffset, uint8 voffset) -> void { +auto TMS9918::text1(n8 hoffset, n8 voffset) -> void { } -auto TMS9918::graphics1(uint8 hoffset, uint8 voffset) -> void { - uint14 nameAddress; +auto TMS9918::graphics1(n8 hoffset, n8 voffset) -> void { + n14 nameAddress; nameAddress.bit( 0, 4) = hoffset.bit(3,7); nameAddress.bit( 5, 9) = voffset.bit(3,7); nameAddress.bit(10,13) = io.nameTableAddress; - uint8 pattern = vram.read(nameAddress); + n8 pattern = vram.read(nameAddress); - uint14 patternAddress; + n14 patternAddress; patternAddress.bit( 0, 2) = voffset.bit(0,2); patternAddress.bit( 3,10) = pattern; patternAddress.bit(11,13) = io.patternTableAddress; - uint14 colorAddress; //d5 = 0 + n14 colorAddress; //d5 = 0 colorAddress.bit(0, 4) = pattern.bit(3,7); colorAddress.bit(6,13) = io.colorTableAddress; - uint8 color = vram.read(colorAddress); - uint3 index = hoffset ^ 7; + n8 color = vram.read(colorAddress); + n3 index = hoffset ^ 7; if(!vram.read(patternAddress).bit(index)) { output.color = color.bit(0,3); } else { @@ -42,26 +42,26 @@ auto TMS9918::graphics1(uint8 hoffset, uint8 voffset) -> void { } } -auto TMS9918::graphics2(uint8 hoffset, uint8 voffset) -> void { - uint14 nameAddress; +auto TMS9918::graphics2(n8 hoffset, n8 voffset) -> void { + n14 nameAddress; nameAddress.bit( 0, 4) = hoffset.bit(3,7); nameAddress.bit( 5, 9) = voffset.bit(3,7); nameAddress.bit(10,13) = io.nameTableAddress; - uint8 pattern = vram.read(nameAddress); + n8 pattern = vram.read(nameAddress); - uint14 patternAddress; + n14 patternAddress; patternAddress.bit(0, 2) = voffset.bit(0,2); patternAddress.bit(3,10) = pattern; if(voffset >= 64 && voffset <= 127) patternAddress.bit(11) = io.patternTableAddress.bit(0); if(voffset >= 128 && voffset <= 191) patternAddress.bit(12) = io.patternTableAddress.bit(1); - uint14 colorAddress = patternAddress; + n14 colorAddress = patternAddress; patternAddress.bit(13) = io.patternTableAddress.bit(2); colorAddress.bit(13) = io.colorTableAddress.bit(7); - uint8 colorMask = io.colorTableAddress.bit(0,6) << 1 | 1; - uint8 color = vram.read(colorAddress); - uint3 index = hoffset ^ 7; + n8 colorMask = io.colorTableAddress.bit(0,6) << 1 | 1; + n8 color = vram.read(colorAddress); + n3 index = hoffset ^ 7; if(!vram.read(patternAddress).bit(index)) { output.color = color.bit(0,3); } else { @@ -72,5 +72,5 @@ auto TMS9918::graphics2(uint8 hoffset, uint8 voffset) -> void { } } -auto TMS9918::multicolor(uint8 hoffset, uint8 voffset) -> void { +auto TMS9918::multicolor(n8 hoffset, n8 voffset) -> void { } diff --git a/ares/component/video/tms9918/io.cpp b/ares/component/video/tms9918/io.cpp index 08656c9ea4..bfbb5685e7 100644 --- a/ares/component/video/tms9918/io.cpp +++ b/ares/component/video/tms9918/io.cpp @@ -1,6 +1,6 @@ -auto TMS9918::status() -> uint8 { +auto TMS9918::status() -> n8 { io.controlLatch = 0; - uint8 data = 0x00; + n8 data = 0x00; data.bit(0,4) = io.spriteOverflowIndex; data.bit(5) = io.spriteCollision; data.bit(6) = io.spriteOverflow; @@ -9,21 +9,21 @@ auto TMS9918::status() -> uint8 { return data; } -auto TMS9918::data() -> uint8 { +auto TMS9918::data() -> n8 { io.controlLatch = 0; - uint14 address = io.controlValue.bit(0,13)++; - uint8 data = io.vramLatch; + n14 address = io.controlValue.bit(0,13)++; + n8 data = io.vramLatch; io.vramLatch = vram.read(address); return data; } -auto TMS9918::data(uint8 data) -> void { +auto TMS9918::data(n8 data) -> void { io.controlLatch = 0; - uint14 address = io.controlValue.bit(0,13)++; + n14 address = io.controlValue.bit(0,13)++; vram.write(address, data); } -auto TMS9918::control(uint8 data) -> void { +auto TMS9918::control(n8 data) -> void { io.controlValue.byte(io.controlLatch++) = data; if(io.controlLatch) return; if(io.controlValue.bit(15)) { @@ -32,7 +32,7 @@ auto TMS9918::control(uint8 data) -> void { if(!io.controlValue.bit(14)) TMS9918::data(); //read-ahead } -auto TMS9918::register(uint3 register, uint8 data) -> void { +auto TMS9918::register(n3 register, n8 data) -> void { switch(register) { case 0: io.externalInput = data.bit(0); diff --git a/ares/component/video/tms9918/sprites.cpp b/ares/component/video/tms9918/sprites.cpp index 425108667c..475cac94f7 100644 --- a/ares/component/video/tms9918/sprites.cpp +++ b/ares/component/video/tms9918/sprites.cpp @@ -1,21 +1,21 @@ -auto TMS9918::sprite(uint8 voffset) -> void { +auto TMS9918::sprite(n8 voffset) -> void { io.spriteCollision = false; io.spriteOverflow = false; io.spriteOverflowIndex = 0; - uint8 valid = 0; - uint5 limit = (8 << io.spriteSize << io.spriteZoom) - 1; - for(uint index : range(4)) sprites[index].y = 0xd0; + n8 valid = 0; + n5 limit = (8 << io.spriteSize << io.spriteZoom) - 1; + for(u32 index : range(4)) sprites[index].y = 0xd0; - uint14 attributeAddress; + n14 attributeAddress; attributeAddress.bit(7,13) = io.spriteAttributeTableAddress; - for(uint index : range(32)) { - uint8 y = vram.read(attributeAddress++); + for(u32 index : range(32)) { + n8 y = vram.read(attributeAddress++); if(y == 0xd0) break; - uint8 x = vram.read(attributeAddress++); - uint8 pattern = vram.read(attributeAddress++); - uint8 extra = vram.read(attributeAddress++); + n8 x = vram.read(attributeAddress++); + n8 pattern = vram.read(attributeAddress++); + n8 extra = vram.read(attributeAddress++); if(extra.bit(7)) x -= 32; y += 1; @@ -34,24 +34,24 @@ auto TMS9918::sprite(uint8 voffset) -> void { } } -auto TMS9918::sprite(uint8 hoffset, uint8 voffset) -> void { - uint4 color; - uint5 limit = (8 << io.spriteSize << io.spriteZoom) - 1; +auto TMS9918::sprite(n8 hoffset, n8 voffset) -> void { + n4 color; + n5 limit = (8 << io.spriteSize << io.spriteZoom) - 1; - for(uint n : range(4)) { + for(u32 n : range(4)) { auto& o = sprites[n]; if(o.y == 0xd0) continue; if(hoffset < o.x) continue; if(hoffset > o.x + limit) continue; - uint x = hoffset - o.x >> io.spriteZoom; - uint y = voffset - o.y >> io.spriteZoom; + u32 x = hoffset - o.x >> io.spriteZoom; + u32 y = voffset - o.y >> io.spriteZoom; - uint14 address; + n14 address; address.bit( 0,10) = (o.pattern << 3) + (x >> 3 << 4) + y; address.bit(11,13) = io.spritePatternTableAddress; - uint3 index = x ^ 7; + n3 index = x ^ 7; if(vram.read(address).bit(index)) { if(color) { io.spriteCollision = true; break; } color = o.color; diff --git a/ares/component/video/tms9918/tms9918.cpp b/ares/component/video/tms9918/tms9918.cpp index 7039a46d2a..367c8cc09a 100644 --- a/ares/component/video/tms9918/tms9918.cpp +++ b/ares/component/video/tms9918/tms9918.cpp @@ -18,10 +18,10 @@ auto TMS9918::unload() -> void { auto TMS9918::main() -> void { if(io.vcounter < 192) { - uint8 y = io.vcounter; + n8 y = io.vcounter; sprite(y); auto line = screen->pixels().data() + y * 256; - for(uint8 x : range(256)) { + for(n8 x : range(256)) { background(x, y); sprite(x, y); line[x] = output.color; diff --git a/ares/component/video/tms9918/tms9918.hpp b/ares/component/video/tms9918/tms9918.hpp index 5baeb4fef5..1e2949082f 100644 --- a/ares/component/video/tms9918/tms9918.hpp +++ b/ares/component/video/tms9918/tms9918.hpp @@ -7,7 +7,7 @@ namespace ares { struct TMS9918 { Node::Video::Screen screen; - virtual auto step(uint clocks) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; virtual auto irq(bool line) -> void = 0; virtual auto frame() -> void = 0; @@ -19,68 +19,68 @@ struct TMS9918 { auto power() -> void; //io.cpp - auto status() -> uint8; - auto data() -> uint8; + auto status() -> n8; + auto data() -> n8; - auto data(uint8) -> void; - auto control(uint8) -> void; - auto register(uint3, uint8) -> void; + auto data(n8) -> void; + auto control(n8) -> void; + auto register(n3, n8) -> void; //background.cpp - auto background(uint8 hoffset, uint8 voffset) -> void; - auto text1(uint8 hoffset, uint8 voffset) -> void; - auto graphics1(uint8 hoffset, uint8 voffset) -> void; - auto graphics2(uint8 hoffset, uint8 voffset) -> void; - auto multicolor(uint8 hoffset, uint8 voffset) -> void; + auto background(n8 hoffset, n8 voffset) -> void; + auto text1(n8 hoffset, n8 voffset) -> void; + auto graphics1(n8 hoffset, n8 voffset) -> void; + auto graphics2(n8 hoffset, n8 voffset) -> void; + auto multicolor(n8 hoffset, n8 voffset) -> void; //sprites.cpp - auto sprite(uint8 voffset) -> void; - auto sprite(uint8 hoffset, uint8 voffset) -> void; + auto sprite(n8 voffset) -> void; + auto sprite(n8 hoffset, n8 voffset) -> void; //serialization.cpp auto serialize(serializer&) -> void; protected: - Memory::Writable vram; + Memory::Writable vram; struct IO { - uint vcounter = 0; - uint hcounter = 0; - - uint1 controlLatch; - uint16 controlValue; - uint8 vramLatch; - - uint5 spriteOverflowIndex; - uint1 spriteCollision; - uint1 spriteOverflow; - uint1 irqLine; - - uint1 externalInput; - uint3 videoMode; - uint1 spriteZoom; - uint1 spriteSize; - uint1 irqEnable; - uint1 displayEnable; - uint1 ramMode = 1; //0 = 4KB; 1 = 16KB - uint4 nameTableAddress; - uint8 colorTableAddress; - uint3 patternTableAddress; - uint7 spriteAttributeTableAddress; - uint3 spritePatternTableAddress; - uint4 colorBackground; - uint4 colorForeground; + u32 vcounter = 0; + u32 hcounter = 0; + + n1 controlLatch; + n16 controlValue; + n8 vramLatch; + + n5 spriteOverflowIndex; + n1 spriteCollision; + n1 spriteOverflow; + n1 irqLine; + + n1 externalInput; + n3 videoMode; + n1 spriteZoom; + n1 spriteSize; + n1 irqEnable; + n1 displayEnable; + n1 ramMode = 1; //0 = 4KB; 1 = 16KB + n4 nameTableAddress; + n8 colorTableAddress; + n3 patternTableAddress; + n7 spriteAttributeTableAddress; + n3 spritePatternTableAddress; + n4 colorBackground; + n4 colorForeground; } io; struct Sprite { - uint8 x; - uint8 y; - uint8 pattern; - uint4 color; + n8 x; + n8 y; + n8 pattern; + n4 color; } sprites[4]; struct Output { - uint4 color; + n4 color; } output; }; diff --git a/ares/component/video/v9938/commands.cpp b/ares/component/video/v9938/commands.cpp index 78fde443e7..5cd076b4ee 100644 --- a/ares/component/video/v9938/commands.cpp +++ b/ares/component/video/v9938/commands.cpp @@ -1,4 +1,4 @@ -auto V9938::command(uint8 data) -> void { +auto V9938::command(n8 data) -> void { if(!data.bit(4,7)) return (void)(op.executing = 0); //stop if(op.executing) return; //busy @@ -41,20 +41,20 @@ auto V9938::command() -> void { auto V9938::relatch() -> void { if(op.lgm == 4) { - op.lsx = (uint8)op.sx & ~1; - op.ldx = (uint8)op.dx & ~1; + op.lsx = (n8)op.sx & ~1; + op.ldx = (n8)op.dx & ~1; op.lnx = op.nx & ~1; } else if(op.lgm == 5) { - op.lsx = (uint9)op.sx & ~3; - op.ldx = (uint9)op.dx & ~3; + op.lsx = (n9)op.sx & ~3; + op.ldx = (n9)op.dx & ~3; op.lnx = op.nx & ~3; } else if(op.lgm == 6) { - op.lsx = (uint9)op.sx & ~1; - op.ldx = (uint9)op.dx & ~1; + op.lsx = (n9)op.sx & ~1; + op.ldx = (n9)op.dx & ~1; op.lnx = op.nx & ~1; } else if(op.lgm == 7) { - op.lsx = (uint8)op.sx & ~0; - op.ldx = (uint8)op.dx & ~0; + op.lsx = (n8)op.sx & ~0; + op.ldx = (n8)op.dx & ~0; op.lnx = op.nx & ~0; } } @@ -74,7 +74,7 @@ auto V9938::advance() -> bool { return false; } -auto V9938::logic(uint8 dc, uint8 sc) -> uint8 { +auto V9938::logic(n8 dc, n8 sc) -> n8 { switch(op.logic) { case 0: dc = sc; break; case 1: dc = sc & dc; break; @@ -96,28 +96,28 @@ auto V9938::logic(uint8 dc, uint8 sc) -> uint8 { return dc; } -auto V9938::address(uint9 x, uint10 y) -> uint17 { - if(op.lgm == 4) return y * 256 + (uint8)x >> 1; - if(op.lgm == 5) return y * 512 + (uint9)x >> 2; - if(op.lgm == 6) return y * 512 + (uint9)x >> 1; - if(op.lgm == 7) return y * 256 + (uint8)x >> 0; +auto V9938::address(n9 x, n10 y) -> n17 { + if(op.lgm == 4) return y * 256 + (n8)x >> 1; + if(op.lgm == 5) return y * 512 + (n9)x >> 2; + if(op.lgm == 6) return y * 512 + (n9)x >> 1; + if(op.lgm == 7) return y * 256 + (n8)x >> 0; unreachable; } -auto V9938::read(uint1 source, uint9 x, uint10 y) -> uint8 { +auto V9938::read(n1 source, n9 x, n10 y) -> n8 { auto& ram = !source ? videoRAM : expansionRAM; - uint8 byte = ram.read(address(x, y)); - if(op.lgm == 4) return uint4(byte >> (~x & 1) * 4); - if(op.lgm == 5) return uint2(byte >> (~x & 3) * 2); - if(op.lgm == 6) return uint4(byte >> (~x & 1) * 4); - if(op.lgm == 7) return uint8(byte >> (~x & 0) * 8); + n8 byte = ram.read(address(x, y)); + if(op.lgm == 4) return n4(byte >> (~x & 1) * 4); + if(op.lgm == 5) return n2(byte >> (~x & 3) * 2); + if(op.lgm == 6) return n4(byte >> (~x & 1) * 4); + if(op.lgm == 7) return n8(byte >> (~x & 0) * 8); unreachable; } -auto V9938::write(uint1 source, uint9 x, uint10 y, uint8 data) -> void { +auto V9938::write(n1 source, n9 x, n10 y, n8 data) -> void { auto& ram = !source ? videoRAM : expansionRAM; - uint8 byte = ram.read(address(x, y)); - uint8 lo, hi; + n8 byte = ram.read(address(x, y)); + n8 lo, hi; if(op.lgm == 4) lo = (~x & 1) * 4, hi = lo + 3; if(op.lgm == 5) lo = (~x & 3) * 2, hi = lo + 1; if(op.lgm == 6) lo = (~x & 1) * 4, hi = lo + 3; @@ -134,8 +134,8 @@ auto V9938::point() -> void { //write pixel from VDP to VRAM auto V9938::pset() -> void { - uint8 sc = op.cr; - uint8 dc = read(op.mxd, op.ldx, op.dy); + n8 sc = op.cr; + n8 dc = read(op.mxd, op.ldx, op.dy); dc = logic(dc, sc); write(op.mxd, op.ldx, op.dy, dc); op.executing = 0; @@ -143,7 +143,7 @@ auto V9938::pset() -> void { //search from VDP to VRAM auto V9938::srch() -> void { - uint8 sc = read(op.mxs, op.lsx, op.sy); + n8 sc = read(op.mxs, op.lsx, op.sy); if((op.eq && sc == op.cr) || (!op.eq && sc != op.cr)) { op.found = 1; op.match = op.lsx; @@ -157,29 +157,29 @@ auto V9938::srch() -> void { //note: no timing emulation currently //algorithm is just bresenham, which is probably not right, but it looks okay auto V9938::line() -> void { - int nx = op.nx; - int ny = op.ny; + s32 nx = op.nx; + s32 ny = op.ny; if(op.maj) swap(nx, ny); - int x0 = op.dx; - int y0 = op.dy; + s32 x0 = op.dx; + s32 y0 = op.dy; - int x1 = op.dx + (!op.dix ? +nx : -nx); - int y1 = op.dy + (!op.diy ? +ny : -ny); + s32 x1 = op.dx + (!op.dix ? +nx : -nx); + s32 y1 = op.dy + (!op.diy ? +ny : -ny); - int dx = abs(x1 - x0), sx = x0 < x1 ? +1 : -1; - int dy = abs(y1 - y0), sy = y0 < y1 ? +1 : -1; + s32 dx = abs(x1 - x0), sx = x0 < x1 ? +1 : -1; + s32 dy = abs(y1 - y0), sy = y0 < y1 ? +1 : -1; - int error = (dx > dy ? +dx : -dy) / 2; + s32 error = (dx > dy ? +dx : -dy) / 2; while(true) { - uint8 sc = op.cr; - uint8 dc = read(op.mxd, x0, y0); + n8 sc = op.cr; + n8 dc = read(op.mxd, x0, y0); dc = logic(dc, sc); write(op.mxd, x0, y0, dc); if(x0 == x1 && y0 == y1) break; - int e = error; + s32 e = error; if(e > -dx) { error -= dy; x0 += sx; } if(e < +dy) { error += dx; y0 += sy; } } @@ -189,8 +189,8 @@ auto V9938::line() -> void { //logical move VDP to VRAM auto V9938::lmmv() -> void { - uint8 sc = op.cr; - uint8 dc = read(op.mxd, op.ldx, op.dy); + n8 sc = op.cr; + n8 dc = read(op.mxd, op.ldx, op.dy); dc = logic(dc, sc); write(op.mxd, op.ldx, op.dy, dc); advance(); @@ -198,8 +198,8 @@ auto V9938::lmmv() -> void { //logical move VRAM to VRAM auto V9938::lmmm() -> void { - uint8 sc = read(op.mxs, op.lsx, op.sy); - uint8 dc = read(op.mxd, op.ldx, op.dy); + n8 sc = read(op.mxs, op.lsx, op.sy); + n8 dc = read(op.mxd, op.ldx, op.dy); dc = logic(dc, sc); write(op.mxd, op.ldx, op.dy, dc); advance(); @@ -209,8 +209,8 @@ auto V9938::lmmm() -> void { auto V9938::lmcm() -> void { if(op.ready) return; op.ready = 0; - uint8 sc = read(op.mxs, op.lsx, op.sy); - uint8 dc = op.cr; + n8 sc = read(op.mxs, op.lsx, op.sy); + n8 dc = op.cr; dc = logic(dc, sc); op.cr = dc; advance(); @@ -220,8 +220,8 @@ auto V9938::lmcm() -> void { auto V9938::lmmc() -> void { if(op.ready) return; op.ready = 0; - uint8 sc = op.cr; - uint8 dc = read(op.mxd, op.ldx, op.dy); + n8 sc = op.cr; + n8 dc = read(op.mxd, op.ldx, op.dy); write(op.mxd, op.ldx, op.dy, dc); advance(); } @@ -234,14 +234,14 @@ auto V9938::hmmv() -> void { //high-speed move VRAM to VRAM auto V9938::hmmm() -> void { - uint8 data = read(op.mxs, op.lsx, op.sy); + n8 data = read(op.mxs, op.lsx, op.sy); write(op.mxd, op.ldx, op.dy, data); advance(); } //high-speed move VRAM to VRAM, Y-coordinate only auto V9938::ymmm() -> void { - uint8 data = read(op.mxd, op.ldx, op.sy); + n8 data = read(op.mxd, op.ldx, op.sy); write(op.mxd, op.ldx, op.dy, data); advance(); } diff --git a/ares/component/video/v9938/graphic1.cpp b/ares/component/video/v9938/graphic1.cpp index 3dc05dfee3..1e6e75848c 100644 --- a/ares/component/video/v9938/graphic1.cpp +++ b/ares/component/video/v9938/graphic1.cpp @@ -1,20 +1,20 @@ -auto V9938::graphic1(uint4& color, uint8 hoffset, uint8 voffset) -> void { - uint14 patternLayout; +auto V9938::graphic1(n4& color, n8 hoffset, n8 voffset) -> void { + n14 patternLayout; patternLayout.bit( 0, 4) = hoffset.bit(3,7); patternLayout.bit( 5, 9) = voffset.bit(3,7); patternLayout.bit(10,13) = table.patternLayout.bit(10,13); - uint8 pattern = videoRAM.read(patternLayout); + n8 pattern = videoRAM.read(patternLayout); - uint14 patternGenerator; + n14 patternGenerator; patternGenerator.bit( 0, 2) = voffset.bit(0,2); patternGenerator.bit( 3,10) = pattern; patternGenerator.bit(11,13) = table.patternGenerator.bit(11,13); - uint14 colorAddress; //d5 = 0 + n14 colorAddress; //d5 = 0 colorAddress.bit(0, 4) = pattern.bit(3,7); colorAddress.bit(6,13) = table.color.bit(6,13); - uint8 output = videoRAM.read(colorAddress); + n8 output = videoRAM.read(colorAddress); if(videoRAM.read(patternGenerator).bit(~hoffset & 7)) output >>= 4; color = output.bit(0,3); } diff --git a/ares/component/video/v9938/graphic2.cpp b/ares/component/video/v9938/graphic2.cpp index 1c3ecb7163..ce22971fa5 100644 --- a/ares/component/video/v9938/graphic2.cpp +++ b/ares/component/video/v9938/graphic2.cpp @@ -1,22 +1,22 @@ -auto V9938::graphic2(uint4& color, uint8 hoffset, uint8 voffset) -> void { - uint14 patternLayout; +auto V9938::graphic2(n4& color, n8 hoffset, n8 voffset) -> void { + n14 patternLayout; patternLayout.bit( 0, 4) = hoffset.bit(3,7); patternLayout.bit( 5, 9) = voffset.bit(3,7); patternLayout.bit(10,13) = table.patternLayout.bit(10,13); - uint8 pattern = videoRAM.read(patternLayout); + n8 pattern = videoRAM.read(patternLayout); - uint14 patternGenerator; + n14 patternGenerator; patternGenerator.bit(0, 2) = voffset.bit(0,2); patternGenerator.bit(3,10) = pattern; if(voffset >= 64 && voffset <= 127) patternGenerator.bit(11) = table.patternGenerator.bit(11); if(voffset >= 128 && voffset <= 191) patternGenerator.bit(12) = table.patternGenerator.bit(12); - uint14 colorAddress = patternGenerator; + n14 colorAddress = patternGenerator; patternGenerator.bit(13) = table.patternGenerator.bit(13); colorAddress.bit(13) = table.color.bit(13); - uint8 colorMask = table.color.bit(6,12) << 1 | 1; - uint8 output = videoRAM.read(colorAddress); + n8 colorMask = table.color.bit(6,12) << 1 | 1; + n8 output = videoRAM.read(colorAddress); if(videoRAM.read(patternGenerator).bit(~hoffset & 7)) output >>= 4; color = output.bit(0,3); } diff --git a/ares/component/video/v9938/graphic3.cpp b/ares/component/video/v9938/graphic3.cpp index a8c84211bb..2c13be1941 100644 --- a/ares/component/video/v9938/graphic3.cpp +++ b/ares/component/video/v9938/graphic3.cpp @@ -1,5 +1,5 @@ //graphic mode 3 is identical to graphic mode 2: //the difference is only that mode 2 uses sprite mode 1, and mode 3 uses sprite mode 2 -auto V9938::graphic3(uint4& color, uint8 hoffset, uint8 voffset) -> void { +auto V9938::graphic3(n4& color, n8 hoffset, n8 voffset) -> void { return graphic2(color, hoffset, voffset); } diff --git a/ares/component/video/v9938/graphic4.cpp b/ares/component/video/v9938/graphic4.cpp index 05244bf591..4392168748 100644 --- a/ares/component/video/v9938/graphic4.cpp +++ b/ares/component/video/v9938/graphic4.cpp @@ -1,8 +1,8 @@ -auto V9938::graphic4(uint4& color, uint8 hoffset, uint8 voffset) -> void { - uint17 address = table.patternLayout & 0x18000; +auto V9938::graphic4(n4& color, n8 hoffset, n8 voffset) -> void { + n17 address = table.patternLayout & 0x18000; address += voffset << 7; address += hoffset >> 1; auto data = videoRAM.read(address); auto shift = !hoffset.bit(0) ? 4 : 0; - color = uint4(data >> shift); + color = n4(data >> shift); } diff --git a/ares/component/video/v9938/io.cpp b/ares/component/video/v9938/io.cpp index 1214e44ee3..5a39043354 100644 --- a/ares/component/video/v9938/io.cpp +++ b/ares/component/video/v9938/io.cpp @@ -1,6 +1,6 @@ -auto V9938::status() -> uint8 { +auto V9938::status() -> n8 { io.controlLatch = 0; - uint8 data; + n8 data; switch(io.statusIndex) { @@ -59,11 +59,11 @@ auto V9938::status() -> uint8 { return data; } -auto V9938::data() -> uint8 { +auto V9938::data() -> n8 { io.controlLatch = 0; - uint17 address = io.ramBank << 14 | io.controlValue.bit(0,13)++; + n17 address = io.ramBank << 14 | io.controlValue.bit(0,13)++; if(!io.controlValue.bit(0,13)) io.ramBank++; //unconfirmed - uint8 data = io.ramLatch; + n8 data = io.ramLatch; if(io.ramSelect == 0) { io.ramLatch = videoRAM.read(address); } else { @@ -74,9 +74,9 @@ auto V9938::data() -> uint8 { // -auto V9938::data(uint8 data) -> void { +auto V9938::data(n8 data) -> void { io.controlLatch = 0; - uint17 address = io.ramBank << 14 | io.controlValue.bit(0,13)++; + n17 address = io.ramBank << 14 | io.controlValue.bit(0,13)++; if(!io.controlValue.bit(0,13)) io.ramBank++; //unconfirmed if(io.ramSelect == 0) { videoRAM.write(address, data); @@ -85,7 +85,7 @@ auto V9938::data(uint8 data) -> void { } } -auto V9938::control(uint8 data) -> void { +auto V9938::control(n8 data) -> void { io.controlValue.byte(io.controlLatch++) = data; if(io.controlLatch) return; if(io.controlValue.bit(15)) { @@ -94,7 +94,7 @@ auto V9938::control(uint8 data) -> void { if(!io.controlValue.bit(14)) V9938::data(); //read-ahead } -auto V9938::palette(uint8 data) -> void { +auto V9938::palette(n8 data) -> void { io.paletteValue.byte(io.paletteLatch++) = data; if(io.paletteLatch) return; paletteRAM[io.paletteIndex].bit(0,2) = io.paletteValue.bit(0, 2); //B @@ -103,7 +103,7 @@ auto V9938::palette(uint8 data) -> void { io.paletteIndex++; } -auto V9938::register(uint8 data) -> void { +auto V9938::register(n8 data) -> void { //indirect register writes cannot change the indirect register index setting if(io.registerIndex != 0x11) register(io.registerIndex, data); if(!io.registerFixed) io.registerIndex++; @@ -111,7 +111,7 @@ auto V9938::register(uint8 data) -> void { // -auto V9938::register(uint6 register, uint8 data) -> void { +auto V9938::register(n6 register, n8 data) -> void { switch(register) { case 0x00: diff --git a/ares/component/video/v9938/sprite1.cpp b/ares/component/video/v9938/sprite1.cpp index 53a1f06395..57e7a38016 100644 --- a/ares/component/video/v9938/sprite1.cpp +++ b/ares/component/video/v9938/sprite1.cpp @@ -1,20 +1,20 @@ -auto V9938::sprite1(uint8 voffset) -> void { +auto V9938::sprite1(n8 voffset) -> void { sprite.collision = 0; sprite.overflow = 0; sprite.last = 0; - uint3 valid = 0; - uint5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; - for(uint index : range(4)) sprites[index].y = 0xd0; + n3 valid = 0; + n5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; + for(u32 index : range(4)) sprites[index].y = 0xd0; - uint14 address = table.spriteAttribute & 0x03f80; - for(uint index : range(32)) { - uint8 y = videoRAM.read(address++); + n14 address = table.spriteAttribute & 0x03f80; + for(u32 index : range(32)) { + n8 y = videoRAM.read(address++); if(y == 0xd0) break; - uint8 x = videoRAM.read(address++); - uint8 pattern = videoRAM.read(address++); - uint8 attributes = videoRAM.read(address++); + n8 x = videoRAM.read(address++); + n8 pattern = videoRAM.read(address++); + n8 attributes = videoRAM.read(address++); y += 1; if(voffset < y) continue; @@ -29,27 +29,27 @@ auto V9938::sprite1(uint8 voffset) -> void { break; } - uint4 color = attributes.bit(0,3); + n4 color = attributes.bit(0,3); if(attributes.bit(7)) x -= 32; sprites[valid++] = {x, y, pattern, color}; } } -auto V9938::sprite1(uint4& color, uint8 hoffset, uint8 voffset) -> void { - uint4 output; - uint5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; +auto V9938::sprite1(n4& color, n8 hoffset, n8 voffset) -> void { + n4 output; + n5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; - for(uint index : range(4)) { + for(u32 index : range(4)) { auto& o = sprites[index]; if(o.y == 0xd0) break; if(hoffset < o.x) continue; if(hoffset > o.x + sizeLimit) continue; - uint4 x = hoffset - o.x >> sprite.magnify; - uint4 y = voffset - o.y >> sprite.magnify; + n4 x = hoffset - o.x >> sprite.magnify; + n4 y = voffset - o.y >> sprite.magnify; - uint14 address = table.spritePatternGenerator; + n14 address = table.spritePatternGenerator; address += (o.pattern << 3) + (x >> 3 << 4) + y; if(videoRAM.read(address).bit(~x & 7)) { diff --git a/ares/component/video/v9938/sprite2.cpp b/ares/component/video/v9938/sprite2.cpp index 95818a8441..8c0ee217c6 100644 --- a/ares/component/video/v9938/sprite2.cpp +++ b/ares/component/video/v9938/sprite2.cpp @@ -1,22 +1,22 @@ -auto V9938::sprite2(uint8 voffset) -> void { +auto V9938::sprite2(n8 voffset) -> void { if(sprite.disable) return; sprite.collision = 0; sprite.overflow = 0; sprite.last = 0; - uint4 valid = 0; - uint5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; - for(uint index : range(8)) sprites[index].y = 0xd8; + n4 valid = 0; + n5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; + for(u32 index : range(8)) sprites[index].y = 0xd8; - uint17 address = table.spriteAttribute & 0x1fe00; - for(uint index : range(32)) { - uint8 y = videoRAM.read(address++); + n17 address = table.spriteAttribute & 0x1fe00; + for(u32 index : range(32)) { + n8 y = videoRAM.read(address++); if(y == 0xd8) break; - uint8 x = videoRAM.read(address++); - uint8 pattern = videoRAM.read(address++); - uint8 reserved = videoRAM.read(address++); + n8 x = videoRAM.read(address++); + n8 pattern = videoRAM.read(address++); + n8 reserved = videoRAM.read(address++); y += 1; if(voffset < y) continue; @@ -31,36 +31,36 @@ auto V9938::sprite2(uint8 voffset) -> void { break; } - uint17 colorTable = table.spriteAttribute & 0x1fc00; + n17 colorTable = table.spriteAttribute & 0x1fc00; colorTable += index << 4; colorTable += voffset - y; - uint8 attributes = videoRAM.read(colorTable); - uint4 color = attributes.bit(0,3); - uint1 collision = attributes.bit(5); - uint1 priority = attributes.bit(6); + n8 attributes = videoRAM.read(colorTable); + n4 color = attributes.bit(0,3); + n1 collision = attributes.bit(5); + n1 priority = attributes.bit(6); if(attributes.bit(7)) x -= 32; sprites[valid++] = {x, y, pattern, color, collision, priority}; } } -auto V9938::sprite2(uint4& color, uint8 hoffset, uint8 voffset) -> void { +auto V9938::sprite2(n4& color, n8 hoffset, n8 voffset) -> void { if(sprite.disable) return; - uint4 output; - uint5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; + n4 output; + n5 sizeLimit = (8 << sprite.size << sprite.magnify) - 1; - for(uint index : range(8)) { + for(u32 index : range(8)) { auto& o = sprites[index]; if(o.y == 0xd8) break; if(hoffset < o.x) continue; if(hoffset > o.x + sizeLimit) continue; - uint4 x = hoffset - o.x >> sprite.magnify; - uint4 y = voffset - o.y >> sprite.magnify; + n4 x = hoffset - o.x >> sprite.magnify; + n4 y = voffset - o.y >> sprite.magnify; - uint17 address = table.spritePatternGenerator; + n17 address = table.spritePatternGenerator; address += (o.pattern << 3) + (x >> 3 << 4) + y; if(videoRAM.read(address).bit(~x & 7)) { diff --git a/ares/component/video/v9938/v9938.cpp b/ares/component/video/v9938/v9938.cpp index 4878e2e742..07c147d161 100644 --- a/ares/component/video/v9938/v9938.cpp +++ b/ares/component/video/v9938/v9938.cpp @@ -23,8 +23,8 @@ auto V9938::unload() -> void { auto V9938::main() -> void { if(io.vcounter < vlines()) { - uint9 y = io.vcounter; - uint9 ycenter = y + (!overscan() ? 10 : 0); //centers output within buffer + n9 y = io.vcounter; + n9 ycenter = y + (!overscan() ? 10 : 0); //centers output within buffer auto line = screen_->pixels().data() + ycenter * 1024; if(interlace() && field()) line += 512; @@ -32,8 +32,8 @@ auto V9938::main() -> void { if(s2()) sprite2(y); while(io.hcounter < 256) { - uint9 x = io.hcounter; - uint4 color; + n9 x = io.hcounter; + n4 color; if(screen.enable) { color = io.colorBackground; if(g1()) graphic1(color, x, y); @@ -71,7 +71,7 @@ auto V9938::poll() -> void { irq(virq.pending || hirq.pending || lirq.pending); } -auto V9938::tick(uint clocks) -> void { +auto V9938::tick(u32 clocks) -> void { io.hcounter += clocks; while(clocks--) { command(); diff --git a/ares/component/video/v9938/v9938.hpp b/ares/component/video/v9938/v9938.hpp index 343f6b678e..6ddc06bd26 100644 --- a/ares/component/video/v9938/v9938.hpp +++ b/ares/component/video/v9938/v9938.hpp @@ -7,7 +7,7 @@ namespace ares { struct V9938 { Node::Video::Screen screen_; - virtual auto step(uint clocks) -> void = 0; + virtual auto step(u32 clocks) -> void = 0; virtual auto irq(bool line) -> void = 0; virtual auto frame() -> void = 0; @@ -16,8 +16,8 @@ struct V9938 { auto interlace() const -> bool { return latch.interlace; } auto field() const -> bool { return latch.field; } - auto vtotal() const -> uint { return !latch.timing ? 262 : 313; } - auto vlines() const -> uint { return !latch.overscan ? 192 : 212; } + auto vtotal() const -> u32 { return !latch.timing ? 262 : 313; } + auto vlines() const -> u32 { return !latch.overscan ? 192 : 212; } auto t1() const -> bool { return screen.mode == 0b00001; } auto t2() const -> bool { return screen.mode == 0b01001; } @@ -39,29 +39,29 @@ struct V9938 { auto main() -> void; auto poll() -> void; - auto tick(uint clocks) -> void; + auto tick(u32 clocks) -> void; auto power() -> void; //io.cpp - auto status() -> uint8; - auto data() -> uint8; + auto status() -> n8; + auto data() -> n8; - auto data(uint8 data) -> void; - auto control(uint8 data) -> void; - auto palette(uint8 data) -> void; - auto register(uint8 data) -> void; + auto data(n8 data) -> void; + auto control(n8 data) -> void; + auto palette(n8 data) -> void; + auto register(n8 data) -> void; - auto register(uint6 register, uint8 data) -> void; + auto register(n6 register, n8 data) -> void; //commands.cpp - auto command(uint8 data) -> void; + auto command(n8 data) -> void; auto command() -> void; auto relatch() -> void; auto advance() -> bool; - auto address(uint9 x, uint10 y) -> uint17; - auto read(uint1 source, uint9 x, uint10 y) -> uint8; - auto write(uint1 source, uint9 x, uint10 y, uint8 data) -> void; - auto logic(uint8 dc, uint8 sc) -> uint8; + auto address(n9 x, n10 y) -> n17; + auto read(n1 source, n9 x, n10 y) -> n8; + auto write(n1 source, n9 x, n10 y, n8 data) -> void; + auto logic(n8 dc, n8 sc) -> n8; auto point() -> void; auto pset() -> void; auto srch() -> void; @@ -76,161 +76,161 @@ struct V9938 { auto hmmc() -> void; //graphic1.cpp - auto graphic1(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto graphic1(n4& color, n8 hoffset, n8 voffset) -> void; //graphic2.cpp - auto graphic2(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto graphic2(n4& color, n8 hoffset, n8 voffset) -> void; //graphic3.cpp - auto graphic3(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto graphic3(n4& color, n8 hoffset, n8 voffset) -> void; //graphic4.cpp - auto graphic4(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto graphic4(n4& color, n8 hoffset, n8 voffset) -> void; //sprite1.cpp - auto sprite1(uint8 voffset) -> void; - auto sprite1(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto sprite1(n8 voffset) -> void; + auto sprite1(n4& color, n8 hoffset, n8 voffset) -> void; //sprite2.cpp - auto sprite2(uint8 voffset) -> void; - auto sprite2(uint4& color, uint8 hoffset, uint8 voffset) -> void; + auto sprite2(n8 voffset) -> void; + auto sprite2(n4& color, n8 hoffset, n8 voffset) -> void; //serialization.cpp auto serialize(serializer&) -> void; protected: - Memory::Writable videoRAM; - Memory::Writable expansionRAM; - uint9 paletteRAM[16]; + Memory::Writable videoRAM; + Memory::Writable expansionRAM; + n9 paletteRAM[16]; struct VerticalScanIRQ { - uint1 enable; - uint1 pending; + n1 enable; + n1 pending; } virq; struct HorizontalScanIRQ { - uint1 enable; - uint1 pending; - uint8 coincidence; + n1 enable; + n1 pending; + n8 coincidence; } hirq; struct LightPenIRQ { - uint1 enable; - uint1 pending; + n1 enable; + n1 pending; } lirq; struct Latch { - uint1 timing; - uint1 overscan; - uint1 interlace; - uint1 field; + n1 timing; + n1 overscan; + n1 interlace; + n1 field; } latch; struct Screen { - uint1 enable; - uint1 digitize; //unemulated - uint1 grayscale; //unemulated - uint5 mode; - uint1 interlace; - uint1 overscan; //0 = 192, 1 = 212 - uint1 timing; //0 = 262, 1 = 313 - int4 hadjust; - int4 vadjust; - uint8 vscroll; + n1 enable; + n1 digitize; //unemulated + n1 grayscale; //unemulated + n5 mode; + n1 interlace; + n1 overscan; //0 = 192, 1 = 212 + n1 timing; //0 = 262, 1 = 313 + i4 hadjust; + i4 vadjust; + n8 vscroll; } screen; struct Table { - uint17 patternLayout; - uint17 patternGenerator; - uint17 spriteAttribute; - uint17 spritePatternGenerator; - uint17 color; + n17 patternLayout; + n17 patternGenerator; + n17 spriteAttribute; + n17 spritePatternGenerator; + n17 color; } table; struct SpriteIO { - uint1 magnify; - uint1 size; //0 = 8x8, 1 = 16x16 - uint1 disable; + n1 magnify; + n1 size; //0 = 8x8, 1 = 16x16 + n1 disable; - uint1 collision; - uint1 overflow; - uint5 last; + n1 collision; + n1 overflow; + n5 last; } sprite; struct SpriteObject { - uint8 x; - uint8 y; - uint8 pattern; - uint4 color; - uint1 collision; - uint1 priority; + n8 x; + n8 y; + n8 pattern; + n4 color; + n1 collision; + n1 priority; } sprites[8]; struct IO { - uint16 vcounter; - uint16 hcounter; + n16 vcounter; + n16 hcounter; - uint1 controlLatch; - uint16 controlValue; + n1 controlLatch; + n16 controlValue; - uint4 colorBackground; - uint4 colorForeground; + n4 colorBackground; + n4 colorForeground; - uint4 blinkColorBackground; - uint4 blinkColorForeground; + n4 blinkColorBackground; + n4 blinkColorForeground; - uint4 blinkPeriodBackground; - uint4 blinkPeriodForeground; + n4 blinkPeriodBackground; + n4 blinkPeriodForeground; - uint4 statusIndex; + n4 statusIndex; - uint4 paletteIndex; - uint1 paletteLatch; - uint16 paletteValue; + n4 paletteIndex; + n1 paletteLatch; + n16 paletteValue; - uint6 registerIndex; - uint1 registerFixed; //0 = auto-increment + n6 registerIndex; + n1 registerFixed; //0 = auto-increment - uint1 ramSelect; //0 = video RAM, 1 = expansion RAM - uint3 ramBank; - uint8 ramLatch; + n1 ramSelect; //0 = video RAM, 1 = expansion RAM + n3 ramBank; + n8 ramLatch; } io; struct Operation { //a very rough, inaccurate approximation of command timing - uint32 counter; + n32 counter; - uint1 executing; - uint1 ready; - uint4 command; + n1 executing; + n1 ready; + n4 command; - uint1 mxs; - uint9 sx; - uint10 sy; + n1 mxs; + n9 sx; + n10 sy; - uint1 mxd; - uint9 dx; - uint10 dy; + n1 mxd; + n9 dx; + n10 dy; - uint9 nx; - uint10 ny; + n9 nx; + n10 ny; - uint1 dix; //0 = right, 1 = left - uint1 diy; //0 = down, 1 = up + n1 dix; //0 = right, 1 = left + n1 diy; //0 = down, 1 = up - uint8 cr; - uint9 match; - uint1 found; - uint1 eq; - uint1 maj; + n8 cr; + n9 match; + n1 found; + n1 eq; + n1 maj; - uint4 logic; + n4 logic; //internal latches - uint3 lgm; - uint9 lsx; - uint9 ldx; - uint9 lnx; + n3 lgm; + n9 lsx; + n9 ldx; + n9 lnx; } op; }; diff --git a/ares/cv/cartridge/cartridge.hpp b/ares/cv/cartridge/cartridge.hpp index f3fcf1bccb..235e383e6c 100644 --- a/ares/cv/cartridge/cartridge.hpp +++ b/ares/cv/cartridge/cartridge.hpp @@ -23,7 +23,7 @@ struct Cartridge { string region; } information; - Memory::Readable rom; + Memory::Readable rom; }; #include "slot.hpp" diff --git a/ares/cv/controller/controller.hpp b/ares/cv/controller/controller.hpp index 0989c9c28f..71b70bae2f 100644 --- a/ares/cv/controller/controller.hpp +++ b/ares/cv/controller/controller.hpp @@ -3,8 +3,8 @@ struct Controller : Thread { virtual ~Controller() = default; - virtual auto read() -> uint8 { return 0xff; } - virtual auto write(uint8 data) -> void {} + virtual auto read() -> n8 { return 0xff; } + virtual auto write(n8 data) -> void {} }; #include "port.hpp" diff --git a/ares/cv/controller/gamepad/gamepad.cpp b/ares/cv/controller/gamepad/gamepad.cpp index 6e1ec00fd3..89243ead63 100644 --- a/ares/cv/controller/gamepad/gamepad.cpp +++ b/ares/cv/controller/gamepad/gamepad.cpp @@ -21,7 +21,7 @@ Gamepad::Gamepad(Node::Port parent) { pound = node->append("#"); } -auto Gamepad::read() -> uint8 { +auto Gamepad::read() -> n8 { platform->input(up); platform->input(down); platform->input(left); @@ -53,7 +53,7 @@ auto Gamepad::read() -> uint8 { xHold = 1, swap(leftLatch, rightLatch); } - uint8 data = 0xff; + n8 data = 0xff; if(select == 0) { if(one->value ()) data.bit(0,3) = 0b1101; else if(two->value ()) data.bit(0,3) = 0b0111; @@ -78,6 +78,6 @@ auto Gamepad::read() -> uint8 { return data; } -auto Gamepad::write(uint8 data) -> void { +auto Gamepad::write(n8 data) -> void { select = data.bit(0); } diff --git a/ares/cv/controller/gamepad/gamepad.hpp b/ares/cv/controller/gamepad/gamepad.hpp index 5565751ee1..3e1d7114ce 100644 --- a/ares/cv/controller/gamepad/gamepad.hpp +++ b/ares/cv/controller/gamepad/gamepad.hpp @@ -20,16 +20,16 @@ struct Gamepad : Controller { Gamepad(Node::Port); - auto read() -> uint8 override; - auto write(uint8 data) -> void override; + auto read() -> n8 override; + auto write(n8 data) -> void override; - uint1 select; + n1 select; private: - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/cv/controller/port.hpp b/ares/cv/controller/port.hpp index 95f7b22225..808004bcee 100644 --- a/ares/cv/controller/port.hpp +++ b/ares/cv/controller/port.hpp @@ -8,8 +8,8 @@ struct ControllerPort { auto unload() -> void; auto allocate(string name) -> Node::Peripheral; - auto read() -> uint8 { if(device) return device->read(); return 0xff; } - auto write(uint8 data) -> void { if(device) return device->write(data); } + auto read() -> n8 { if(device) return device->read(); return 0xff; } + auto write(n8 data) -> void { if(device) return device->write(data); } auto serialize(serializer&) -> void; diff --git a/ares/cv/cpu/cpu.hpp b/ares/cv/cpu/cpu.hpp index 48983082b2..03d4e88ca6 100644 --- a/ares/cv/cpu/cpu.hpp +++ b/ares/cv/cpu/cpu.hpp @@ -1,7 +1,7 @@ struct CPU : Z80, Z80::Bus, Thread { Node::Object node; - Memory::Writable ram; - Memory::Writable expansion; + Memory::Writable ram; + Memory::Writable expansion; struct Debugger { //debugger.cpp @@ -27,7 +27,7 @@ struct CPU : Z80, Z80::Bus, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto setNMI(bool value) -> void; auto setIRQ(bool value) -> void; @@ -35,14 +35,14 @@ struct CPU : Z80, Z80::Bus, Thread { auto power() -> void; //memory.cpp - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto in(uint16 address) -> uint8 override; - auto out(uint16 address, uint8 data) -> void override; + auto in(n16 address) -> n8 override; + auto out(n16 address, n8 data) -> void override; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; private: struct State { diff --git a/ares/cv/cpu/memory.cpp b/ares/cv/cpu/memory.cpp index 73b8fe05e8..b48a3ab70e 100644 --- a/ares/cv/cpu/memory.cpp +++ b/ares/cv/cpu/memory.cpp @@ -1,5 +1,5 @@ -auto CPU::read(uint16 address) -> uint8 { - uint8 data = 0xff; +auto CPU::read(n16 address) -> n8 { + n8 data = 0xff; if(address >= 0x0000 && address <= 0x1fff && io.replaceBIOS) return expansion.read(address); if(address >= 0x2000 && address <= 0x7fff && io.replaceRAM ) return expansion.read(address); if(address >= 0x0000 && address <= 0x1fff) return system.bios[address & 0x1fff]; @@ -8,23 +8,23 @@ auto CPU::read(uint16 address) -> uint8 { return data; } -auto CPU::write(uint16 address, uint8 data) -> void { +auto CPU::write(n16 address, n8 data) -> void { if(address >= 0x0000 && address <= 0x1fff && io.replaceBIOS) return expansion.write(address, data); if(address >= 0x2000 && address <= 0x7fff && io.replaceRAM) return expansion.write(address, data); if(address >= 0x6000 && address <= 0x7fff) return ram.write(address - 0x6000, data); if(address >= 0x8000 && address <= 0xffff) return; } -auto CPU::in(uint16 address) -> uint8 { +auto CPU::in(n16 address) -> n8 { address &= 0xff; - uint8 data = 0xff; + n8 data = 0xff; if(address >= 0xa0 && address <= 0xbf) return !address.bit(0) ? vdp.data() : vdp.status(); if(address >= 0xe0 && address <= 0xff && address.bit(1) == 0) return controllerPort1.read(); if(address >= 0xe0 && address <= 0xff && address.bit(1) == 1) return controllerPort2.read(); return data; } -auto CPU::out(uint16 address, uint8 data) -> void { +auto CPU::out(n16 address, n8 data) -> void { address &= 0xff; if(address == 0x53) io.replaceRAM = data.bit(0); if(address == 0x7f) io.replaceBIOS = data.bit(1); diff --git a/ares/cv/cv.hpp b/ares/cv/cv.hpp index 1e19b3cb84..9aecf54416 100644 --- a/ares/cv/cv.hpp +++ b/ares/cv/cv.hpp @@ -9,6 +9,7 @@ namespace ares::ColecoVision { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { diff --git a/ares/cv/psg/psg.cpp b/ares/cv/psg/psg.cpp index 886ce7b3ea..72ca1abdac 100644 --- a/ares/cv/psg/psg.cpp +++ b/ares/cv/psg/psg.cpp @@ -30,7 +30,7 @@ auto PSG::main() -> void { step(1); } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -39,7 +39,7 @@ auto PSG::power() -> void { SN76489::power(); Thread::create(system.colorburst() / 16.0, {&PSG::main, this}); - for(uint level : range(15)) { + for(u32 level : range(15)) { volume[level] = pow(2, level * -2.0 / 6.0); } volume[15] = 0; diff --git a/ares/cv/psg/psg.hpp b/ares/cv/psg/psg.hpp index 3d7b6e995a..ff29a18ac0 100644 --- a/ares/cv/psg/psg.hpp +++ b/ares/cv/psg/psg.hpp @@ -7,14 +7,14 @@ struct PSG : SN76489, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; private: - double volume[16]; + f64 volume[16]; }; extern PSG psg; diff --git a/ares/cv/system/serialization.cpp b/ares/cv/system/serialization.cpp index ed8ceeb25c..47586f0c73 100644 --- a/ares/cv/system/serialization.cpp +++ b/ares/cv/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/cv/system/system.cpp b/ares/cv/system/system.cpp index 6966d2f0f5..062b1f83f9 100644 --- a/ares/cv/system/system.cpp +++ b/ares/cv/system/system.cpp @@ -2,7 +2,17 @@ namespace ares::ColecoVision { +auto enumerate() -> vector { + return { + "[Coleco] ColecoVision (NTSC)", + "[Coleco] ColecoVision (PAL)", + "[Coleco] ColecoAdam (NTSC)", + "[Coleco] ColecoAdam (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -28,10 +38,24 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "ColecoVision") information.model = Model::ColecoVision; - if(name == "ColecoAdam" ) information.model = Model::ColecoAdam; + if(name.find("ColecoVision")) { + information.name = "ColecoVision"; + information.model = Model::ColecoVision; + } + if(name.find("ColecoAdam")) { + information.name = "ColecoAdam"; + information.model = Model::ColecoAdam; + } + if(name.find("NTSC")) { + information.region = Region::NTSC; + information.colorburst = Constants::Colorburst::NTSC; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -41,14 +65,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC → PAL"); - regionNode->setAllowedValues({ - "NTSC → PAL", - "PAL → NTSC", - "NTSC", - "PAL" - }); - scheduler.reset(); controls.load(node); cpu.load(node); @@ -80,22 +96,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC") { - information.region = Region::NTSC; - information.colorburst = Constants::Colorburst::NTSC; - } - if(region == "PAL") { - information.region = Region::PAL; - information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; - } - }; - auto regions = regionNode->latch().split("→").strip(); - setRegion(regions.first()); - for(auto& requested : reverse(regions)) { - if(requested == cartridge.region()) setRegion(requested); - } - if(auto fp = platform->open(node, "bios.rom", File::Read, File::Required)) { fp->read(bios, 0x2000); } diff --git a/ares/cv/system/system.hpp b/ares/cv/system/system.hpp index 1e0f81613b..38726e715d 100644 --- a/ares/cv/system/system.hpp +++ b/ares/cv/system/system.hpp @@ -1,6 +1,5 @@ struct System { Node::System node; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -11,13 +10,13 @@ struct System { auto poll() -> void; } controls; - enum class Model : uint { ColecoVision, ColecoAdam }; - enum class Region : uint { NTSC, PAL }; + enum class Model : u32 { ColecoVision, ColecoAdam }; + enum class Region : u32 { NTSC, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto region() const -> Region { return information.region; } - auto colorburst() const -> double { return information.colorburst; } + auto colorburst() const -> f64 { return information.colorburst; } //system.cpp auto game() -> string; @@ -32,13 +31,14 @@ struct System { auto serialize(bool synchronize) -> serializer; auto unserialize(serializer&) -> bool; - uint8 bios[0x2000]; + u8 bios[0x2000]; private: struct Information { + string name = "ColecoVision"; Model model = Model::ColecoVision; Region region = Region::NTSC; - double colorburst = Constants::Colorburst::NTSC; + f64 colorburst = Constants::Colorburst::NTSC; } information; //serialization.cpp diff --git a/ares/cv/vdp/color.cpp b/ares/cv/vdp/color.cpp index a4baba508e..53f3dd7ccf 100644 --- a/ares/cv/vdp/color.cpp +++ b/ares/cv/vdp/color.cpp @@ -1,4 +1,4 @@ -auto VDP::color(uint32 color) -> uint64 { +auto VDP::color(n32 color) -> n64 { switch(color.bit(0,3)) { case 0: return 0x0000'0000'0000ull; //transparent case 1: return 0x0000'0000'0000ull; //black diff --git a/ares/cv/vdp/vdp.cpp b/ares/cv/vdp/vdp.cpp index babdae7ea2..312b8c3628 100644 --- a/ares/cv/vdp/vdp.cpp +++ b/ares/cv/vdp/vdp.cpp @@ -26,7 +26,7 @@ auto VDP::unload() -> void { node.reset(); } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } diff --git a/ares/cv/vdp/vdp.hpp b/ares/cv/vdp/vdp.hpp index 7af96b8cea..af5a7e4321 100644 --- a/ares/cv/vdp/vdp.hpp +++ b/ares/cv/vdp/vdp.hpp @@ -6,13 +6,13 @@ struct VDP : TMS9918, Thread { auto load(Node::Object) -> void; auto unload() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto irq(bool line) -> void override; auto frame() -> void override; auto power() -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/fc/apu/apu.hpp b/ares/fc/apu/apu.hpp index 28710d5ea2..ed3c6ed8ba 100644 --- a/ares/fc/apu/apu.hpp +++ b/ares/fc/apu/apu.hpp @@ -28,12 +28,12 @@ struct APU : Thread { //serialization.cpp auto serialize(serializer&) -> void; - n04 speed; - n01 useSpeedAsVolume; - n01 loopMode; - n01 reloadDecay; - n08 decayCounter; - n04 decayVolume; + n4 speed; + n1 useSpeedAsVolume; + n1 loopMode; + n1 reloadDecay; + n8 decayCounter; + n4 decayVolume; }; struct Sweep { @@ -44,12 +44,12 @@ struct APU : Thread { //serialization.cpp auto serialize(serializer&) -> void; - n08 shift; - n01 decrement; - n03 period; - n08 counter; - n01 enable; - n01 reload; + n8 shift; + n1 decrement; + n3 period; + n8 counter; + n1 enable; + n1 reload; n11 pulsePeriod; }; @@ -67,8 +67,8 @@ struct APU : Thread { n16 lengthCounter; n16 periodCounter; - n02 duty; - n03 dutyCounter; + n2 duty; + n3 dutyCounter; n11 period; } pulse1, pulse2; @@ -83,12 +83,12 @@ struct APU : Thread { n16 lengthCounter; n16 periodCounter; - n08 linearLength; - n01 haltLengthCounter; + n8 linearLength; + n1 haltLengthCounter; n11 period; - n05 stepCounter; - n08 linearLengthCounter; - n01 reloadLinear; + n5 stepCounter; + n8 linearLengthCounter; + n1 reloadLinear; } triangle; struct Noise { @@ -103,8 +103,8 @@ struct APU : Thread { n16 lengthCounter; n16 periodCounter; - n04 period; - n01 shortMode; + n4 period; + n1 shortMode; n15 lfsr; } noise; @@ -120,19 +120,19 @@ struct APU : Thread { n16 lengthCounter; n16 periodCounter; n16 dmaDelayCounter; - n01 irqPending; - n04 period; - n01 irqEnable; - n01 loopMode; - n08 dacLatch; - n08 addressLatch; - n08 lengthLatch; + n1 irqPending; + n4 period; + n1 irqEnable; + n1 loopMode; + n8 dacLatch; + n8 addressLatch; + n8 lengthLatch; n15 readAddress; - n03 bitCounter; - n01 dmaBufferValid; - n08 dmaBuffer; - n01 sampleValid; - n08 sample; + n3 bitCounter; + n1 dmaBufferValid; + n8 dmaBuffer; + n1 sampleValid; + n8 sample; } dmc; struct FrameCounter { @@ -141,9 +141,9 @@ struct APU : Thread { //serialization.cpp auto serialize(serializer&) -> void; - n01 irqPending; - n02 mode; - n02 counter; + n1 irqPending; + n2 mode; + n2 counter; i32 divider; } frame; @@ -151,13 +151,13 @@ struct APU : Thread { auto clockFrameCounter() -> void; auto clockFrameCounterDivider() -> void; - n05 enabledChannels; + n5 enabledChannels; //unserialized: i16 pulseDAC[32]; i16 dmcTriangleNoiseDAC[128][16][16]; - static const n08 lengthCounterTable[32]; + static const n8 lengthCounterTable[32]; static const n16 dmcPeriodTableNTSC[16]; static const n16 dmcPeriodTablePAL[16]; static const n16 noisePeriodTableNTSC[16]; diff --git a/ares/fc/cartridge/board/bandai-fcg.cpp b/ares/fc/cartridge/board/bandai-fcg.cpp index 22e6ab6b54..7f45cffedd 100644 --- a/ares/fc/cartridge/board/bandai-fcg.cpp +++ b/ares/fc/cartridge/board/bandai-fcg.cpp @@ -110,11 +110,11 @@ struct BandaiFCG : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { eeprom.reset(); } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(eeprom); s(characterBank); @@ -125,10 +125,10 @@ struct BandaiFCG : Interface { s(irqLatch); } - n08 characterBank[8]; - n04 programBank; - n02 mirror; - n01 irqCounterEnable; + n8 characterBank[8]; + n4 programBank; + n2 mirror; + n1 irqCounterEnable; n16 irqCounter; n16 irqLatch; }; diff --git a/ares/fc/cartridge/board/hvc-axrom.cpp b/ares/fc/cartridge/board/hvc-axrom.cpp index 0b4cf33159..dd194d6ca8 100644 --- a/ares/fc/cartridge/board/hvc-axrom.cpp +++ b/ares/fc/cartridge/board/hvc-axrom.cpp @@ -55,11 +55,11 @@ struct HVC_AxROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { programBank = 0x0f; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(programBank); s(mirror); diff --git a/ares/fc/cartridge/board/hvc-bnrom.cpp b/ares/fc/cartridge/board/hvc-bnrom.cpp index ffa94151f3..b71d26c66d 100644 --- a/ares/fc/cartridge/board/hvc-bnrom.cpp +++ b/ares/fc/cartridge/board/hvc-bnrom.cpp @@ -49,10 +49,10 @@ struct HVC_BNROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(mirror); s(programBank); diff --git a/ares/fc/cartridge/board/hvc-cnrom.cpp b/ares/fc/cartridge/board/hvc-cnrom.cpp index 1ff67948aa..896f271f94 100644 --- a/ares/fc/cartridge/board/hvc-cnrom.cpp +++ b/ares/fc/cartridge/board/hvc-cnrom.cpp @@ -51,10 +51,10 @@ struct HVC_CNROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(mirror); s(characterBank); diff --git a/ares/fc/cartridge/board/hvc-exrom.cpp b/ares/fc/cartridge/board/hvc-exrom.cpp index 0e32fff599..e55c195412 100644 --- a/ares/fc/cartridge/board/hvc-exrom.cpp +++ b/ares/fc/cartridge/board/hvc-exrom.cpp @@ -101,8 +101,8 @@ struct HVC_ExROM : Interface { //MMC5 Envelope envelope; n16 lengthCounter; n16 periodCounter; - n02 duty; - n03 dutyCounter; + n2 duty; + n3 dutyCounter; n11 period; }; @@ -694,13 +694,13 @@ struct HVC_ExROM : Interface { //MMC5 } } - auto power() -> void { + auto power() -> void override { for(auto& byte : exram) byte = 0xff; programMode = 3; programBank[3] = 0xff; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(exram); s(pulse1); @@ -756,54 +756,54 @@ struct HVC_ExROM : Interface { //MMC5 Pin cl3; //$5207-5208 Pin sl3; //$5207-5208 - n02 programMode; //$5100 - n02 characterMode; //$5101 + n2 programMode; //$5100 + n2 characterMode; //$5101 - n02 ramWriteProtect[2]; //$5102-$5103 + n2 ramWriteProtect[2]; //$5102-$5103 - n02 exramMode; //$5104 - n02 nametableMode[4]; //$5105 - n08 fillmodeTile; //$5106 - n08 fillmodeColor; //$5107 + n2 exramMode; //$5104 + n2 nametableMode[4]; //$5105 + n8 fillmodeTile; //$5106 + n8 fillmodeColor; //$5107 - n01 ramSelect; //$5113 - n02 ramBank; //$5113 - n08 programBank[4]; //$5114-5117 + n1 ramSelect; //$5113 + n2 ramBank; //$5113 + n8 programBank[4]; //$5114-5117 n10 characterSpriteBank[8]; //$5120-5127 n10 characterBackgroundBank[4]; //$5128-512b - n02 characterBankHi; //$5130 + n2 characterBankHi; //$5130 - n01 vsplitEnable; //$5200 - n01 vsplitSide; //$5200 - n05 vsplitTile; //$5200 - n08 vsplitScroll; //$5201 - n08 vsplitBank; //$5202 + n1 vsplitEnable; //$5200 + n1 vsplitSide; //$5200 + n5 vsplitTile; //$5200 + n8 vsplitScroll; //$5201 + n8 vsplitBank; //$5202 - n08 irqCoincidence; //$5203 - n01 irqEnable; //$5204 + n8 irqCoincidence; //$5203 + n1 irqEnable; //$5204 - n08 multiplicand; //$5205 - n08 multiplier; //$5206 + n8 multiplicand; //$5205 + n8 multiplier; //$5206 n16 timerCounter; //$5209-520a - n01 timerLine; + n1 timerLine; //status registers - n08 cycleCounter; - n01 irqLine; - n01 inFrame; + n8 cycleCounter; + n1 irqLine; + n1 inFrame; n16 vcounter; n16 hcounter; n16 characterAccess[4]; - n01 characterActive; - n01 sprite8x16; + n1 characterActive; + n1 sprite8x16; - n08 exbank; - n08 exattr; + n8 exbank; + n8 exattr; - n01 vsplitFetch; - n08 vsplitVoffset; - n08 vsplitHoffset; + n1 vsplitFetch; + n8 vsplitVoffset; + n8 vsplitHoffset; }; diff --git a/ares/fc/cartridge/board/hvc-fmr.cpp b/ares/fc/cartridge/board/hvc-fmr.cpp index 3aef4ebc22..5e2294d00d 100644 --- a/ares/fc/cartridge/board/hvc-fmr.cpp +++ b/ares/fc/cartridge/board/hvc-fmr.cpp @@ -57,11 +57,11 @@ struct HVC_FMR : Interface { return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { fds.power(); } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(fds); s(programRAM); s(characterRAM); diff --git a/ares/fc/cartridge/board/hvc-fxrom.cpp b/ares/fc/cartridge/board/hvc-fxrom.cpp index ae18edd070..3708d63aac 100644 --- a/ares/fc/cartridge/board/hvc-fxrom.cpp +++ b/ares/fc/cartridge/board/hvc-fxrom.cpp @@ -78,10 +78,10 @@ struct HVC_FxROM : Interface { //MMC4 if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(programBank); diff --git a/ares/fc/cartridge/board/hvc-gxrom.cpp b/ares/fc/cartridge/board/hvc-gxrom.cpp index 51a3836466..15acf3a12b 100644 --- a/ares/fc/cartridge/board/hvc-gxrom.cpp +++ b/ares/fc/cartridge/board/hvc-gxrom.cpp @@ -60,10 +60,10 @@ struct HVC_GxROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(mirror); s(programBank); diff --git a/ares/fc/cartridge/board/hvc-hkrom.cpp b/ares/fc/cartridge/board/hvc-hkrom.cpp index 0fcbf33a2b..13da8fca0d 100644 --- a/ares/fc/cartridge/board/hvc-hkrom.cpp +++ b/ares/fc/cartridge/board/hvc-hkrom.cpp @@ -23,7 +23,7 @@ struct HVC_HKROM : Interface { //MMC6 Interface::save(characterRAM, board["memory(type=RAM,content=Character)"]); } - auto main() -> void { + auto main() -> void override { if(irqDelay) irqDelay--; cpu.irqLine(irqLine); tick(); @@ -161,10 +161,10 @@ struct HVC_HKROM : Interface { //MMC6 if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(characterMode); @@ -184,19 +184,19 @@ struct HVC_HKROM : Interface { //MMC6 s(characterAddress); } - n01 characterMode; - n01 programMode; - n01 ramEnable; - n03 bankSelect; - n06 programBank[2]; - n08 characterBank[6]; - n01 mirror; - n01 ramReadable[2]; - n01 ramWritable[2]; - n08 irqLatch; - n08 irqCounter; - n01 irqEnable; - n01 irqDelay; - n01 irqLine; + n1 characterMode; + n1 programMode; + n1 ramEnable; + n3 bankSelect; + n6 programBank[2]; + n8 characterBank[6]; + n1 mirror; + n1 ramReadable[2]; + n1 ramWritable[2]; + n8 irqLatch; + n8 irqCounter; + n1 irqEnable; + n1 irqDelay; + n1 irqLine; n16 characterAddress; }; diff --git a/ares/fc/cartridge/board/hvc-nrom.cpp b/ares/fc/cartridge/board/hvc-nrom.cpp index 7f34ef36df..d840c8d979 100644 --- a/ares/fc/cartridge/board/hvc-nrom.cpp +++ b/ares/fc/cartridge/board/hvc-nrom.cpp @@ -57,10 +57,10 @@ struct HVC_NROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(mirror); } diff --git a/ares/fc/cartridge/board/hvc-pxrom.cpp b/ares/fc/cartridge/board/hvc-pxrom.cpp index 93f3377811..59e00720ad 100644 --- a/ares/fc/cartridge/board/hvc-pxrom.cpp +++ b/ares/fc/cartridge/board/hvc-pxrom.cpp @@ -86,10 +86,10 @@ struct HVC_PxROM : Interface { //MMC2 if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(programBank); diff --git a/ares/fc/cartridge/board/hvc-sxrom.cpp b/ares/fc/cartridge/board/hvc-sxrom.cpp index 7922105f6b..ef32c6e407 100644 --- a/ares/fc/cartridge/board/hvc-sxrom.cpp +++ b/ares/fc/cartridge/board/hvc-sxrom.cpp @@ -84,7 +84,7 @@ struct HVC_SxROM : Interface { //MMC1 Interface::save(characterRAM, board["memory(type=RAM,content=Character)"]); } - auto main() -> void { + auto main() -> void override { if(writeDelay) writeDelay--; tick(); } @@ -201,13 +201,13 @@ struct HVC_SxROM : Interface { //MMC1 if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { programMode = 1; programSize = 1; characterBank[1] = 1; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(writeDelay); diff --git a/ares/fc/cartridge/board/hvc-txrom.cpp b/ares/fc/cartridge/board/hvc-txrom.cpp index 6c5843bce2..e78758c809 100644 --- a/ares/fc/cartridge/board/hvc-txrom.cpp +++ b/ares/fc/cartridge/board/hvc-txrom.cpp @@ -182,12 +182,12 @@ struct HVC_TxROM : Interface { //MMC3 if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { ramEnable = 1; ramWritable = 1; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(characterMode); @@ -206,18 +206,18 @@ struct HVC_TxROM : Interface { //MMC3 s(characterAddress); } - n01 characterMode; - n01 programMode; - n03 bankSelect; - n06 programBank[2]; - n08 characterBank[6]; - n01 mirror; - n01 ramEnable; - n01 ramWritable; - n08 irqLatch; - n08 irqCounter; - n01 irqEnable; - n08 irqDelay; - n01 irqLine; + n1 characterMode; + n1 programMode; + n3 bankSelect; + n6 programBank[2]; + n8 characterBank[6]; + n1 mirror; + n1 ramEnable; + n1 ramWritable; + n8 irqLatch; + n8 irqCounter; + n1 irqEnable; + n8 irqDelay; + n1 irqLine; n16 characterAddress; }; diff --git a/ares/fc/cartridge/board/hvc-uxrom.cpp b/ares/fc/cartridge/board/hvc-uxrom.cpp index 03f4295039..72c1d9bb92 100644 --- a/ares/fc/cartridge/board/hvc-uxrom.cpp +++ b/ares/fc/cartridge/board/hvc-uxrom.cpp @@ -58,10 +58,10 @@ struct HVC_UxROM : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(mirror); s(programBank); diff --git a/ares/fc/cartridge/board/jaleco-jf.cpp b/ares/fc/cartridge/board/jaleco-jf.cpp index 4a92a830e3..e531130ba1 100644 --- a/ares/fc/cartridge/board/jaleco-jf.cpp +++ b/ares/fc/cartridge/board/jaleco-jf.cpp @@ -30,8 +30,8 @@ struct JalecoJF : Interface { switch(irqMode) { case 0: irqCounter = n16(irqReload); break; case 1: irqCounter = n12(irqReload); break; - case 2: irqCounter = n08(irqReload); break; - case 3: irqCounter = n04(irqReload); break; + case 2: irqCounter = n8 (irqReload); break; + case 3: irqCounter = n4 (irqReload); break; } } } @@ -118,7 +118,6 @@ struct JalecoJF : Interface { auto readCHR(n32 address, n8 data) -> n8 override { if(address & 0x2000) return ppu.readCIRAM(addressCIRAM(address)); return characterROM.read(addressCHR(address)); - return data; } auto writeCHR(n32 address, n8 data) -> void override { @@ -142,12 +141,12 @@ struct JalecoJF : Interface { s(mirror); } - n06 programBank[3]; - n08 characterBank[8]; - n01 irqLine; + n6 programBank[3]; + n8 characterBank[8]; + n1 irqLine; n16 irqCounter; n16 irqReload; - n01 irqEnable; - n03 irqMode; - n02 mirror; + n1 irqEnable; + n3 irqMode; + n2 mirror; }; diff --git a/ares/fc/cartridge/board/konami-vrc1.cpp b/ares/fc/cartridge/board/konami-vrc1.cpp index f51acc83c9..4d06b04253 100644 --- a/ares/fc/cartridge/board/konami-vrc1.cpp +++ b/ares/fc/cartridge/board/konami-vrc1.cpp @@ -79,10 +79,10 @@ struct KonamiVRC1 : Interface { if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(characterRAM); s(programBank); s(characterBank); diff --git a/ares/fc/cartridge/board/konami-vrc2.cpp b/ares/fc/cartridge/board/konami-vrc2.cpp index b06ed9fafa..8781742829 100644 --- a/ares/fc/cartridge/board/konami-vrc2.cpp +++ b/ares/fc/cartridge/board/konami-vrc2.cpp @@ -115,10 +115,10 @@ struct KonamiVRC2 : Interface { if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(programBank); diff --git a/ares/fc/cartridge/board/konami-vrc3.cpp b/ares/fc/cartridge/board/konami-vrc3.cpp index 3be575fabf..45b23dff6c 100644 --- a/ares/fc/cartridge/board/konami-vrc3.cpp +++ b/ares/fc/cartridge/board/konami-vrc3.cpp @@ -22,7 +22,7 @@ struct KonamiVRC3 : Interface { Interface::save(characterRAM, board["memory(type=RAM,content=Character)"]); } - auto main() -> void { + auto main() -> void override { if(irqEnable) { if(irqMode == 0) { //16-bit if(++irqCounter.bit(0,15) == 0) { @@ -92,10 +92,10 @@ struct KonamiVRC3 : Interface { if(characterRAM) return characterRAM.write(address, data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(mirror); @@ -108,12 +108,12 @@ struct KonamiVRC3 : Interface { s(irqLine); } - n01 mirror; - n04 programBank; - n01 irqMode; - n01 irqEnable; - n01 irqAcknowledge; + n1 mirror; + n4 programBank; + n1 irqMode; + n1 irqEnable; + n1 irqAcknowledge; n16 irqLatch; n16 irqCounter; - n01 irqLine; + n1 irqLine; }; diff --git a/ares/fc/cartridge/board/konami-vrc4.cpp b/ares/fc/cartridge/board/konami-vrc4.cpp index af5472305d..6be7682362 100644 --- a/ares/fc/cartridge/board/konami-vrc4.cpp +++ b/ares/fc/cartridge/board/konami-vrc4.cpp @@ -151,10 +151,10 @@ struct KonamiVRC4 : Interface { if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(programMode); @@ -170,19 +170,19 @@ struct KonamiVRC4 : Interface { s(irqLine); } - n01 programMode; - n05 programBank[2]; - n02 mirror; - n08 characterBank[8]; - n08 irqLatch; - n01 irqMode; - n01 irqEnable; - n01 irqAcknowledge; - n08 irqCounter; + n1 programMode; + n5 programBank[2]; + n2 mirror; + n8 characterBank[8]; + n8 irqLatch; + n1 irqMode; + n1 irqEnable; + n1 irqAcknowledge; + n8 irqCounter; i16 irqScalar; - n01 irqLine; + n1 irqLine; //unserialized: - n08 pinA0; - n08 pinA1; + n8 pinA0; + n8 pinA1; }; diff --git a/ares/fc/cartridge/board/konami-vrc5.cpp b/ares/fc/cartridge/board/konami-vrc5.cpp index f5a4a3da09..68e21a1483 100644 --- a/ares/fc/cartridge/board/konami-vrc5.cpp +++ b/ares/fc/cartridge/board/konami-vrc5.cpp @@ -286,13 +286,13 @@ struct KonamiVRC5 : Interface { } } - auto power() -> void { + auto power() -> void override { programBank3 = 0x3f; programChip3 = 1; graphicBank1 = 1; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(qtram); @@ -324,38 +324,38 @@ struct KonamiVRC5 : Interface { s(chrLatchCount); } - n01 saveBank0; - n01 saveBank1; + n1 saveBank0; + n1 saveBank1; - n01 saveChip0; //0 = external, 1 = internal - n01 saveChip1; + n1 saveChip0; //0 = external, 1 = internal + n1 saveChip1; - n06 programBank0; - n06 programBank1; - n06 programBank2; - n06 programBank3; //fixed + n6 programBank0; + n6 programBank1; + n6 programBank2; + n6 programBank3; //fixed - n01 programChip0; //0 = internal, 1 = external - n01 programChip1; - n01 programChip2; - n01 programChip3; //fixed + n1 programChip0; //0 = internal, 1 = external + n1 programChip1; + n1 programChip2; + n1 programChip3; //fixed - n01 graphicBank0; - n01 graphicBank1; //fixed + n1 graphicBank0; + n1 graphicBank1; //fixed n16 irqCounter; n16 irqLatch; - n01 irqRepeat; - n01 irqEnable; + n1 irqRepeat; + n1 irqEnable; - n01 qtramEnable; //0 = CIRAM, 1 = QTRAM - n01 mirror; //0 = vertical, 1 = horizontal + n1 qtramEnable; //0 = CIRAM, 1 = QTRAM + n1 mirror; //0 = vertical, 1 = horizontal - n02 jisPosition; //0 = top-left, 1 = top-right, 2 = bottom-left, 3 = bottom-right - n01 jisAttribute; //0 = normal, 1 = alternate - n07 jisColumn; - n07 jisRow; + n2 jisPosition; //0 = top-left, 1 = top-right, 2 = bottom-left, 3 = bottom-right + n1 jisAttribute; //0 = normal, 1 = alternate + n7 jisColumn; + n7 jisRow; - n08 chrLatchData; - n08 chrLatchCount; + n8 chrLatchData; + n8 chrLatchCount; }; diff --git a/ares/fc/cartridge/board/konami-vrc6.cpp b/ares/fc/cartridge/board/konami-vrc6.cpp index 5af76ee8c5..db15bb0ee1 100644 --- a/ares/fc/cartridge/board/konami-vrc6.cpp +++ b/ares/fc/cartridge/board/konami-vrc6.cpp @@ -31,14 +31,14 @@ struct KonamiVRC6 : Interface { s(output); } - n01 mode; - n03 duty; - n04 volume; - n01 enable; + n1 mode; + n3 duty; + n4 volume; + n1 enable; n12 frequency; n12 divider; - n04 cycle; - n04 output; + n4 cycle; + n4 output; }; struct Sawtooth { @@ -68,14 +68,14 @@ struct KonamiVRC6 : Interface { s(output); } - n06 rate; - n01 enable; + n6 rate; + n1 enable; n12 frequency; n12 divider; - n01 phase; - n03 stage; - n08 accumulator; - n05 output; + n1 phase; + n3 stage; + n8 accumulator; + n5 output; }; using Interface::Interface; @@ -129,7 +129,7 @@ struct KonamiVRC6 : Interface { pulse1.clock(); pulse2.clock(); sawtooth.clock(); - double output = (pulse1.output + pulse2.output + sawtooth.output) / 61.0 * 0.25; + f64 output = (pulse1.output + pulse2.output + sawtooth.output) / 61.0 * 0.25; stream->frame(-output); tick(); @@ -243,25 +243,25 @@ struct KonamiVRC6 : Interface { return bank << 10 | (n10)address; } - auto readCHR(n32 address, n8 data) -> n8 { + auto readCHR(n32 address, n8 data) -> n8 override { if(address & 0x2000) return ppu.readCIRAM(addressCIRAM(address)); if(characterROM) return characterROM.read(addressCHR(address)); if(characterRAM) return characterRAM.read(addressCHR(address)); return data; } - auto writeCHR(n32 address, n8 data) -> void { + auto writeCHR(n32 address, n8 data) -> void override { if(address & 0x2000) return ppu.writeCIRAM(addressCIRAM(address), data); if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { pulse1.divider = 1; pulse2.divider = 1; sawtooth.divider = 1; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(pulse1); @@ -282,18 +282,18 @@ struct KonamiVRC6 : Interface { Pulse pulse1; Pulse pulse2; Sawtooth sawtooth; - n08 programBank[2]; - n08 characterBank[8]; - n02 mirror; - n08 irqLatch; - n01 irqMode; - n01 irqEnable; - n01 irqAcknowledge; - n08 irqCounter; + n8 programBank[2]; + n8 characterBank[8]; + n2 mirror; + n8 irqLatch; + n1 irqMode; + n1 irqEnable; + n1 irqAcknowledge; + n8 irqCounter; i16 irqScalar; - n01 irqLine; + n1 irqLine; //unserialized: - n8 pinA0; - n8 pinA1; + n8 pinA0; + n8 pinA1; }; diff --git a/ares/fc/cartridge/board/konami-vrc7.cpp b/ares/fc/cartridge/board/konami-vrc7.cpp index 8d4d69f286..e1f71aaaf5 100644 --- a/ares/fc/cartridge/board/konami-vrc7.cpp +++ b/ares/fc/cartridge/board/konami-vrc7.cpp @@ -147,18 +147,18 @@ struct KonamiVRC7 : Interface { return data; } - auto writeCHR(n32 address, n8 data) -> void { + auto writeCHR(n32 address, n8 data) -> void override { if(address & 0x2000) return ppu.writeCIRAM(addressCIRAM(address), data); if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { ym2413.power(); disableFM = 1; ramWritable = 1; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(ym2413); @@ -177,17 +177,17 @@ struct KonamiVRC7 : Interface { s(divider); } - n08 programBank[3]; - n08 characterBank[8]; - n02 mirror; - n01 disableFM; - n01 ramWritable; - n08 irqLatch; - n01 irqMode; - n01 irqEnable; - n01 irqAcknowledge; - n08 irqCounter; + n8 programBank[3]; + n8 characterBank[8]; + n2 mirror; + n1 disableFM; + n1 ramWritable; + n8 irqLatch; + n1 irqMode; + n1 irqEnable; + n1 irqAcknowledge; + n8 irqCounter; i16 irqScalar; - n01 irqLine; - n06 divider; + n1 irqLine; + n6 divider; }; diff --git a/ares/fc/cartridge/board/sunsoft-3.cpp b/ares/fc/cartridge/board/sunsoft-3.cpp index 3a5c9a5e47..e9a671816d 100644 --- a/ares/fc/cartridge/board/sunsoft-3.cpp +++ b/ares/fc/cartridge/board/sunsoft-3.cpp @@ -106,7 +106,7 @@ struct Sunsoft3 : Interface { auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programBank); s(characterBank); s(mirror); @@ -115,10 +115,10 @@ struct Sunsoft3 : Interface { s(irqCounter); } - n05 programBank; - n06 characterBank[4]; - n02 mirror; - n01 irqEnable; - n01 irqToggle; + n5 programBank; + n6 characterBank[4]; + n2 mirror; + n1 irqEnable; + n1 irqToggle; n16 irqCounter; }; diff --git a/ares/fc/cartridge/board/sunsoft-4.cpp b/ares/fc/cartridge/board/sunsoft-4.cpp index 7b546eed10..3085a1dfd4 100644 --- a/ares/fc/cartridge/board/sunsoft-4.cpp +++ b/ares/fc/cartridge/board/sunsoft-4.cpp @@ -136,11 +136,11 @@ struct Sunsoft4 : Interface { } n32 optionTimer; - n08 characterBank[4]; - n08 nametableBank[2]; - n04 programBank; - n01 optionDisable; - n01 ramEnable; - n01 nametableEnable; - n02 mirror; + n8 characterBank[4]; + n8 nametableBank[2]; + n4 programBank; + n1 optionDisable; + n1 ramEnable; + n1 nametableEnable; + n2 mirror; }; diff --git a/ares/fc/cartridge/board/sunsoft-5b.cpp b/ares/fc/cartridge/board/sunsoft-5b.cpp index 09751d6096..69a24852b5 100644 --- a/ares/fc/cartridge/board/sunsoft-5b.cpp +++ b/ares/fc/cartridge/board/sunsoft-5b.cpp @@ -29,7 +29,7 @@ struct Sunsoft5B : Interface { Interface::save(characterRAM, board["memory(type=RAM,content=Character)"]); } - auto main() -> void { + auto main() -> void override { if(irqCounterEnable) { if(--irqCounter == 0xffff) { cpu.irqLine(irqEnable); @@ -141,14 +141,14 @@ struct Sunsoft5B : Interface { if(characterRAM) return characterRAM.write(addressCHR(address), data); } - auto power() -> void { + auto power() -> void override { ym2149.power(); for(u32 level : range(32)) { volume[level] = 1.0 / pow(2, 1.0 / 2 * (31 - level)); } } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(programRAM); s(characterRAM); s(ym2149); @@ -162,14 +162,14 @@ struct Sunsoft5B : Interface { s(divider); } - n04 port; - n08 programBank[4]; - n08 characterBank[8]; - n02 mirror; - n01 irqEnable; - n01 irqCounterEnable; + n4 port; + n8 programBank[4]; + n8 characterBank[8]; + n2 mirror; + n1 irqEnable; + n1 irqCounterEnable; n16 irqCounter; - n04 divider; + n4 divider; //unserialized: f64 volume[32]; diff --git a/ares/fc/cpu/cpu.hpp b/ares/fc/cpu/cpu.hpp index a69b218309..0fd39eb8e7 100644 --- a/ares/fc/cpu/cpu.hpp +++ b/ares/fc/cpu/cpu.hpp @@ -57,16 +57,16 @@ struct CPU : MOS6502, Thread { //protected: struct IO { - n01 interruptPending; - n01 nmiPending; - n01 nmiLine; - n01 irqLine; - n01 apuLine; - n01 rdyLine; - n01 rdyAddressValid; + n1 interruptPending; + n1 nmiPending; + n1 nmiLine; + n1 irqLine; + n1 apuLine; + n1 rdyLine; + n1 rdyAddressValid; n16 rdyAddressValue; - n01 oamDMAPending; - n08 oamDMAPage; + n1 oamDMAPending; + n8 oamDMAPage; } io; }; diff --git a/ares/fc/fc.hpp b/ares/fc/fc.hpp index 5001c3421a..18632d0375 100644 --- a/ares/fc/fc.hpp +++ b/ares/fc/fc.hpp @@ -10,6 +10,7 @@ namespace ares::Famicom { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Region { diff --git a/ares/fc/fds/audio.hpp b/ares/fc/fds/audio.hpp index 93df851074..0c581aef67 100644 --- a/ares/fc/fds/audio.hpp +++ b/ares/fc/fds/audio.hpp @@ -17,11 +17,11 @@ struct FDSAudio { auto clockEnvelope() -> bool; auto reloadPeriod() -> void; - n08 masterSpeed = 0xff; - n06 speed; - n06 gain; - n01 direction; //0 = decrease, 1 = increase - n01 envelope; //0 = disable, 1 = enable + n8 masterSpeed = 0xff; + n6 speed; + n6 gain; + n1 direction; //0 = decrease, 1 = increase + n1 envelope; //0 = disable, 1 = enable n12 frequency; n32 period; }; @@ -37,24 +37,24 @@ struct FDSAudio { n6 index; }; - n01 disabled; - i08 counter; + n1 disabled; + i8 counter; n16 overflow; i32 output; Table table; }; struct Waveform { - n01 halt; - n01 writable; + n1 halt; + n1 writable; n16 overflow; - n06 data[64]; - n06 index; + n6 data[64]; + n6 index; }; - n01 enable; - n01 envelopes; //0 = disable, 1 = enable - n02 masterVolume; + n1 enable; + n1 envelopes; //0 = disable, 1 = enable + n2 masterVolume; Operator carrier; Modulator modulator; Waveform waveform; diff --git a/ares/fc/fds/drive.hpp b/ares/fc/fds/drive.hpp index c0b389b9e5..690b895436 100644 --- a/ares/fc/fds/drive.hpp +++ b/ares/fc/fds/drive.hpp @@ -13,23 +13,23 @@ struct FDSDrive { //serialization.cpp auto serialize(serializer&) -> void; - n01 enable; - n01 power; - n01 changing; - n01 ready; - n01 scan; - n01 rewinding; - n01 scanning; - n01 reading; //0 = writing - n01 writeCRC; - n01 clearCRC; - n01 irq; - n01 pending; - n01 available; + n1 enable; + n1 power; + n1 changing; + n1 ready; + n1 scan; + n1 rewinding; + n1 scanning; + n1 reading; //0 = writing + n1 writeCRC; + n1 clearCRC; + n1 irq; + n1 pending; + n1 available; n32 counter; n32 offset; - n01 gap; - n08 data; - n01 completed; + n1 gap; + n8 data; + n1 completed; n16 crc16; }; diff --git a/ares/fc/fds/timer.hpp b/ares/fc/fds/timer.hpp index 336e5314ca..a0dc523e9e 100644 --- a/ares/fc/fds/timer.hpp +++ b/ares/fc/fds/timer.hpp @@ -6,10 +6,10 @@ struct FDSTimer { //serialization.cpp auto serialize(serializer&) -> void; - n01 enable; + n1 enable; n16 counter; n16 period; - n01 repeat; - n01 irq; - n01 pending; + n1 repeat; + n1 irq; + n1 pending; }; diff --git a/ares/fc/ppu/ppu.hpp b/ares/fc/ppu/ppu.hpp index b16f323fd5..d08ac2eea6 100644 --- a/ares/fc/ppu/ppu.hpp +++ b/ares/fc/ppu/ppu.hpp @@ -60,11 +60,11 @@ struct PPU : Thread { struct IO { //internal - n08 mdr; - n01 field; + n8 mdr; + n1 field; n16 lx; n16 ly; - n08 busData; + n8 busData; struct Union { n19 data; @@ -81,31 +81,31 @@ struct PPU : Thread { BitRange<19,16,18> fineX {&data}; } v, t; - n01 nmiHold; - n01 nmiFlag; + n1 nmiHold; + n1 nmiFlag; //$2000 - n06 vramIncrement; //1 or 32 + n6 vramIncrement; //1 or 32 n16 spriteAddress; //0x0000 or 0x1000 n16 bgAddress; //0x0000 or 0x1000 - n05 spriteHeight; //8 or 16 - n01 masterSelect; - n01 nmiEnable; + n5 spriteHeight; //8 or 16 + n1 masterSelect; + n1 nmiEnable; //$2001 - n01 grayscale; - n01 bgEdgeEnable; - n01 spriteEdgeEnable; - n01 bgEnable; - n01 spriteEnable; - n03 emphasis; + n1 grayscale; + n1 bgEdgeEnable; + n1 spriteEdgeEnable; + n1 bgEnable; + n1 spriteEnable; + n3 emphasis; //$2002 - n01 spriteOverflow; - n01 spriteZeroHit; + n1 spriteOverflow; + n1 spriteZeroHit; //$2003 - n08 oamAddress; + n8 oamAddress; } io; struct OAM { diff --git a/ares/fc/system/system.cpp b/ares/fc/system/system.cpp index 6503b0c944..9f6856ea28 100644 --- a/ares/fc/system/system.cpp +++ b/ares/fc/system/system.cpp @@ -2,7 +2,16 @@ namespace ares::Famicom { +auto enumerate() -> vector { + return { + "[Nintendo] Famicom (NTSC-J)", + "[Nintendo] Nintendo (NTSC-U)", + "[Nintendo] Nintendo (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -35,8 +44,23 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("NTSC-J")) { + information.name = "Famicom"; + information.region = Region::NTSCJ; + information.frequency = Constants::Colorburst::NTSC * 6.0; + } + if(name.find("NTSC-U")) { + information.name = "Famicom"; + information.region = Region::NTSCU; + information.frequency = Constants::Colorburst::NTSC * 6.0; + } + if(name.find("PAL")) { + information.name = "Famicom"; + information.region = Region::PAL; + information.frequency = Constants::Colorburst::PAL * 6.0; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -46,17 +70,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC-J → NTSC-U → PAL"); - regionNode->setAllowedValues({ - "NTSC-J → NTSC-U → PAL", - "NTSC-U → NTSC-J → PAL", - "PAL → NTSC-J → NTSC-U", - "PAL → NTSC-U → NTSC-J", - "NTSC-J", - "NTSC-U", - "PAL" - }); - scheduler.reset(); controls.load(node); cpu.load(node); @@ -90,26 +103,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC-J") { - information.region = Region::NTSCJ; - information.frequency = Constants::Colorburst::NTSC * 6.0; - } - if(region == "NTSC-U") { - information.region = Region::NTSCU; - information.frequency = Constants::Colorburst::NTSC * 6.0; - } - if(region == "PAL") { - information.region = Region::PAL; - information.frequency = Constants::Colorburst::PAL * 6.0; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - //zero-initialization (breaks Super Mario Bros.) #if 0 if(!reset) { diff --git a/ares/fc/system/system.hpp b/ares/fc/system/system.hpp index 083445ccd9..03734604ea 100644 --- a/ares/fc/system/system.hpp +++ b/ares/fc/system/system.hpp @@ -2,7 +2,6 @@ extern Random random; struct System { Node::System node; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -16,7 +15,7 @@ struct System { enum class Region : u32 { NTSCJ, NTSCU, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto region() const -> Region { return information.region; } auto frequency() const -> f64 { return information.frequency; } @@ -35,6 +34,7 @@ struct System { private: struct Information { + string name = "Famicom"; Region region = Region::NTSCJ; f64 frequency = Constants::Colorburst::NTSC * 6.0; } information; diff --git a/ares/gb/apu/apu.hpp b/ares/gb/apu/apu.hpp index d2b1d33fdc..176e56e0d9 100644 --- a/ares/gb/apu/apu.hpp +++ b/ares/gb/apu/apu.hpp @@ -10,8 +10,8 @@ struct APU : Thread { auto power() -> void; //io.cpp - auto readIO(uint cycle, uint16 address, uint8 data) -> uint8; - auto writeIO(uint cycle, uint16 address, uint8 data) -> void; + auto readIO(u32 cycle, n16 address, n8 data) -> n8; + auto writeIO(u32 cycle, n16 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -32,27 +32,27 @@ struct APU : Thread { bool enable; - uint3 sweepFrequency; + n3 sweepFrequency; bool sweepDirection; - uint3 sweepShift; + n3 sweepShift; bool sweepNegate; - uint2 duty; - uint length; - uint4 envelopeVolume; + n2 duty; + u32 length; + n4 envelopeVolume; bool envelopeDirection; - uint3 envelopeFrequency; - uint11 frequency; + n3 envelopeFrequency; + n11 frequency; bool counter; - int16 output; + i16 output; bool dutyOutput; - uint3 phase; - uint period; - uint3 envelopePeriod; - uint3 sweepPeriod; - int frequencyShadow; + n3 phase; + u32 period; + n3 envelopePeriod; + n3 sweepPeriod; + s32 frequencyShadow; bool sweepEnable; - uint4 volume; + n4 volume; } square1; //square2.cpp @@ -69,30 +69,30 @@ struct APU : Thread { bool enable; - uint2 duty; - uint length; - uint4 envelopeVolume; + n2 duty; + u32 length; + n4 envelopeVolume; bool envelopeDirection; - uint3 envelopeFrequency; - uint11 frequency; + n3 envelopeFrequency; + n11 frequency; bool counter; - int16 output; + i16 output; bool dutyOutput; - uint3 phase; - uint period; - uint3 envelopePeriod; - uint4 volume; + n3 phase; + u32 period; + n3 envelopePeriod; + n4 volume; } square2; struct Wave { - auto getPattern(uint5 offset) const -> uint4; + auto getPattern(n5 offset) const -> n4; auto run() -> void; auto clockLength() -> void; auto trigger() -> void; - auto readRAM(uint4 address, uint8 data) -> uint8; - auto writeRAM(uint4 address, uint8 data) -> void; + auto readRAM(n4 address, n8 data) -> n8; + auto writeRAM(n4 address, n8 data) -> void; auto power(bool initializeLength = true) -> void; auto serialize(serializer&) -> void; @@ -100,22 +100,22 @@ struct APU : Thread { bool enable; bool dacEnable; - uint2 volume; - uint11 frequency; + n2 volume; + n11 frequency; bool counter; - uint8 pattern[16]; - - int16 output; - uint length; - uint period; - uint5 patternOffset; - uint4 patternSample; - uint patternHold; + n8 pattern[16]; + + i16 output; + u32 length; + u32 period; + n5 patternOffset; + n4 patternSample; + u32 patternHold; } wave; struct Noise { auto dacEnable() const -> bool; - auto getPeriod() const -> uint; + auto getPeriod() const -> u32; auto run() -> void; auto clockLength() -> void; @@ -127,20 +127,20 @@ struct APU : Thread { bool enable; - uint4 envelopeVolume; + n4 envelopeVolume; bool envelopeDirection; - uint3 envelopeFrequency; - uint4 frequency; + n3 envelopeFrequency; + n4 frequency; bool narrow; - uint3 divisor; + n3 divisor; bool counter; - int16 output; - uint length; - uint3 envelopePeriod; - uint4 volume; - uint period; - uint15 lfsr; + i16 output; + u32 length; + n3 envelopePeriod; + n4 volume; + u32 period; + n15 lfsr; } noise; struct Sequencer { @@ -150,9 +150,9 @@ struct APU : Thread { auto serialize(serializer&) -> void; bool leftEnable; - uint3 leftVolume; + n3 leftVolume; bool rightEnable; - uint3 rightVolume; + n3 rightVolume; struct Channel { bool leftEnable; @@ -161,13 +161,13 @@ struct APU : Thread { bool enable; - int16 center; - int16 left; - int16 right; + i16 center; + i16 left; + i16 right; } sequencer; - uint3 phase; //high 3-bits of clock counter - uint12 cycle; //low 12-bits of clock counter + n3 phase; //high 3-bits of clock counter + n12 cycle; //low 12-bits of clock counter }; extern APU apu; diff --git a/ares/gb/apu/io.cpp b/ares/gb/apu/io.cpp index dcdcf70d0d..f36a366a34 100644 --- a/ares/gb/apu/io.cpp +++ b/ares/gb/apu/io.cpp @@ -1,4 +1,4 @@ -auto APU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { +auto APU::readIO(u32 cycle, n16 address, n8 data) -> n8 { if(address < 0xff10 || address > 0xff3f) return data; //NR10 @@ -163,7 +163,7 @@ auto APU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { return data; } -auto APU::writeIO(uint cycle, uint16 address, uint8 data) -> void { +auto APU::writeIO(u32 cycle, n16 address, n8 data) -> void { if(address < 0xff10 || address > 0xff3f) return; if(!sequencer.enable) { diff --git a/ares/gb/apu/noise.cpp b/ares/gb/apu/noise.cpp index 07633da145..79a77fc857 100644 --- a/ares/gb/apu/noise.cpp +++ b/ares/gb/apu/noise.cpp @@ -2,8 +2,8 @@ auto APU::Noise::dacEnable() const -> bool { return (envelopeVolume || envelopeDirection); } -auto APU::Noise::getPeriod() const -> uint { - static const uint table[] = {4, 8, 16, 24, 32, 40, 48, 56}; +auto APU::Noise::getPeriod() const -> u32 { + static const u32 table[] = {4, 8, 16, 24, 32, 40, 48, 56}; return table[divisor] << frequency; } @@ -16,7 +16,7 @@ auto APU::Noise::run() -> void { } } - uint4 sample = lfsr & 1 ? 0 : (uint)volume; + n4 sample = lfsr & 1 ? 0 : (u32)volume; if(!enable) sample = 0; output = sample; @@ -30,7 +30,7 @@ auto APU::Noise::clockLength() -> void { auto APU::Noise::clockEnvelope() -> void { if(enable && envelopeFrequency && --envelopePeriod == 0) { - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; if(envelopeDirection == 0 && volume > 0) volume--; if(envelopeDirection == 1 && volume < 15) volume++; } @@ -39,7 +39,7 @@ auto APU::Noise::clockEnvelope() -> void { auto APU::Noise::trigger() -> void { enable = dacEnable(); lfsr = -1; - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; volume = envelopeVolume; if(!length) { diff --git a/ares/gb/apu/sequencer.cpp b/ares/gb/apu/sequencer.cpp index 144b9482c0..60d01c631c 100644 --- a/ares/gb/apu/sequencer.cpp +++ b/ares/gb/apu/sequencer.cpp @@ -6,7 +6,7 @@ auto APU::Sequencer::run() -> void { return; } - int sample = 0; + s32 sample = 0; sample += apu.square1.output; sample += apu.square2.output; sample += apu.wave.output; diff --git a/ares/gb/apu/square1.cpp b/ares/gb/apu/square1.cpp index d93116a712..7b47e0e371 100644 --- a/ares/gb/apu/square1.cpp +++ b/ares/gb/apu/square1.cpp @@ -14,7 +14,7 @@ auto APU::Square1::run() -> void { } } - uint4 sample = dutyOutput ? (uint)volume : 0; + n4 sample = dutyOutput ? (u32)volume : 0; if(!enable) sample = 0; output = sample; @@ -24,8 +24,8 @@ auto APU::Square1::sweep(bool update) -> void { if(!sweepEnable) return; sweepNegate = sweepDirection; - uint delta = frequencyShadow >> sweepShift; - int freq = frequencyShadow + (sweepNegate ? -delta : delta); + u32 delta = frequencyShadow >> sweepShift; + s32 freq = frequencyShadow + (sweepNegate ? -delta : delta); if(freq > 2047) { enable = false; @@ -44,7 +44,7 @@ auto APU::Square1::clockLength() -> void { auto APU::Square1::clockSweep() -> void { if(--sweepPeriod == 0) { - sweepPeriod = sweepFrequency ? (uint)sweepFrequency : 8; + sweepPeriod = sweepFrequency ? (u32)sweepFrequency : 8; if(sweepEnable && sweepFrequency) { sweep(1); sweep(0); @@ -54,7 +54,7 @@ auto APU::Square1::clockSweep() -> void { auto APU::Square1::clockEnvelope() -> void { if(enable && envelopeFrequency && --envelopePeriod == 0) { - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; if(envelopeDirection == 0 && volume > 0) volume--; if(envelopeDirection == 1 && volume < 15) volume++; } @@ -63,7 +63,7 @@ auto APU::Square1::clockEnvelope() -> void { auto APU::Square1::trigger() -> void { enable = dacEnable(); period = 2 * (2048 - frequency); - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; volume = envelopeVolume; if(!length) { @@ -73,7 +73,7 @@ auto APU::Square1::trigger() -> void { frequencyShadow = frequency; sweepNegate = false; - sweepPeriod = sweepFrequency ? (uint)sweepFrequency : 8; + sweepPeriod = sweepFrequency ? (u32)sweepFrequency : 8; sweepEnable = sweepPeriod || sweepShift; if(sweepShift) sweep(0); } diff --git a/ares/gb/apu/square2.cpp b/ares/gb/apu/square2.cpp index e63be95a9e..ae5dbbc1bf 100644 --- a/ares/gb/apu/square2.cpp +++ b/ares/gb/apu/square2.cpp @@ -14,7 +14,7 @@ auto APU::Square2::run() -> void { } } - uint4 sample = dutyOutput ? (uint)volume : 0; + n4 sample = dutyOutput ? (u32)volume : 0; if(!enable) sample = 0; output = sample; @@ -28,7 +28,7 @@ auto APU::Square2::clockLength() -> void { auto APU::Square2::clockEnvelope() -> void { if(enable && envelopeFrequency && --envelopePeriod == 0) { - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; if(envelopeDirection == 0 && volume > 0) volume--; if(envelopeDirection == 1 && volume < 15) volume++; } @@ -37,7 +37,7 @@ auto APU::Square2::clockEnvelope() -> void { auto APU::Square2::trigger() -> void { enable = dacEnable(); period = 2 * (2048 - frequency); - envelopePeriod = envelopeFrequency ? (uint)envelopeFrequency : 8; + envelopePeriod = envelopeFrequency ? (u32)envelopeFrequency : 8; volume = envelopeVolume; if(!length) { diff --git a/ares/gb/apu/wave.cpp b/ares/gb/apu/wave.cpp index ec5df58141..e89c49eab2 100644 --- a/ares/gb/apu/wave.cpp +++ b/ares/gb/apu/wave.cpp @@ -1,4 +1,4 @@ -auto APU::Wave::getPattern(uint5 offset) const -> uint4 { +auto APU::Wave::getPattern(n5 offset) const -> n4 { return pattern[offset >> 1] >> (offset & 1 ? 0 : 4); } @@ -11,8 +11,8 @@ auto APU::Wave::run() -> void { patternHold = 1; } - static const uint shift[] = {4, 0, 1, 2}; //0%, 100%, 50%, 25% - uint4 sample = patternSample >> shift[volume]; + static const u32 shift[] = {4, 0, 1, 2}; //0%, 100%, 50%, 25% + n4 sample = patternSample >> shift[volume]; if(!enable) sample = 0; output = sample; @@ -51,7 +51,7 @@ auto APU::Wave::trigger() -> void { } } -auto APU::Wave::readRAM(uint4 address, uint8 data) -> uint8 { +auto APU::Wave::readRAM(n4 address, n8 data) -> n8 { if(enable) { if(!Model::GameBoyColor() && !patternHold) return data; return pattern[patternOffset >> 1]; @@ -60,7 +60,7 @@ auto APU::Wave::readRAM(uint4 address, uint8 data) -> uint8 { } } -auto APU::Wave::writeRAM(uint4 address, uint8 data) -> void { +auto APU::Wave::writeRAM(n4 address, n8 data) -> void { if(enable) { if(!Model::GameBoyColor() && !patternHold) return; pattern[patternOffset >> 1] = data; diff --git a/ares/gb/bus/bus.cpp b/ares/gb/bus/bus.cpp index 421762bbb8..a6ba4879f1 100644 --- a/ares/gb/bus/bus.cpp +++ b/ares/gb/bus/bus.cpp @@ -4,7 +4,7 @@ namespace ares::GameBoy { Bus bus; -auto Bus::read(uint cycle, uint16 address, uint8 data) -> uint8 { +auto Bus::read(u32 cycle, n16 address, n8 data) -> n8 { data &= cpu.readIO(cycle, address, data); data &= apu.readIO(cycle, address, data); data &= ppu.readIO(cycle, address, data); @@ -12,14 +12,14 @@ auto Bus::read(uint cycle, uint16 address, uint8 data) -> uint8 { return data; } -auto Bus::write(uint cycle, uint16 address, uint8 data) -> void { +auto Bus::write(u32 cycle, n16 address, n8 data) -> void { cpu.writeIO(cycle, address, data); apu.writeIO(cycle, address, data); ppu.writeIO(cycle, address, data); cartridge.write(cycle, address, data); } -auto Bus::read(uint16 address, uint8 data) -> uint8 { +auto Bus::read(n16 address, n8 data) -> n8 { //data &= read(0, address, data); //data &= read(1, address, data); data &= read(2, address, data); @@ -28,7 +28,7 @@ auto Bus::read(uint16 address, uint8 data) -> uint8 { return data; } -auto Bus::write(uint16 address, uint8 data) -> void { +auto Bus::write(n16 address, n8 data) -> void { //write(0, address, data); //write(1, address, data); write(2, address, data); diff --git a/ares/gb/bus/bus.hpp b/ares/gb/bus/bus.hpp index 799830acd1..96f20bb1a8 100644 --- a/ares/gb/bus/bus.hpp +++ b/ares/gb/bus/bus.hpp @@ -1,9 +1,9 @@ struct Bus { - auto read(uint cycle, uint16 address, uint8 data) -> uint8; - auto write(uint cycle, uint16 address, uint8 data) -> void; + auto read(u32 cycle, n16 address, n8 data) -> n8; + auto write(u32 cycle, n16 address, n8 data) -> void; - auto read(uint16 address, uint8 data) -> uint8; - auto write(uint16 address, uint8 data) -> void; + auto read(n16 address, n8 data) -> n8; + auto write(n16 address, n8 data) -> void; }; extern Bus bus; diff --git a/ares/gb/cartridge/board/board.cpp b/ares/gb/cartridge/board/board.cpp index 6c0044076f..64e3c38ea6 100644 --- a/ares/gb/cartridge/board/board.cpp +++ b/ares/gb/cartridge/board/board.cpp @@ -13,7 +13,7 @@ namespace Board { #include "mmm01.cpp" #include "tama.cpp" -auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); @@ -24,7 +24,7 @@ auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool return false; } -auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); if(node["volatile"]) return true; @@ -36,7 +36,7 @@ auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool return false; } -auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); @@ -51,7 +51,7 @@ auto Interface::main() -> void { step(cartridge.frequency()); } -auto Interface::step(uint clocks) -> void { +auto Interface::step(u32 clocks) -> void { cartridge.step(clocks); } diff --git a/ares/gb/cartridge/board/board.hpp b/ares/gb/cartridge/board/board.hpp index 8c98d2755a..52ec084489 100644 --- a/ares/gb/cartridge/board/board.hpp +++ b/ares/gb/cartridge/board/board.hpp @@ -7,15 +7,15 @@ struct Interface { virtual auto save(Markup::Node) -> void {} virtual auto unload() -> void {} virtual auto main() -> void; - virtual auto step(uint clocks) -> void; - virtual auto read(uint16 address, uint8 data) -> uint8 { return data; } - virtual auto write(uint16 address, uint8 data) -> void {} + virtual auto step(u32 clocks) -> void; + virtual auto read(n16 address, n8 data) -> n8 { return data; } + virtual auto write(n16 address, n8 data) -> void {} virtual auto power() -> void {} virtual auto serialize(serializer&) -> void {} - auto load(Memory::Readable&, Markup::Node) -> bool; - auto load(Memory::Writable&, Markup::Node) -> bool; - auto save(Memory::Writable&, Markup::Node) -> bool; + auto load(Memory::Readable&, Markup::Node) -> bool; + auto load(Memory::Writable&, Markup::Node) -> bool; + auto save(Memory::Writable&, Markup::Node) -> bool; Cartridge& cartridge; }; diff --git a/ares/gb/cartridge/board/huc1.cpp b/ares/gb/cartridge/board/huc1.cpp index d5f2f1084e..1199eaa837 100644 --- a/ares/gb/cartridge/board/huc1.cpp +++ b/ares/gb/cartridge/board/huc1.cpp @@ -1,7 +1,7 @@ struct HuC1 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,24 +17,24 @@ struct HuC1 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram) return 0xff; - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.writable = data.bit(0,3) == 0x0a; return; @@ -58,7 +58,7 @@ struct HuC1 : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.writable) return; - return ram.write(io.ram.bank << 13 | (uint13)address, data); + return ram.write(io.ram.bank << 13 | (n13)address, data); } } @@ -75,13 +75,13 @@ struct HuC1 : Interface { } struct IO { - uint1 model; + n1 model; struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 writable; - uint8 bank; + n1 writable; + n8 bank; } ram; } io; }; diff --git a/ares/gb/cartridge/board/huc3.cpp b/ares/gb/cartridge/board/huc3.cpp index d7c5b14439..6b89ba12c0 100644 --- a/ares/gb/cartridge/board/huc3.cpp +++ b/ares/gb/cartridge/board/huc3.cpp @@ -1,7 +1,7 @@ struct HuC3 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,24 +17,24 @@ struct HuC3 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return 0x01; //does not return open collection - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.enable = data.bit(0,3) == 0x0a; return; @@ -52,7 +52,7 @@ struct HuC3 : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return; - return ram.write(io.ram.bank << 13 | (uint13)address, data); + return ram.write(io.ram.bank << 13 | (n13)address, data); } } @@ -69,11 +69,11 @@ struct HuC3 : Interface { struct IO { struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable; - uint8 bank; + n1 enable; + n8 bank; } ram; } io; }; diff --git a/ares/gb/cartridge/board/linear.cpp b/ares/gb/cartridge/board/linear.cpp index 79bd2d37da..9dd973bbc9 100644 --- a/ares/gb/cartridge/board/linear.cpp +++ b/ares/gb/cartridge/board/linear.cpp @@ -1,7 +1,7 @@ struct Linear : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,20 +17,20 @@ struct Linear : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x7fff) { - return rom.read((uint15)address); + return rom.read((n15)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram) return data; - return ram.read((uint13)address); + return ram.read((n13)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0xa000 && address <= 0xbfff) { if(!ram) return; return ram.write(address, data); diff --git a/ares/gb/cartridge/board/mbc1.cpp b/ares/gb/cartridge/board/mbc1.cpp index 11dd88e0a3..71f9ad0ab8 100644 --- a/ares/gb/cartridge/board/mbc1.cpp +++ b/ares/gb/cartridge/board/mbc1.cpp @@ -1,7 +1,7 @@ struct MBC1 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,32 +17,32 @@ struct MBC1 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { if(io.mode == 0) { - return rom.read(io.ram.bank << 19 | io.rom.bank << 14 | (uint14)address); + return rom.read(io.ram.bank << 19 | io.rom.bank << 14 | (n14)address); } else { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } } if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return 0xff; if(io.mode == 0) { - return ram.read((uint13)address); + return ram.read((n13)address); } else { - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.enable = data.bit(0,3) == 0x0a; return; @@ -67,9 +67,9 @@ struct MBC1 : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return; if(io.mode == 0) { - return ram.write((uint13)address, data); + return ram.write((n13)address, data); } else { - return ram.write(io.ram.bank << 13 | (uint13)address, data); + return ram.write(io.ram.bank << 13 | (n13)address, data); } } } @@ -87,13 +87,13 @@ struct MBC1 : Interface { } struct IO { - uint1 mode; + n1 mode; struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable; - uint8 bank; + n1 enable; + n8 bank; } ram; } io; }; diff --git a/ares/gb/cartridge/board/mbc1m.cpp b/ares/gb/cartridge/board/mbc1m.cpp index 437d1408cb..f857914ac8 100644 --- a/ares/gb/cartridge/board/mbc1m.cpp +++ b/ares/gb/cartridge/board/mbc1m.cpp @@ -1,8 +1,8 @@ //MBC1 with mapper bits repurposed for supporting multi-game cartridges struct MBC1M : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -18,25 +18,25 @@ struct MBC1M : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - if(io.mode == 0) return rom.read((uint14)address); - return rom.read(io.rom.bank.bit(4,5) << 18 | (uint14)address); + if(io.mode == 0) return rom.read((n14)address); + return rom.read(io.rom.bank.bit(4,5) << 18 | (n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram) return data; - return ram.read((uint13)address); + return ram.read((n13)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x2000 && address <= 0x3fff) { io.rom.bank.bit(0,3) = data.bit(0,3); } @@ -51,7 +51,7 @@ struct MBC1M : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram) return; - ram.write((uint14)address, data); + ram.write((n14)address, data); } } @@ -66,9 +66,9 @@ struct MBC1M : Interface { } struct IO { - uint1 mode; + n1 mode; struct ROM { - uint6 bank = 0x01; + n6 bank = 0x01; } rom; } io; }; diff --git a/ares/gb/cartridge/board/mbc2.cpp b/ares/gb/cartridge/board/mbc2.cpp index eb3fb0a934..0a7f579178 100644 --- a/ares/gb/cartridge/board/mbc2.cpp +++ b/ares/gb/cartridge/board/mbc2.cpp @@ -1,7 +1,7 @@ struct MBC2 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,13 +17,13 @@ struct MBC2 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xa1ff) { @@ -37,7 +37,7 @@ struct MBC2 : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { if(!address.bit(8)) io.ram.enable = data.bit(0,3) == 0x0a; return; @@ -70,10 +70,10 @@ struct MBC2 : Interface { struct IO { struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable = 0; + n1 enable = 0; } ram; } io; }; diff --git a/ares/gb/cartridge/board/mbc3.cpp b/ares/gb/cartridge/board/mbc3.cpp index b3d1e4665d..5b235c8f90 100644 --- a/ares/gb/cartridge/board/mbc3.cpp +++ b/ares/gb/cartridge/board/mbc3.cpp @@ -1,8 +1,8 @@ struct MBC3 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; - Memory::Writable rtc; + Memory::Readable rom; + Memory::Writable ram; + Memory::Writable rtc; bool MBC30 = false; //0 = MBC3, 1 = MBC30 //MBC3 supports 128 ROM banks (2MB) and 4 RAM banks (32KB) //MBC30 supports 256 ROM banks (4MB) and 8 RAM banks (64KB) @@ -23,11 +23,11 @@ struct MBC3 : Interface { io.rtc.halt = rtc[4].bit(6); io.rtc.dayCarry = rtc[4].bit(7); - uint64 timestamp = 0; - for(uint index : range(8)) { + n64 timestamp = 0; + for(u32 index : range(8)) { timestamp.byte(index) = rtc[5 + index]; } - uint64 diff = chrono::timestamp() - timestamp; + n64 diff = chrono::timestamp() - timestamp; if(diff < 32 * 365 * 24 * 60 * 60) { while(diff >= 24 * 60 * 60) { tickDay(); diff -= 24 * 60 * 60; } while(diff >= 60 * 60) { tickHour(); diff -= 60 * 60; } @@ -49,8 +49,8 @@ struct MBC3 : Interface { rtc[3] = io.rtc.day.bit(0,7); rtc[4] = io.rtc.day.bit(8) << 0 | io.rtc.halt << 6 | io.rtc.dayCarry << 7; - uint64 timestamp = chrono::timestamp(); - for(uint index : range(8)) { + n64 timestamp = chrono::timestamp(); + for(u32 index : range(8)) { rtc[5 + index] = timestamp.byte(index); } } @@ -91,13 +91,13 @@ struct MBC3 : Interface { } } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { @@ -105,7 +105,7 @@ struct MBC3 : Interface { if(!io.ram.enable) return 0xff; if(io.ram.bank <= (!MBC30 ? 0x03 : 0x07)) { if(!ram) return 0xff; - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } if(io.ram.bank == 0x08) return io.rtc.latchSecond; if(io.ram.bank == 0x09) return io.rtc.latchMinute; @@ -118,7 +118,7 @@ struct MBC3 : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.enable = data.bit(0,3) == 0x0a; return; @@ -154,7 +154,7 @@ struct MBC3 : Interface { if(!io.ram.enable) return; if(io.ram.bank <= (!MBC30 ? 0x03 : 0x07)) { if(!ram) return; - ram.write(io.ram.bank << 13 | (uint13)address, data); + ram.write(io.ram.bank << 13 | (n13)address, data); } else if(io.ram.bank == 0x08) { if(data >= 60) data = 0; //unverified io.rtc.second = data; @@ -201,27 +201,27 @@ struct MBC3 : Interface { struct IO { struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable; - uint8 bank; + n1 enable; + n8 bank; } ram; struct RTC { - uint8 second; - uint8 minute; - uint8 hour; - uint9 day; - uint1 halt; - uint1 dayCarry; - - uint1 latch; - uint8 latchSecond; - uint8 latchMinute; - uint8 latchHour; - uint9 latchDay; - uint1 latchHalt; - uint1 latchDayCarry; + n8 second; + n8 minute; + n8 hour; + n9 day; + n1 halt; + n1 dayCarry; + + n1 latch; + n8 latchSecond; + n8 latchMinute; + n8 latchHour; + n9 latchDay; + n1 latchHalt; + n1 latchDayCarry; } rtc; } io; }; diff --git a/ares/gb/cartridge/board/mbc5.cpp b/ares/gb/cartridge/board/mbc5.cpp index 685d001be1..755cb459fc 100644 --- a/ares/gb/cartridge/board/mbc5.cpp +++ b/ares/gb/cartridge/board/mbc5.cpp @@ -1,7 +1,7 @@ struct MBC5 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; Node::Input::Rumble rumble; auto load(Markup::Node document) -> void override { @@ -20,24 +20,24 @@ struct MBC5 : Interface { cartridge.node->remove(rumble); } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return 0xff; - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.enable = data.bit(0,3) == 0x0a; return; @@ -63,7 +63,7 @@ struct MBC5 : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return; - return ram.write(io.ram.bank << 13 | (uint13)address, data); + return ram.write(io.ram.bank << 13 | (n13)address, data); } } @@ -80,11 +80,11 @@ struct MBC5 : Interface { struct IO { struct ROM { - uint9 bank = 0x01; + n9 bank = 0x01; } rom; struct RAM { - uint1 enable; - uint4 bank; + n1 enable; + n4 bank; } ram; } io; }; diff --git a/ares/gb/cartridge/board/mbc6.cpp b/ares/gb/cartridge/board/mbc6.cpp index c21bbef0b6..967f43a3fa 100644 --- a/ares/gb/cartridge/board/mbc6.cpp +++ b/ares/gb/cartridge/board/mbc6.cpp @@ -1,8 +1,8 @@ struct MBC6 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; - Memory::Writable flash; //Macronix MX29F008TC-14 (writes unemulated) + Memory::Readable rom; + Memory::Writable ram; + Memory::Writable flash; //Macronix MX29F008TC-14 (writes unemulated) auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -20,35 +20,35 @@ struct MBC6 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x5fff) { - if(io.region[0].select == 0) return rom.read(io.region[0].bank << 13 | (uint13)address); - if(io.region[0].select == 1) return flash.read(io.region[0].bank << 13 | (uint13)address); + if(io.region[0].select == 0) return rom.read(io.region[0].bank << 13 | (n13)address); + if(io.region[0].select == 1) return flash.read(io.region[0].bank << 13 | (n13)address); } if(address >= 0x6000 && address <= 0x7fff) { - if(io.region[1].select == 0) return rom.read(io.region[1].bank << 13 | (uint13)address); - if(io.region[1].select == 1) return flash.read(io.region[1].bank << 13 | (uint13)address); + if(io.region[1].select == 0) return rom.read(io.region[1].bank << 13 | (n13)address); + if(io.region[1].select == 1) return flash.read(io.region[1].bank << 13 | (n13)address); } if(address >= 0xa000 && address <= 0xafff) { if(!ram || !io.ram.enable) return 0xff; - return ram.read(io.ram.bank[0] << 12 | (uint12)address); + return ram.read(io.ram.bank[0] << 12 | (n12)address); } if(address >= 0xb000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return 0xff; - return ram.read(io.ram.bank[1] << 12 | (uint12)address); + return ram.read(io.ram.bank[1] << 12 | (n12)address); } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x03ff) { io.ram.enable = data.bit(0,3) == 0xa; return; @@ -96,12 +96,12 @@ struct MBC6 : Interface { if(address >= 0xa000 && address <= 0xafff) { if(!ram || !io.ram.enable) return; - return ram.write(io.ram.bank[0] << 12 | (uint12)address, data); + return ram.write(io.ram.bank[0] << 12 | (n12)address, data); } if(address >= 0xb000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return; - return ram.write(io.ram.bank[1] << 12 | (uint12)address, data); + return ram.write(io.ram.bank[1] << 12 | (n12)address, data); } } @@ -124,16 +124,16 @@ struct MBC6 : Interface { struct IO { struct Region { - uint1 select; //0 = ROM, 1 = Flash - uint7 bank; + n1 select; //0 = ROM, 1 = Flash + n7 bank; } region[2]; struct RAM { - uint1 enable; - uint3 bank[2]; + n1 enable; + n3 bank[2]; } ram; struct Flash { - uint1 enable; //unknown purpose - uint1 writable; //flash /WE pin + n1 enable; //unknown purpose + n1 writable; //flash /WE pin } flash; } io; }; diff --git a/ares/gb/cartridge/board/mbc7.cpp b/ares/gb/cartridge/board/mbc7.cpp index e108be954c..78968adac6 100644 --- a/ares/gb/cartridge/board/mbc7.cpp +++ b/ares/gb/cartridge/board/mbc7.cpp @@ -1,9 +1,9 @@ struct MBC7 : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; Node::Input::Axis x; Node::Input::Axis y; - static constexpr int Center = 0x81d0; //not 0x8000 + static constexpr s32 Center = 0x81d0; //not 0x8000 auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -28,13 +28,13 @@ struct MBC7 : Interface { step(cartridge.frequency() / 1000); //step by approximately one millisecond } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xafff) { @@ -56,7 +56,7 @@ struct MBC7 : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x1fff) { io.ram.enable[0] = data.bit(0,3) == 0xa; if(!io.ram.enable[0]) io.ram.enable[1] = false; @@ -119,8 +119,8 @@ struct MBC7 : Interface { auto load(Markup::Node document) -> void { if(auto memory = document["game/board/memory(type=EEPROM,content=Save)"]) { - uint size = memory["size"].natural(); - uint width = memory["width"].natural(); + u32 size = memory["size"].natural(); + u32 width = memory["width"].natural(); allocate(size, width, 0, 0xff); if(auto fp = platform->open(self.cartridge.node, "save.eeprom", File::Read, File::Optional)) { @@ -147,8 +147,8 @@ struct MBC7 : Interface { M93LCx6::clock(); //clocked at ~1000hz } - auto readIO() -> uint8 { - uint8 data; + auto readIO() -> n8 { + n8 data; if(!select) { data.bit(0) = 1; //high-z when the chip is idle (not selected) } else if(busy) { @@ -168,7 +168,7 @@ struct MBC7 : Interface { return data; } - auto writeIO(uint8 data) -> void { + auto writeIO(n8 data) -> void { //chip enters idle state on falling CS edge if(select && !data.bit(7)) return power(); @@ -210,14 +210,14 @@ struct MBC7 : Interface { struct IO { struct ROM { - uint8 bank = 0x01; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable[2]; + n1 enable[2]; } ram; struct Accelerometer { - uint16 x = Center; - uint16 y = Center; + n16 x = Center; + n16 y = Center; } accelerometer; } io; }; diff --git a/ares/gb/cartridge/board/mmm01.cpp b/ares/gb/cartridge/board/mmm01.cpp index 1dd3cef8a1..7f3a4e07dc 100644 --- a/ares/gb/cartridge/board/mmm01.cpp +++ b/ares/gb/cartridge/board/mmm01.cpp @@ -1,7 +1,7 @@ struct MMM01 : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,10 +17,10 @@ struct MMM01 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(io.mode == 0) { if(address >= 0x0000 && address <= 0x7fff) { - return rom.read(rom.size() - 0x8000 + (uint15)address); + return rom.read(rom.size() - 0x8000 + (n15)address); } return data; @@ -28,16 +28,16 @@ struct MMM01 : Interface { if(io.mode == 1) { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((io.rom.base << 14) + (uint14)address); + return rom.read((io.rom.base << 14) + (n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read((io.rom.base << 14) + (io.rom.bank << 14) + (uint14)address); + return rom.read((io.rom.base << 14) + (io.rom.bank << 14) + (n14)address); } if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return 0xff; - return ram.read(io.ram.bank << 13 | (uint13)address); + return ram.read(io.ram.bank << 13 | (n13)address); } return data; @@ -46,7 +46,7 @@ struct MMM01 : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(io.mode == 0) { if(address >= 0x0000 && address <= 0x1fff) { io.mode = 1; @@ -74,7 +74,7 @@ struct MMM01 : Interface { if(address >= 0xa000 && address <= 0xbfff) { if(!ram || !io.ram.enable) return; - ram.write(io.ram.bank << 13 | (uint13)address, data); + ram.write(io.ram.bank << 13 | (n13)address, data); } return; @@ -95,14 +95,14 @@ struct MMM01 : Interface { } struct IO { - uint1 mode; + n1 mode; struct ROM { - uint6 base; - uint8 bank = 0x01; + n6 base; + n8 bank = 0x01; } rom; struct RAM { - uint1 enable; - uint8 bank; + n1 enable; + n8 bank; } ram; } io; }; diff --git a/ares/gb/cartridge/board/tama.cpp b/ares/gb/cartridge/board/tama.cpp index 2188bad191..7bb2578236 100644 --- a/ares/gb/cartridge/board/tama.cpp +++ b/ares/gb/cartridge/board/tama.cpp @@ -8,12 +8,12 @@ struct TAMA : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; - Memory::Writable rtc; + Memory::Readable rom; + Memory::Writable ram; + Memory::Writable rtc; - auto toBCD (uint8 data) -> uint8 { return (data / 10) * 16 + (data % 10); } - auto fromBCD(uint8 data) -> uint8 { return (data / 16) * 10 + (data % 16); } + auto toBCD (n8 data) -> n8 { return (data / 10) * 16 + (data % 10); } + auto fromBCD(n8 data) -> n8 { return (data / 16) * 10 + (data % 16); } auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -33,11 +33,11 @@ struct TAMA : Interface { io.rtc.hourMode = rtc[6].bit(3); io.rtc.test = rtc[6].bit(4,7); - uint64 timestamp = 0; - for(uint index : range(8)) { + n64 timestamp = 0; + for(u32 index : range(8)) { timestamp.byte(index) = rtc[7 + index]; } - uint64 diff = chrono::timestamp() - timestamp; + n64 diff = chrono::timestamp() - timestamp; if(diff < 32 * 365 * 24 * 60 * 60) { while(diff >= 24 * 60 * 60) { tickDay(); diff -= 24 * 60 * 60; } while(diff >= 60 * 60) { tickHour(); diff -= 60 * 60; } @@ -61,8 +61,8 @@ struct TAMA : Interface { rtc[5] = toBCD(io.rtc.second); rtc[6] = io.rtc.meridian << 0 | io.rtc.leapYear << 1 | io.rtc.hourMode << 3 | io.rtc.test << 4; - uint64 timestamp = chrono::timestamp(); - for(uint index : range(8)) { + n64 timestamp = chrono::timestamp(); + for(u32 index : range(8)) { rtc[7 + index] = timestamp.byte(index); } } @@ -76,13 +76,13 @@ struct TAMA : Interface { step(cartridge.frequency()); } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(address >= 0x0000 && address <= 0x3fff) { - return rom.read((uint14)address); + return rom.read((n14)address); } if(address >= 0x4000 && address <= 0x7fff) { - return rom.read(io.rom.bank << 14 | (uint14)address); + return rom.read(io.rom.bank << 14 | (n14)address); } if(address >= 0xa000 && address <= 0xbfff && (address & 1) == 0) { @@ -102,7 +102,7 @@ struct TAMA : Interface { if(io.mode == 2 || io.mode == 4) { if(io.select == 0x0c || io.select == 0x0d) { - uint4 data; + n4 data; if(io.rtc.index == 0) data = io.rtc.minute % 10; if(io.rtc.index == 1) data = io.rtc.minute / 10; if(io.rtc.index == 2) data = io.rtc.hour % 10; @@ -126,7 +126,7 @@ struct TAMA : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0xa000 && address <= 0xbfff && (address & 1) == 0) { if(io.select == 0x00) { io.rom.bank.bit(0,3) = data.bit(0,3); @@ -170,37 +170,37 @@ struct TAMA : Interface { } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0x7) { - uint8 day = toBCD(io.rtc.day); + n8 day = toBCD(io.rtc.day); day.bit(0,3) = io.input.bit(4,7); io.rtc.day = fromBCD(day); } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0x8) { - uint8 day = toBCD(io.rtc.day); + n8 day = toBCD(io.rtc.day); day.bit(4,7) = io.input.bit(4,7); io.rtc.day = fromBCD(day); } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0x9) { - uint8 month = toBCD(io.rtc.month); + n8 month = toBCD(io.rtc.month); month.bit(0,3) = io.input.bit(4,7); io.rtc.month = fromBCD(month); } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0xa) { - uint8 month = toBCD(io.rtc.month); + n8 month = toBCD(io.rtc.month); month.bit(4,7) = io.input.bit(4,7); io.rtc.month = fromBCD(month); } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0xb) { - uint8 year = toBCD(io.rtc.year); + n8 year = toBCD(io.rtc.year); year.bit(0,3) = io.input.bit(4,7); io.rtc.year = fromBCD(year); } if(io.mode == 4 && io.index == 0x00 && io.input.bit(0,3) == 0xc) { - uint8 year = toBCD(io.rtc.year); + n8 year = toBCD(io.rtc.year); year.bit(4,7) = io.input.bit(4,7); io.rtc.year = fromBCD(year); } @@ -303,7 +303,7 @@ struct TAMA : Interface { } auto tickDay() -> void { - uint days[12] = {31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31}; + u32 days[12] = {31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31}; if(io.rtc.leapYear == 0) days[1] = 29; //extra day in February for leap years if(++io.rtc.day > days[(io.rtc.month - 1) % 12]) { @@ -327,27 +327,27 @@ struct TAMA : Interface { } struct IO { - uint1 ready; - uint4 select; - uint3 mode; - uint5 index; - uint8 input; - uint8 output; + n1 ready; + n4 select; + n3 mode; + n5 index; + n8 input; + n8 output; struct ROM { - uint5 bank; + n5 bank; } rom; struct RTC { - uint8 year; //0 - 99 - uint8 month; //1 - 12 - uint8 day; //1 - 31 - uint8 hour; //0 - 23 - uint8 minute; //0 - 59 - uint8 second; //0 - 59 - uint1 meridian; //0 = AM; 1 = PM - uint2 leapYear; //0 = leap year; 1-3 = non-leap year - uint1 hourMode; //0 = 12-hour; 1 = 24-hour - uint4 test; - uint8 index; + n8 year; //0 - 99 + n8 month; //1 - 12 + n8 day; //1 - 31 + n8 hour; //0 - 23 + n8 minute; //0 - 59 + n8 second; //0 - 59 + n1 meridian; //0 = AM; 1 = PM + n2 leapYear; //0 = leap year; 1-3 = non-leap year + n1 hourMode; //0 = 12-hour; 1 = 24-hour + n4 test; + n8 index; } rtc; } io; }; diff --git a/ares/gb/cartridge/cartridge.cpp b/ares/gb/cartridge/cartridge.cpp index 9fc2fa9950..2e3e436dbd 100644 --- a/ares/gb/cartridge/cartridge.cpp +++ b/ares/gb/cartridge/cartridge.cpp @@ -66,7 +66,7 @@ auto Cartridge::main() -> void { board->main(); } -auto Cartridge::step(uint clocks) -> void { +auto Cartridge::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); } diff --git a/ares/gb/cartridge/cartridge.hpp b/ares/gb/cartridge/cartridge.hpp index c35fd71087..9d86feccbc 100644 --- a/ares/gb/cartridge/cartridge.hpp +++ b/ares/gb/cartridge/cartridge.hpp @@ -15,12 +15,12 @@ struct Cartridge : Thread { auto save() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //memory.cpp - auto read(uint cycle, uint16 address, uint8 data) -> uint8; - auto write(uint cycle, uint16 address, uint8 data) -> void; + auto read(u32 cycle, n16 address, n8 data) -> n8; + auto write(u32 cycle, n16 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/gb/cartridge/memory.cpp b/ares/gb/cartridge/memory.cpp index 27989318d5..e49b9be52b 100644 --- a/ares/gb/cartridge/memory.cpp +++ b/ares/gb/cartridge/memory.cpp @@ -1,4 +1,4 @@ -auto Cartridge::read(uint cycle, uint16 address, uint8 data) -> uint8 { +auto Cartridge::read(u32 cycle, n16 address, n8 data) -> n8 { if(address == 0xff50 && cycle == 2) { return data; } @@ -24,7 +24,7 @@ auto Cartridge::read(uint cycle, uint16 address, uint8 data) -> uint8 { return data; } -auto Cartridge::write(uint cycle, uint16 address, uint8 data) -> void { +auto Cartridge::write(u32 cycle, n16 address, n8 data) -> void { if(bootromEnable && address == 0xff50 && cycle == 2) { bootromEnable = false; //does the written value matter? return; diff --git a/ares/gb/cpu/cpu.cpp b/ares/gb/cpu/cpu.cpp index f4831ee980..2d12afb30e 100644 --- a/ares/gb/cpu/cpu.cpp +++ b/ares/gb/cpu/cpu.cpp @@ -77,10 +77,10 @@ auto CPU::main() -> void { idle(); r.ime = 0; write(--SP, PC >> 8); //upper byte may write to IE before it is polled again - uint8 mask = status.interruptFlag & status.interruptEnable; + n8 mask = status.interruptFlag & status.interruptEnable; write(--SP, PC >> 0); //lower byte write to IE has no effect if(mask) { - uint interruptID = bit::first(mask); //find highest priority interrupt + u32 interruptID = bit::first(mask); //find highest priority interrupt lower(interruptID); PC = 0x0040 + interruptID * 8; } else { @@ -98,11 +98,11 @@ auto CPU::main() -> void { } } -auto CPU::raised(uint interruptID) const -> bool { +auto CPU::raised(u32 interruptID) const -> bool { return status.interruptFlag.bit(interruptID); } -auto CPU::raise(uint interruptID) -> void { +auto CPU::raise(u32 interruptID) -> void { status.interruptFlag.bit(interruptID) = 1; if(status.interruptEnable.bit(interruptID)) { r.halt = false; @@ -110,7 +110,7 @@ auto CPU::raise(uint interruptID) -> void { } } -auto CPU::lower(uint interruptID) -> void { +auto CPU::lower(u32 interruptID) -> void { status.interruptFlag.bit(interruptID) = 0; } diff --git a/ares/gb/cpu/cpu.hpp b/ares/gb/cpu/cpu.hpp index 14bc97557f..8cdd6b5767 100644 --- a/ares/gb/cpu/cpu.hpp +++ b/ares/gb/cpu/cpu.hpp @@ -1,8 +1,8 @@ struct CPU : SM83, Thread { Node::Object node; Node::Setting::String version; - Memory::Writable wram; //GB = 8KB, GBC = 32KB - Memory::Writable hram; + Memory::Writable wram; //GB = 8KB, GBC = 32KB + Memory::Writable hram; struct Debugger { //debugger.cpp @@ -21,7 +21,7 @@ struct CPU : SM83, Thread { } tracer; } debugger; - struct Interrupt { enum : uint { + struct Interrupt { enum : u32 { /* 0 */ VerticalBlank, /* 1 */ Stat, /* 2 */ Timer, @@ -37,34 +37,34 @@ struct CPU : SM83, Thread { auto unload() -> void; auto main() -> void; - auto raised(uint interrupt) const -> bool; - auto raise(uint interrupt) -> void; - auto lower(uint interrupt) -> void; + auto raised(u32 interrupt) const -> bool; + auto raise(u32 interrupt) -> void; + auto lower(u32 interrupt) -> void; auto stoppable() -> bool override; auto power() -> void; auto serialize(serializer&) -> void; //io.cpp - auto wramAddress(uint13 address) const -> uint16; - auto input(uint4 data) -> void; + auto wramAddress(n13 address) const -> n16; + auto input(n4 data) -> void; auto joypPoll() -> void; - auto readIO(uint cycle, uint16 address, uint8 data) -> uint8; - auto writeIO(uint cycle, uint16 address, uint8 data) -> void; + auto readIO(u32 cycle, n16 address, n8 data) -> n8; + auto writeIO(u32 cycle, n16 address, n8 data) -> void; //memory.cpp auto stop() -> void override; auto halt() -> void override; auto idle() -> void override; - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; - auto readDMA(uint16 address, uint8 data) -> uint8; - auto writeDMA(uint13 address, uint8 data) -> void; - auto readDebugger(uint16 address) -> uint8 override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; + auto readDMA(n16 address, n8 data) -> n8; + auto writeDMA(n13 address, n8 data) -> void; + auto readDebugger(n16 address) -> n8 override; //timing.cpp auto step() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto timer262144hz() -> void; auto timer65536hz() -> void; auto timer16384hz() -> void; @@ -75,68 +75,68 @@ struct CPU : SM83, Thread { auto hblankTrigger() -> void; struct Status { - uint22 clock; - uint8 interruptLatch; - uint1 hblankPending; + n22 clock; + n8 interruptLatch; + n1 hblankPending; //$ff00 JOYP - uint4 joyp; - uint1 p14; - uint1 p15; + n4 joyp; + n1 p14; + n1 p15; //$ff01 SB - uint8 serialData; - uint4 serialBits; + n8 serialData; + n4 serialBits; //$ff02 SC - uint1 serialClock; - uint1 serialSpeed; - uint1 serialTransfer; + n1 serialClock; + n1 serialSpeed; + n1 serialTransfer; //$ff04 DIV - uint16 div; + n16 div; //$ff05 TIMA - uint8 tima; + n8 tima; //$ff06 TMA - uint8 tma; + n8 tma; //$ff07 TAC - uint2 timerClock; - uint1 timerEnable; + n2 timerClock; + n1 timerEnable; //$ff0f IF - uint5 interruptFlag; + n5 interruptFlag; //$ff4d KEY1 - uint1 speedSwitch; - uint1 speedDouble; + n1 speedSwitch; + n1 speedDouble; //$ff51,$ff52 HDMA1,HDMA2 - uint16 dmaSource; + n16 dmaSource; //$ff53,$ff54 HDMA3,HDMA4 - uint16 dmaTarget; + n16 dmaTarget; //$ff55 HDMA5 - uint7 dmaLength; - uint1 hdmaActive; + n7 dmaLength; + n1 hdmaActive; //$ff6c ??? - uint1 ff6c; + n1 ff6c; //$ff70 SVBK - uint3 wramBank = 1; + n3 wramBank = 1; //$ff72-$ff75 ??? - uint8 ff72; - uint8 ff73; - uint8 ff74; - uint3 ff75; + n8 ff72; + n8 ff73; + n8 ff74; + n3 ff75; //$ffff IE - uint8 interruptEnable; + n8 interruptEnable; } status; }; diff --git a/ares/gb/cpu/io.cpp b/ares/gb/cpu/io.cpp index d5ba2512e4..5de27287b2 100644 --- a/ares/gb/cpu/io.cpp +++ b/ares/gb/cpu/io.cpp @@ -1,10 +1,10 @@ -auto CPU::wramAddress(uint13 address) const -> uint16 { +auto CPU::wramAddress(n13 address) const -> n16 { if(address < 0x1000) return address; auto bank = status.wramBank + (status.wramBank == 0); - return bank << 12 | (uint12)address; + return bank << 12 | (n12)address; } -auto CPU::input(uint4 data) -> void { +auto CPU::input(n4 data) -> void { status.joyp = data; } @@ -12,13 +12,13 @@ auto CPU::joypPoll() -> void { if(!Model::SuperGameBoy()) { system.controls.poll(); - uint4 dpad; + n4 dpad; dpad.bit(0) = !system.controls.rightLatch; dpad.bit(1) = !system.controls.leftLatch; dpad.bit(2) = !system.controls.upLatch; dpad.bit(3) = !system.controls.downLatch; - uint4 button; + n4 button; button.bit(0) = !system.controls.a->value(); button.bit(1) = !system.controls.b->value(); button.bit(2) = !system.controls.select->value(); @@ -32,10 +32,10 @@ auto CPU::joypPoll() -> void { if(status.joyp != 0xf) raise(Interrupt::Joypad); } -auto CPU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { +auto CPU::readIO(u32 cycle, n16 address, n8 data) -> n8 { if(address <= 0xbfff) return data; if(address >= 0xc000 && address <= 0xfdff && cycle == 2) return wram[wramAddress(address)]; - if(address >= 0xff80 && address <= 0xfffe && cycle == 2) return hram[(uint7)address]; + if(address >= 0xff80 && address <= 0xfffe && cycle == 2) return hram[(n7)address]; if(address == 0xff00 && cycle == 2) { //JOYP joypPoll(); @@ -157,10 +157,10 @@ auto CPU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { return data; } -auto CPU::writeIO(uint cycle, uint16 address, uint8 data) -> void { +auto CPU::writeIO(u32 cycle, n16 address, n8 data) -> void { if(address <= 0xbfff) return; if(address >= 0xc000 && address <= 0xfdff && cycle == 2) { wram[wramAddress(address)] = data; return; } - if(address >= 0xff80 && address <= 0xfffe && cycle == 2) { hram[(uint7)address] = data; return; } + if(address >= 0xff80 && address <= 0xfffe && cycle == 2) { hram[(n7)address] = data; return; } if(address == 0xff00 && cycle == 2) { //JOYP status.p14 = data.bit(4); @@ -253,7 +253,7 @@ auto CPU::writeIO(uint cycle, uint16 address, uint8 data) -> void { //GDMA if(!data.bit(7)) { do { - for(uint loop : range(16)) { + for(u32 loop : range(16)) { writeDMA(status.dmaTarget++, readDMA(status.dmaSource++, 0xff)); } step(8 << status.speedDouble); diff --git a/ares/gb/cpu/memory.cpp b/ares/gb/cpu/memory.cpp index 591e5e4c76..8955819e91 100644 --- a/ares/gb/cpu/memory.cpp +++ b/ares/gb/cpu/memory.cpp @@ -21,8 +21,8 @@ auto CPU::idle() -> void { step(); } -auto CPU::read(uint16 address) -> uint8 { - uint8 data = 0xff; +auto CPU::read(n16 address) -> n8 { + n8 data = 0xff; if(r.ei) r.ei = 0, r.ime = 1; data &= bus.read(0, address, data); step(); @@ -37,7 +37,7 @@ auto CPU::read(uint16 address) -> uint8 { return data; } -auto CPU::write(uint16 address, uint8 data) -> void { +auto CPU::write(n16 address, n8 data) -> void { if(r.ei) r.ei = 0, r.ime = 1; bus.write(0, address, data); step(); @@ -52,7 +52,7 @@ auto CPU::write(uint16 address, uint8 data) -> void { } //VRAM DMA source can only be ROM or RAM -auto CPU::readDMA(uint16 address, uint8 data) -> uint8 { +auto CPU::readDMA(n16 address, n8 data) -> n8 { if(address < 0x8000) return bus.read(address, data); //0000-7fff if(address < 0xa000) return data; //8000-9fff if(address < 0xe000) return bus.read(address, data); //a000-dfff @@ -60,10 +60,10 @@ auto CPU::readDMA(uint16 address, uint8 data) -> uint8 { } //VRAM DMA target is always VRAM -auto CPU::writeDMA(uint13 address, uint8 data) -> void { +auto CPU::writeDMA(n13 address, n8 data) -> void { return bus.write(0x8000 | address, data); } -auto CPU::readDebugger(uint16 address) -> uint8 { +auto CPU::readDebugger(n16 address) -> n8 { return bus.read(address, 0xff); } diff --git a/ares/gb/cpu/timing.cpp b/ares/gb/cpu/timing.cpp index f6566cd24a..7fed99c7fd 100644 --- a/ares/gb/cpu/timing.cpp +++ b/ares/gb/cpu/timing.cpp @@ -6,15 +6,15 @@ auto CPU::step() -> void { step(1); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { for(auto n : range(clocks)) { status.div++; - if(( uint4)status.div == 0) timer262144hz(); - if(( uint6)status.div == 0) timer65536hz(); - if(( uint8)status.div == 0) timer16384hz(); - if(( uint9)status.div == 0) timer8192hz(); - if((uint10)status.div == 0) timer4096hz(); - if((uint12)status.div == 0) timer1024hz(); + if((n4 )status.div == 0) timer262144hz(); + if((n6 )status.div == 0) timer65536hz(); + if((n8 )status.div == 0) timer16384hz(); + if((n9 )status.div == 0) timer8192hz(); + if((n10)status.div == 0) timer4096hz(); + if((n12)status.div == 0) timer1024hz(); Thread::step(1); Thread::synchronize(); @@ -80,7 +80,7 @@ auto CPU::hblank() -> void { auto CPU::hblankTrigger() -> void { if(status.hdmaActive && ppu.status.ly < 144) { - for(uint loop : range(16)) { + for(u32 loop : range(16)) { writeDMA(status.dmaTarget++, readDMA(status.dmaSource++, 0xff)); if(loop & 1) step(1 << status.speedDouble); } diff --git a/ares/gb/gb.hpp b/ares/gb/gb.hpp index 5e01854157..65725c1038 100644 --- a/ares/gb/gb.hpp +++ b/ares/gb/gb.hpp @@ -8,6 +8,7 @@ namespace ares::GameBoy { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { @@ -19,8 +20,8 @@ namespace ares::GameBoy { struct SuperGameBoyInterface { virtual auto ppuHreset() -> void = 0; virtual auto ppuVreset() -> void = 0; - virtual auto ppuWrite(uint2 color) -> void = 0; - virtual auto joypWrite(uint1 p14, uint1 p15) -> void = 0; + virtual auto ppuWrite(n2 color) -> void = 0; + virtual auto joypWrite(n1 p14, n1 p15) -> void = 0; }; #include diff --git a/ares/gb/ppu/cgb.cpp b/ares/gb/ppu/cgb.cpp index 8a3e7b3260..3c09908af3 100644 --- a/ares/gb/ppu/cgb.cpp +++ b/ares/gb/ppu/cgb.cpp @@ -12,18 +12,18 @@ //0x08: VRAM bank# //0x07: palette# -auto PPU::readTileCGB(bool select, uint x, uint y, uint16& tiledata, uint8& attributes) -> void { - uint14 tilemapAddress = 0x1800 + (select << 10); +auto PPU::readTileCGB(bool select, u32 x, u32 y, n16& tiledata, n8& attributes) -> void { + n14 tilemapAddress = 0x1800 + (select << 10); tilemapAddress += (((y >> 3) << 5) + (x >> 3)) & 0x03ff; - uint8 tile = vram[0x0000 + tilemapAddress]; + n8 tile = vram[0x0000 + tilemapAddress]; attributes = vram[0x2000 + tilemapAddress]; - uint14 tiledataAddress = attributes.bit(3) ? 0x2000 : 0x0000; + n14 tiledataAddress = attributes.bit(3) ? 0x2000 : 0x0000; if(status.bgTiledataSelect == 0) { - tiledataAddress += 0x1000 + ( int8(tile) << 4); + tiledataAddress += 0x1000 + (i8(tile) << 4); } else { - tiledataAddress += 0x0000 + (uint8(tile) << 4); + tiledataAddress += 0x0000 + (n8(tile) << 4); } if(attributes.bit(6)) y ^= 7; @@ -37,23 +37,23 @@ auto PPU::readTileCGB(bool select, uint x, uint y, uint16& tiledata, uint8& attr auto PPU::scanlineCGB() -> void { px = 0; - const int Height = (status.obSize == 0 ? 8 : 16); + const s32 Height = (status.obSize == 0 ? 8 : 16); sprites = 0; //find first ten sprites on this scanline - for(uint n = 0; n < 40 * 4; n += 4) { + for(u32 n = 0; n < 40 * 4; n += 4) { Sprite& s = sprite[sprites]; s.y = oam[n + 0] - 16; s.x = oam[n + 1] - 8; s.tile = oam[n + 2] & ~status.obSize; s.attributes = oam[n + 3]; - if(int(status.ly) < s.y) continue; - if(int(status.ly) >= s.y + Height) continue; + if(s32(status.ly) < s.y) continue; + if(s32(status.ly) >= s.y + Height) continue; s.y = status.ly - s.y; if(s.attributes.bit(6)) s.y ^= Height - 1; - uint14 tiledataAddress = (s.attributes.bit(3) ? 0x2000 : 0x0000) + (s.tile << 4) + (s.y << 1); + n14 tiledataAddress = (s.attributes.bit(3) ? 0x2000 : 0x0000) + (s.tile << 4) + (s.y << 1); s.tiledata.byte(0) = vram[tiledataAddress + 0]; s.tiledata.byte(1) = vram[tiledataAddress + 1]; if(s.attributes.bit(5)) s.tiledata = hflip(s.tiledata); @@ -66,7 +66,7 @@ auto PPU::runCGB() -> void { bg = {}; ob = {}; - uint15 color = 0x7fff; + n15 color = 0x7fff; runBackgroundCGB(); if(latch.windowDisplayEnable) runWindowCGB(); if(status.obEnable) runObjectsCGB(); @@ -90,15 +90,15 @@ auto PPU::runCGB() -> void { } auto PPU::runBackgroundCGB() -> void { - uint8 scrollY = status.ly + status.scy; - uint8 scrollX = px + status.scx; - uint3 tileX = scrollX & 7; + n8 scrollY = status.ly + status.scy; + n8 scrollX = px + status.scx; + n3 tileX = scrollX & 7; if(tileX == 0 || px == 0) readTileCGB(status.bgTilemapSelect, scrollX, scrollY, background.tiledata, background.attributes); - uint2 index; + n2 index; index.bit(0) = background.tiledata.bit( 7 - tileX); index.bit(1) = background.tiledata.bit(15 - tileX); - uint5 palette = background.attributes.bit(0,2) << 2 | index; + n5 palette = background.attributes.bit(0,2) << 2 | index; bg.color = bgpd[palette]; bg.palette = index; @@ -109,17 +109,17 @@ auto PPU::runWindowCGB() -> void { if(status.ly < status.wy) return; if(px + 7 == status.wx) latch.wy++; - uint8 scrollY = latch.wy - 1; - uint8 scrollX = px + 7 - latch.wx; - uint3 tileX = scrollX & 7; + n8 scrollY = latch.wy - 1; + n8 scrollX = px + 7 - latch.wx; + n3 tileX = scrollX & 7; if(scrollX >= 160u) return; //also matches underflow (scrollX < 0) if(tileX == 0 || px == 0) readTileCGB(status.windowTilemapSelect, scrollX, scrollY, window.tiledata, window.attributes); - uint2 index; + n2 index; index.bit(0) = window.tiledata.bit( 7 - tileX); index.bit(1) = window.tiledata.bit(15 - tileX); - uint5 palette = window.attributes.bit(0,2) << 2 | index; + n5 palette = window.attributes.bit(0,2) << 2 | index; bg.color = bgpd[palette]; bg.palette = index; @@ -128,17 +128,17 @@ auto PPU::runWindowCGB() -> void { auto PPU::runObjectsCGB() -> void { //render backwards, so that first sprite has priority - for(int n = sprites - 1; n >= 0; n--) { + for(s32 n = sprites - 1; n >= 0; n--) { Sprite& s = sprite[n]; - int tileX = px - s.x; + s32 tileX = px - s.x; if(tileX < 0 || tileX > 7) continue; - uint2 index; + n2 index; index.bit(0) = s.tiledata.bit( 7 - tileX); index.bit(1) = s.tiledata.bit(15 - tileX); if(index == 0) continue; - uint5 palette = s.attributes.bit(0,2) << 2 | index; + n5 palette = s.attributes.bit(0,2) << 2 | index; ob.color = obpd[palette]; ob.palette = index; diff --git a/ares/gb/ppu/color.cpp b/ares/gb/ppu/color.cpp index b1e5323f05..243453806b 100644 --- a/ares/gb/ppu/color.cpp +++ b/ares/gb/ppu/color.cpp @@ -1,54 +1,54 @@ -auto PPU::colorGameBoy(uint32 color) -> uint64 { +auto PPU::colorGameBoy(n32 color) -> n64 { if(colorEmulationDMG->value() == "Game Boy") { - const uint8 monochrome[4][3] = { + const n8 monochrome[4][3] = { {0xae, 0xd9, 0x27}, {0x58, 0xa0, 0x28}, {0x20, 0x62, 0x29}, {0x1a, 0x45, 0x2a}, }; - uint64 R = monochrome[color][0] * 0x0101; - uint64 G = monochrome[color][1] * 0x0101; - uint64 B = monochrome[color][2] * 0x0101; + n64 R = monochrome[color][0] * 0x0101; + n64 G = monochrome[color][1] * 0x0101; + n64 B = monochrome[color][2] * 0x0101; return R << 32 | G << 16 | B << 0; } if(colorEmulationDMG->value() == "Game Boy Pocket") { - const uint8 monochrome[4][3] = { + const n8 monochrome[4][3] = { {0xe0, 0xdb, 0xcd}, {0xa8, 0x9f, 0x94}, {0x70, 0x6b, 0x66}, {0x2b, 0x2b, 0x26}, }; - uint64 R = monochrome[color][0] * 0x0101; - uint64 G = monochrome[color][1] * 0x0101; - uint64 B = monochrome[color][2] * 0x0101; + n64 R = monochrome[color][0] * 0x0101; + n64 G = monochrome[color][1] * 0x0101; + n64 B = monochrome[color][2] * 0x0101; return R << 32 | G << 16 | B << 0; } if(colorEmulationDMG->value() == "RGB") { - const uint8 monochrome[4][3] = { + const n8 monochrome[4][3] = { {0xff, 0xff, 0xff}, {0xaa, 0xaa, 0xaa}, {0x55, 0x55, 0x55}, {0x00, 0x00, 0x00}, }; - uint64 R = monochrome[color][0] * 0x0101; - uint64 G = monochrome[color][1] * 0x0101; - uint64 B = monochrome[color][2] * 0x0101; + n64 R = monochrome[color][0] * 0x0101; + n64 G = monochrome[color][1] * 0x0101; + n64 B = monochrome[color][2] * 0x0101; return R << 32 | G << 16 | B << 0; } return 0; } -auto PPU::colorGameBoyColor(uint32 color) -> uint64 { - uint r = color.bit( 0, 4); - uint g = color.bit( 5, 9); - uint b = color.bit(10,14); +auto PPU::colorGameBoyColor(n32 color) -> n64 { + n32 r = color.bit( 0, 4); + n32 g = color.bit( 5, 9); + n32 b = color.bit(10,14); - uint64_t R = image::normalize(r, 5, 16); - uint64_t G = image::normalize(g, 5, 16); - uint64_t B = image::normalize(b, 5, 16); + n64 R = image::normalize(r, 5, 16); + n64 G = image::normalize(g, 5, 16); + n64 B = image::normalize(b, 5, 16); if(colorEmulationCGB->value()) { R = (r * 26 + g * 4 + b * 2); diff --git a/ares/gb/ppu/dmg.cpp b/ares/gb/ppu/dmg.cpp index f887a1e680..c3b084c501 100644 --- a/ares/gb/ppu/dmg.cpp +++ b/ares/gb/ppu/dmg.cpp @@ -4,17 +4,17 @@ //0x20: horizontal flip //0x10: palette# -auto PPU::readTileDMG(bool select, uint x, uint y, uint16& tiledata) -> void { - uint13 tilemapAddress = 0x1800 + (select << 10); +auto PPU::readTileDMG(bool select, u32 x, u32 y, n16& tiledata) -> void { + n13 tilemapAddress = 0x1800 + (select << 10); tilemapAddress += (((y >> 3) << 5) + (x >> 3)) & 0x03ff; - uint8 tile = vram[tilemapAddress]; + n8 tile = vram[tilemapAddress]; - uint13 tiledataAddress; + n13 tiledataAddress; if(status.bgTiledataSelect == 0) { - tiledataAddress = 0x1000 + ( int8(tile) << 4); + tiledataAddress = 0x1000 + (i8(tile) << 4); } else { - tiledataAddress = 0x0000 + (uint8(tile) << 4); + tiledataAddress = 0x0000 + (n8(tile) << 4); } tiledataAddress += (y & 7) << 1; @@ -26,23 +26,23 @@ auto PPU::readTileDMG(bool select, uint x, uint y, uint16& tiledata) -> void { auto PPU::scanlineDMG() -> void { px = 0; - const int Height = (status.obSize == 0 ? 8 : 16); + const s32 Height = (status.obSize == 0 ? 8 : 16); sprites = 0; //find first ten sprites on this scanline - for(uint n = 0; n < 40 * 4; n += 4) { + for(u32 n = 0; n < 40 * 4; n += 4) { Sprite& s = sprite[sprites]; s.y = oam[n + 0] - 16; s.x = oam[n + 1] - 8; s.tile = oam[n + 2] & ~status.obSize; s.attributes = oam[n + 3]; - if(int(status.ly) < s.y) continue; - if(int(status.ly) >= s.y + Height) continue; - s.y = int(status.ly) - s.y; + if(s32(status.ly) < s.y) continue; + if(s32(status.ly) >= s.y + Height) continue; + s.y = s32(status.ly) - s.y; if(s.attributes.bit(6)) s.y ^= Height - 1; - uint13 tiledataAddress = (s.tile << 4) + (s.y << 1); + n13 tiledataAddress = (s.tile << 4) + (s.y << 1); s.tiledata.byte(0) = vram[tiledataAddress + 0]; s.tiledata.byte(1) = vram[tiledataAddress + 1]; if(s.attributes.bit(5)) s.tiledata = hflip(s.tiledata); @@ -51,8 +51,8 @@ auto PPU::scanlineDMG() -> void { } //sort by X-coordinate - for(uint lo = 0; lo < sprites; lo++) { - for(uint hi = lo + 1; hi < sprites; hi++) { + for(u32 lo = 0; lo < sprites; lo++) { + for(u32 hi = lo + 1; hi < sprites; hi++) { if(sprite[hi].x < sprite[lo].x) swap(sprite[lo], sprite[hi]); } } @@ -62,7 +62,7 @@ auto PPU::runDMG() -> void { bg = {}; ob = {}; - uint2 color = 0; + n2 color = 0; if(status.bgEnable) runBackgroundDMG(); if(latch.windowDisplayEnable) runWindowDMG(); if(status.obEnable) runObjectsDMG(); @@ -83,12 +83,12 @@ auto PPU::runDMG() -> void { } auto PPU::runBackgroundDMG() -> void { - uint8 scrollY = status.ly + status.scy; - uint8 scrollX = px + status.scx; - uint3 tileX = scrollX & 7; + n8 scrollY = status.ly + status.scy; + n8 scrollX = px + status.scx; + n3 tileX = scrollX & 7; if(tileX == 0 || px == 0) readTileDMG(status.bgTilemapSelect, scrollX, scrollY, background.tiledata); - uint2 index; + n2 index; index.bit(0) = background.tiledata.bit( 7 - tileX); index.bit(1) = background.tiledata.bit(15 - tileX); @@ -100,14 +100,14 @@ auto PPU::runWindowDMG() -> void { if(status.ly < status.wy) return; if(px + 7 == status.wx) latch.wy++; - uint8 scrollY = latch.wy - 1; - uint8 scrollX = px + 7 - latch.wx; - uint3 tileX = scrollX & 7; + n8 scrollY = latch.wy - 1; + n8 scrollX = px + 7 - latch.wx; + n3 tileX = scrollX & 7; if(scrollX >= 160u) return; //also matches underflow (scrollX < 0) if(tileX == 0 || px == 0) readTileDMG(status.windowTilemapSelect, scrollX, scrollY, window.tiledata); - uint2 index; + n2 index; index.bit(0) = window.tiledata.bit( 7 - tileX); index.bit(1) = window.tiledata.bit(15 - tileX); @@ -117,17 +117,17 @@ auto PPU::runWindowDMG() -> void { auto PPU::runObjectsDMG() -> void { //render backwards, so that first sprite has priority - for(int n = sprites - 1; n >= 0; n--) { + for(s32 n = sprites - 1; n >= 0; n--) { Sprite& s = sprite[n]; - int tileX = px - s.x; + s32 tileX = px - s.x; if(tileX < 0 || tileX > 7) continue; - uint2 index; + n2 index; index.bit(0) = s.tiledata.bit( 7 - tileX); index.bit(1) = s.tiledata.bit(15 - tileX); if(index == 0) continue; - uint3 palette = s.attributes.bit(4) << 2 | index; + n3 palette = s.attributes.bit(4) << 2 | index; ob.color = obp[palette]; ob.palette = index; diff --git a/ares/gb/ppu/io.cpp b/ares/gb/ppu/io.cpp index 64d52f90b2..3b4ea8987e 100644 --- a/ares/gb/ppu/io.cpp +++ b/ares/gb/ppu/io.cpp @@ -1,8 +1,8 @@ -auto PPU::vramAddress(uint13 address) const -> uint16 { +auto PPU::vramAddress(n13 address) const -> n16 { return status.vramBank << 13 | address; } -auto PPU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { +auto PPU::readIO(u32 cycle, n16 address, n8 data) -> n8 { if(address >= 0x8000 && address <= 0x9fff && cycle == 2) { if(!canAccessVRAM()) return data; return vram[vramAddress(address)]; @@ -10,7 +10,7 @@ auto PPU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { if(address >= 0xfe00 && address <= 0xfe9f && cycle == 2) { if(!canAccessOAM()) return data; - return oam[(uint8)address]; + return oam[(n8)address]; } if(address < 0xff40 || address > 0xff7f) return data; @@ -123,7 +123,7 @@ auto PPU::readIO(uint cycle, uint16 address, uint8 data) -> uint8 { return data; } -auto PPU::writeIO(uint cycle, uint16 address, uint8 data) -> void { +auto PPU::writeIO(u32 cycle, n16 address, n8 data) -> void { if(address >= 0x8000 && address <= 0x9fff && cycle == 2) { vram[vramAddress(address)] = data; return; @@ -131,7 +131,7 @@ auto PPU::writeIO(uint cycle, uint16 address, uint8 data) -> void { if(address >= 0xfe00 && address <= 0xfe9f && cycle == 2) { if(status.dmaActive && status.dmaClock >= 8) return; - oam[(uint8)address] = data; + oam[(n8)address] = data; return; } diff --git a/ares/gb/ppu/ppu.cpp b/ares/gb/ppu/ppu.cpp index e46b3108a2..babfcde4a4 100644 --- a/ares/gb/ppu/ppu.cpp +++ b/ares/gb/ppu/ppu.cpp @@ -142,7 +142,7 @@ auto PPU::main() -> void { } } -auto PPU::mode(uint2 mode) -> void { +auto PPU::mode(n2 mode) -> void { if(status.mode == 0 && mode != 0) { if(Model::SuperGameBoy()) superGameBoy->ppuHreset(); } @@ -166,18 +166,18 @@ auto PPU::stat() -> void { } auto PPU::coincidence() -> bool { - uint ly = status.ly; + u32 ly = status.ly; if(ly == 153 && status.lx >= 92) ly = 0; //LYC=0 triggers early during LY=153 return ly == status.lyc; } -auto PPU::step(uint clocks) -> void { +auto PPU::step(u32 clocks) -> void { while(clocks--) { history.mode = history.mode << 2 | status.mode; stat(); if(status.dmaActive) { - uint hi = status.dmaClock++; - uint lo = hi & (cpu.status.speedDouble ? 1 : 3); + u32 hi = status.dmaClock++; + u32 lo = hi & (cpu.status.speedDouble ? 1 : 3); hi >>= cpu.status.speedDouble ? 1 : 2; if(lo == 0) { if(hi == 0) { @@ -186,10 +186,10 @@ auto PPU::step(uint clocks) -> void { //cool-down; disable status.dmaActive = 0; } else { - uint8 bank = status.dmaBank; + n8 bank = status.dmaBank; if(bank == 0xfe) bank = 0xde; //OAM DMA cannot reference OAM, I/O, or HRAM: if(bank == 0xff) bank = 0xdf; //it accesses HRAM instead. - uint8 data = bus.read(bank << 8 | hi - 1, 0xff); + n8 data = bus.read(bank << 8 | hi - 1, 0xff); oam[hi - 1] = data; } } @@ -202,7 +202,7 @@ auto PPU::step(uint clocks) -> void { } //flips 2bpp tiledata line horizontally -auto PPU::hflip(uint16 tiledata) const -> uint16 { +auto PPU::hflip(n16 tiledata) const -> n16 { return tiledata >> 7 & 0x0101 | tiledata >> 5 & 0x0202 | tiledata >> 3 & 0x0404 diff --git a/ares/gb/ppu/ppu.hpp b/ares/gb/ppu/ppu.hpp index 80a6b73522..a8702d13e5 100644 --- a/ares/gb/ppu/ppu.hpp +++ b/ares/gb/ppu/ppu.hpp @@ -4,12 +4,12 @@ struct PPU : Thread { Node::Setting::String colorEmulationDMG; Node::Setting::Boolean colorEmulationCGB; Node::Setting::Boolean interframeBlending; - Memory::Writable vram; //GB = 8KB, GBC = 16KB - Memory::Writable oam; - Memory::Writable bgp; - Memory::Writable obp; - Memory::Writable bgpd; - Memory::Writable obpd; + Memory::Writable vram; //GB = 8KB, GBC = 16KB + Memory::Writable oam; + Memory::Writable bgp; + Memory::Writable obp; + Memory::Writable bgpd; + Memory::Writable obpd; struct Debugger { //debugger.cpp @@ -30,12 +30,12 @@ struct PPU : Thread { auto unload() -> void; auto main() -> void; - auto mode(uint2 mode) -> void; + auto mode(n2 mode) -> void; auto stat() -> void; auto coincidence() -> bool; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; - auto hflip(uint16 tiledata) const -> uint16; + auto hflip(n16 tiledata) const -> n16; auto power() -> void; @@ -45,12 +45,12 @@ struct PPU : Thread { auto compareLYC() const -> bool; //io.cpp - auto vramAddress(uint13 address) const -> uint16; - auto readIO(uint cycle, uint16 address, uint8 data) -> uint8; - auto writeIO(uint cycle, uint16 address, uint8 data) -> void; + auto vramAddress(n13 address) const -> n16; + auto readIO(u32 cycle, n16 address, n8 data) -> n8; + auto writeIO(u32 cycle, n16 address, n8 data) -> void; //dmg.cpp - auto readTileDMG(bool select, uint x, uint y, uint16& tiledata) -> void; + auto readTileDMG(bool select, u32 x, u32 y, n16& tiledata) -> void; auto scanlineDMG() -> void; auto runDMG() -> void; auto runBackgroundDMG() -> void; @@ -58,7 +58,7 @@ struct PPU : Thread { auto runObjectsDMG() -> void; //cgb.cpp - auto readTileCGB(bool select, uint x, uint y, uint16& tiledata, uint8& attributes) -> void; + auto readTileCGB(bool select, u32 x, u32 y, n16& tiledata, n8& attributes) -> void; auto scanlineCGB() -> void; auto runCGB() -> void; auto runBackgroundCGB() -> void; @@ -66,8 +66,8 @@ struct PPU : Thread { auto runObjectsCGB() -> void; //color.cpp - auto colorGameBoy(uint32) -> uint64; - auto colorGameBoyColor(uint32) -> uint64; + auto colorGameBoy(n32) -> n64; + auto colorGameBoyColor(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; @@ -76,95 +76,95 @@ struct PPU : Thread { function run; struct Status { - uint1 irq; //STAT IRQ line - uint9 lx; //0~455 + n1 irq; //STAT IRQ line + n9 lx; //0~455 //$ff40 LCDC - uint1 bgEnable; //DMG: BG enable; CGB: BG priority - uint1 obEnable; - uint1 obSize; - uint1 bgTilemapSelect; - uint1 bgTiledataSelect; - uint1 windowDisplayEnable; - uint1 windowTilemapSelect; - uint1 displayEnable; + n1 bgEnable; //DMG: BG enable; CGB: BG priority + n1 obEnable; + n1 obSize; + n1 bgTilemapSelect; + n1 bgTiledataSelect; + n1 windowDisplayEnable; + n1 windowTilemapSelect; + n1 displayEnable; //$ff41 STAT - uint2 mode; //0 = Hblank, 1 = Vblank, 2 = OAM search, 3 = LCD transfer - uint1 interruptHblank; - uint1 interruptVblank; - uint1 interruptOAM; - uint1 interruptLYC; + n2 mode; //0 = Hblank, 1 = Vblank, 2 = OAM search, 3 = LCD transfer + n1 interruptHblank; + n1 interruptVblank; + n1 interruptOAM; + n1 interruptLYC; //$ff42 SCY - uint8 scy; + n8 scy; //$ff43 SCX - uint8 scx; + n8 scx; //$ff44 LY - uint8 ly; + n8 ly; //$ff45 LYC - uint8 lyc; + n8 lyc; //$ff46 DMA - uint8 dmaBank; - uint1 dmaActive; - uint10 dmaClock; //0~323 (DMG), 0~645 (CGB) + n8 dmaBank; + n1 dmaActive; + n10 dmaClock; //0~323 (DMG), 0~645 (CGB) //$ff4a WY - uint8 wy; + n8 wy; //$ff4b WX - uint8 wx; + n8 wx; //$ff4f VBK - uint1 vramBank; + n1 vramBank; //$ff68 BGPI - uint6 bgpi; - uint1 bgpiIncrement; + n6 bgpi; + n1 bgpiIncrement; //$ff6a OBPI - uint8 obpi; - uint1 obpiIncrement; + n8 obpi; + n1 obpiIncrement; } status; struct Latch { - uint1 displayEnable; - uint1 windowDisplayEnable; - uint8 wx; - uint8 wy; + n1 displayEnable; + n1 windowDisplayEnable; + n8 wx; + n8 wy; } latch; struct History { - uint10 mode; //5 x 2-bit + n10 mode; //5 x 2-bit } history; struct Pixel { - uint15 color; - uint8 palette; - uint1 priority; + n15 color; + n8 palette; + n1 priority; }; Pixel bg; Pixel ob; struct Sprite { - int16 x; - int16 y; - uint8 tile; - uint8 attributes; - uint16 tiledata; + i16 x; + i16 y; + n8 tile; + n8 attributes; + n16 tiledata; }; Sprite sprite[10]; - uint4 sprites; //0-9 + n4 sprites; //0-9 - uint8 px; //0-159 + n8 px; //0-159 struct Background { - uint8 attributes; - uint16 tiledata; + n8 attributes; + n16 tiledata; }; Background background; Background window; diff --git a/ares/gb/system/serialization.cpp b/ares/gb/system/serialization.cpp index 9872d263bf..5b266c882b 100644 --- a/ares/gb/system/serialization.cpp +++ b/ares/gb/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/gb/system/system.cpp b/ares/gb/system/system.cpp index 06dc99d239..985c6f3a08 100644 --- a/ares/gb/system/system.cpp +++ b/ares/gb/system/system.cpp @@ -2,7 +2,16 @@ namespace ares::GameBoy { +auto enumerate() -> vector { + return { + "[Nintendo] Game Boy", + "[Nintendo] Game Boy Color", + "[Nintendo] Super Game Boy", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -24,8 +33,8 @@ auto System::run() -> void { scheduler.enter(); } -auto System::clocksExecuted() -> uint { - uint clocks = information.clocksExecuted; +auto System::clocksExecuted() -> u32 { + u32 clocks = information.clocksExecuted; information.clocksExecuted = 0; return clocks; } @@ -34,10 +43,21 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "Game Boy" || name == "Game Boy Color") { - if(name == "Game Boy") information.model = Model::GameBoy; - if(name == "Game Boy Color") information.model = Model::GameBoyColor; - node = Node::System::create(name); + if(name.find("Game Boy")) { + information.name = "Game Boy"; + information.model = Model::GameBoy; + } + if(name.find("Game Boy Color")) { + information.name = "Game Boy Color"; + information.model = Model::GameBoyColor; + } + if(name.find("Super Game Boy")) { + information.name = "Super Game Boy"; + information.model = Model::SuperGameBoy; + } + + if(information.name == "Game Boy" || information.name == "Game Boy Color") { + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -48,8 +68,7 @@ auto System::load(Node::System& root, string name) -> bool { root = node; fastBoot = node->append("Fast Boot", false); } - if(name == "Super Game Boy") { - information.model = Model::SuperGameBoy; + if(information.name == "Super Game Boy") { node = root; } diff --git a/ares/gb/system/system.hpp b/ares/gb/system/system.hpp index 0febcc117a..a2348b6acd 100644 --- a/ares/gb/system/system.hpp +++ b/ares/gb/system/system.hpp @@ -25,21 +25,21 @@ struct System { bool rightLatch = 0; } controls; - enum class Model : uint { + enum class Model : u32 { GameBoy, GameBoyColor, SuperGameBoy, }; - Memory::Readable bootROM; + Memory::Readable bootROM; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } - auto clocksExecuted() const -> uint { return information.clocksExecuted; } + auto clocksExecuted() const -> u32 { return information.clocksExecuted; } //system.cpp auto game() -> string; auto run() -> void; - auto clocksExecuted() -> uint; + auto clocksExecuted() -> u32; auto load(Node::System& node, string name) -> bool; auto unload() -> void; @@ -51,8 +51,9 @@ struct System { auto unserialize(serializer&) -> bool; struct Information { + string name = "Game Boy"; Model model = Model::GameBoy; - uint32 clocksExecuted; + n32 clocksExecuted; } information; //serialization.cpp diff --git a/ares/gba/apu/apu.cpp b/ares/gba/apu/apu.cpp index e9e40f1065..924ac1d56e 100644 --- a/ares/gba/apu/apu.cpp +++ b/ares/gba/apu/apu.cpp @@ -43,8 +43,8 @@ auto APU::main() -> void { //always run the output frequency at the maximum 262144hz if(++clock & 7) return; - int lsample = bias.level - 0x0200; - int rsample = bias.level - 0x0200; + s32 lsample = bias.level - 0x0200; + s32 rsample = bias.level - 0x0200; //amplitude: 0 = 32768hz; 1 = 65536hz; 2 = 131072hz; 3 = 262144hz if((clock & (63 >> (3 - bias.amplitude))) == 0) { @@ -56,8 +56,8 @@ auto APU::main() -> void { lsample += sequencer.loutput; rsample += sequencer.routput; - int fifo0 = fifo[0].output << fifo[0].volume; - int fifo1 = fifo[1].output << fifo[1].volume; + s32 fifo0 = fifo[0].output << fifo[0].volume; + s32 fifo1 = fifo[1].output << fifo[1].volume; if(fifo[0].lenable) lsample += fifo0; if(fifo[1].lenable) lsample += fifo1; @@ -79,7 +79,7 @@ auto APU::main() -> void { stream->frame((lsample << 5) / 32768.0, (rsample << 5) / 32768.0); } -auto APU::step(uint clocks) -> void { +auto APU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -97,7 +97,7 @@ auto APU::power() -> void { fifo[0].power(); fifo[1].power(); - for(uint n = 0x060; n <= 0x0a7; n++) bus.io[n] = this; + for(u32 n = 0x060; n <= 0x0a7; n++) bus.io[n] = this; } } diff --git a/ares/gba/apu/apu.hpp b/ares/gba/apu/apu.hpp index 127caa6f18..471b40166c 100644 --- a/ares/gba/apu/apu.hpp +++ b/ares/gba/apu/apu.hpp @@ -7,10 +7,10 @@ struct APU : Thread, IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; - auto readIO(uint32 address) -> uint8; - auto writeIO(uint32 address, uint8 byte) -> void; + auto readIO(n32 address) -> n8; + auto writeIO(n32 address, n8 byte) -> void; auto power() -> void; //sequencer.cpp @@ -19,31 +19,31 @@ struct APU : Thread, IO { //serialization.cpp auto serialize(serializer&) -> void; - uint clock; + u32 clock; struct Bias { - uint10 level = 0x200; - uint2 amplitude = 0; + n10 level = 0x200; + n2 amplitude = 0; } bias; struct Sweep { - uint3 shift; - uint1 direction; - uint3 frequency; + n3 shift; + n1 direction; + n3 frequency; - uint1 enable; - uint1 negate; - uint3 period; + n1 enable; + n1 negate; + n3 period; }; struct Envelope { auto dacEnable() const -> bool { return volume || direction; } - uint3 frequency; - uint1 direction; - uint4 volume; + n3 frequency; + n1 direction; + n4 volume; - uint3 period; + n3 period; }; struct Square { @@ -54,27 +54,27 @@ struct APU : Thread, IO { Envelope envelope; - uint1 enable; - uint6 length; - uint2 duty; - uint11 frequency; - uint1 counter; - uint1 initialize; - - int32 shadowfrequency; - uint1 signal; - uint4 output; - uint32 period; - uint3 phase; - uint4 volume; + n1 enable; + n6 length; + n2 duty; + n11 frequency; + n1 counter; + n1 initialize; + + i32 shadowfrequency; + n1 signal; + n4 output; + n32 period; + n3 phase; + n4 volume; }; struct Square1 : Square { //square1.cpp auto runSweep(bool update) -> void; auto clockSweep() -> void; - auto read(uint addr) const -> uint8; - auto write(uint addr, uint8 byte) -> void; + auto read(u32 address) const -> n8; + auto write(u32 address, n8 byte) -> void; auto power() -> void; Sweep sweep; @@ -82,8 +82,8 @@ struct APU : Thread, IO { struct Square2 : Square { //square2.cpp - auto read(uint addr) const -> uint8; - auto write(uint addr, uint8 byte) -> void; + auto read(u32 address) const -> n8; + auto write(u32 address, n8 byte) -> void; auto power() -> void; } square2; @@ -91,100 +91,100 @@ struct APU : Thread, IO { //wave.cpp auto run() -> void; auto clockLength() -> void; - auto read(uint addr) const -> uint8; - auto write(uint addr, uint8 byte) -> void; - auto readRAM(uint addr) const -> uint8; - auto writeRAM(uint addr, uint8 byte) -> void; + auto read(u32 address) const -> n8; + auto write(u32 address, n8 byte) -> void; + auto readRAM(u32 address) const -> n8; + auto writeRAM(u32 address, n8 byte) -> void; auto power() -> void; - uint1 mode; - uint1 bank; - uint1 dacenable; - uint8 length; - uint3 volume; - uint11 frequency; - uint1 counter; - uint1 initialize; - uint4 pattern[2 * 32]; - - uint1 enable; - uint4 output; - uint5 patternaddr; - uint1 patternbank; - uint4 patternsample; - uint32 period; + n1 mode; + n1 bank; + n1 dacenable; + n8 length; + n3 volume; + n11 frequency; + n1 counter; + n1 initialize; + n4 pattern[2 * 32]; + + n1 enable; + n4 output; + n5 patternaddr; + n1 patternbank; + n4 patternsample; + n32 period; } wave; struct Noise { //noise.cpp - auto divider() const -> uint; + auto divider() const -> u32; auto run() -> void; auto clockLength() -> void; auto clockEnvelope() -> void; - auto read(uint addr) const -> uint8; - auto write(uint addr, uint8 byte) -> void; + auto read(u32 address) const -> n8; + auto write(u32 address, n8 byte) -> void; auto power() -> void; Envelope envelope; - uint6 length; - uint3 divisor; - uint1 narrowlfsr; - uint4 frequency; - uint1 counter; - uint1 initialize; - - uint1 enable; - uint15 lfsr; - uint4 output; - uint32 period; - uint4 volume; + n6 length; + n3 divisor; + n1 narrowlfsr; + n4 frequency; + n1 counter; + n1 initialize; + + n1 enable; + n15 lfsr; + n4 output; + n32 period; + n4 volume; } noise; struct Sequencer { //sequencer.cpp auto sample() -> void; - auto read(uint addr) const -> uint8; - auto write(uint addr, uint8 byte) -> void; + auto read(u32 address) const -> n8; + auto write(u32 address, n8 byte) -> void; auto power() -> void; - uint2 volume; - uint3 lvolume; - uint3 rvolume; - uint1 lenable[4]; - uint1 renable[4]; - uint1 masterenable; + n2 volume; + n3 lvolume; + n3 rvolume; + n1 lenable[4]; + n1 renable[4]; + n1 masterenable; - uint12 base; - uint3 step; - int16 lsample; - int16 rsample; + n12 base; + n3 step; + i16 lsample; + i16 rsample; - uint10 loutput; - uint10 routput; + n10 loutput; + n10 routput; } sequencer; struct FIFO { //fifo.cpp auto sample() -> void; auto read() -> void; - auto write(int8 byte) -> void; + auto write(i8 byte) -> void; auto reset() -> void; auto power() -> void; - int8 samples[32]; - int8 active; - int8 output; + i8 samples[32]; + i8 active; + i8 output; - uint5 rdoffset; - uint5 wroffset; - uint6 size; + n5 rdoffset; + n5 wroffset; + n6 size; - uint1 volume; //0 = 50%, 1 = 100% - uint1 lenable; - uint1 renable; - uint1 timer; + n1 volume; //0 = 50%, 1 = 100% + n1 lenable; + n1 renable; + n1 timer; } fifo[2]; }; diff --git a/ares/gba/apu/fifo.cpp b/ares/gba/apu/fifo.cpp index 641abc3c3f..a4487baa60 100644 --- a/ares/gba/apu/fifo.cpp +++ b/ares/gba/apu/fifo.cpp @@ -8,7 +8,7 @@ auto APU::FIFO::read() -> void { active = samples[rdoffset++]; } -auto APU::FIFO::write(int8 byte) -> void { +auto APU::FIFO::write(i8 byte) -> void { if(size == 32) rdoffset++; else size++; samples[wroffset++] = byte; diff --git a/ares/gba/apu/io.cpp b/ares/gba/apu/io.cpp index cfc4b4fa9c..2f08a17d5d 100644 --- a/ares/gba/apu/io.cpp +++ b/ares/gba/apu/io.cpp @@ -1,4 +1,4 @@ -auto APU::readIO(uint32 address) -> uint8 { +auto APU::readIO(n32 address) -> n8 { switch(address) { //NR10 @@ -140,7 +140,7 @@ auto APU::readIO(uint32 address) -> uint8 { return cpu.pipeline.fetch.instruction.byte(address & 1); } -auto APU::writeIO(uint32 address, uint8 data) -> void { +auto APU::writeIO(n32 address, n8 data) -> void { switch(address) { //NR10 diff --git a/ares/gba/apu/noise.cpp b/ares/gba/apu/noise.cpp index e797a6c446..7061736e4c 100644 --- a/ares/gba/apu/noise.cpp +++ b/ares/gba/apu/noise.cpp @@ -1,4 +1,4 @@ -auto APU::Noise::divider() const -> uint { +auto APU::Noise::divider() const -> u32 { if(divisor == 0) return 4; return divisor * 8; } @@ -30,7 +30,7 @@ auto APU::Noise::clockEnvelope() -> void { } } -auto APU::Noise::read(uint addr) const -> uint8 { +auto APU::Noise::read(u32 addr) const -> n8 { switch(addr) { case 1: return 0; case 2: return (envelope.frequency << 0) | (envelope.direction << 3) | (envelope.volume << 4); @@ -40,7 +40,7 @@ auto APU::Noise::read(uint addr) const -> uint8 { return 0; } -auto APU::Noise::write(uint addr, uint8 byte) -> void { +auto APU::Noise::write(u32 addr, n8 byte) -> void { switch(addr) { case 1: //NR41 length = byte >> 0; diff --git a/ares/gba/apu/sequencer.cpp b/ares/gba/apu/sequencer.cpp index e76dc5743e..8556563011 100644 --- a/ares/gba/apu/sequencer.cpp +++ b/ares/gba/apu/sequencer.cpp @@ -48,7 +48,7 @@ auto APU::Sequencer::sample() -> void { routput >>= 3 - volume; } -auto APU::Sequencer::read(uint addr) const -> uint8 { +auto APU::Sequencer::read(u32 addr) const -> n8 { switch(addr) { case 0: return (rvolume << 0) | (lvolume << 4); case 1: return ( @@ -72,7 +72,7 @@ auto APU::Sequencer::read(uint addr) const -> uint8 { return 0; } -auto APU::Sequencer::write(uint addr, uint8 byte) -> void { +auto APU::Sequencer::write(u32 addr, n8 byte) -> void { switch(addr) { case 0: //NR50 rvolume = byte >> 0; diff --git a/ares/gba/apu/square.cpp b/ares/gba/apu/square.cpp index 31e515478d..922b3bcf21 100644 --- a/ares/gba/apu/square.cpp +++ b/ares/gba/apu/square.cpp @@ -10,7 +10,7 @@ auto APU::Square::run() -> void { } } - uint4 sample = volume; + n4 sample = volume; if(enable == false || signal == false) sample = 0; output = sample; } diff --git a/ares/gba/apu/square1.cpp b/ares/gba/apu/square1.cpp index 3e484fdfc5..cae0cf4272 100644 --- a/ares/gba/apu/square1.cpp +++ b/ares/gba/apu/square1.cpp @@ -2,8 +2,8 @@ auto APU::Square1::runSweep(bool update) -> void { if(!sweep.enable) return; sweep.negate = sweep.direction; - uint delta = shadowfrequency >> sweep.shift; - int updatefrequency = shadowfrequency + (sweep.negate ? -delta : delta); + u32 delta = shadowfrequency >> sweep.shift; + s32 updatefrequency = shadowfrequency + (sweep.negate ? -delta : delta); if(updatefrequency > 2047) { enable = false; @@ -22,7 +22,7 @@ auto APU::Square1::clockSweep() -> void { } } -auto APU::Square1::read(uint addr) const -> uint8 { +auto APU::Square1::read(u32 addr) const -> n8 { switch(addr) { case 0: return (sweep.shift << 0) | (sweep.direction << 3) | (sweep.frequency << 4); case 1: return (duty << 6); @@ -33,7 +33,7 @@ auto APU::Square1::read(uint addr) const -> uint8 { return 0; } -auto APU::Square1::write(uint addr, uint8 byte) -> void { +auto APU::Square1::write(u32 addr, n8 byte) -> void { switch(addr) { case 0: //NR10 if(sweep.negate && sweep.direction && !(byte & 0x08)) enable = false; diff --git a/ares/gba/apu/square2.cpp b/ares/gba/apu/square2.cpp index acbb1dec63..6849a64ac2 100644 --- a/ares/gba/apu/square2.cpp +++ b/ares/gba/apu/square2.cpp @@ -1,4 +1,4 @@ -auto APU::Square2::read(uint addr) const -> uint8 { +auto APU::Square2::read(u32 addr) const -> n8 { switch(addr) { case 1: return (duty << 6); case 2: return (envelope.frequency << 0) | (envelope.direction << 3) | (envelope.volume << 4); @@ -8,7 +8,7 @@ auto APU::Square2::read(uint addr) const -> uint8 { return 0; } -auto APU::Square2::write(uint addr, uint8 byte) -> void { +auto APU::Square2::write(u32 addr, n8 byte) -> void { switch(addr) { case 1: //NR21 length = byte >> 0; diff --git a/ares/gba/apu/wave.cpp b/ares/gba/apu/wave.cpp index ce1d1d3fbf..7f0b127903 100644 --- a/ares/gba/apu/wave.cpp +++ b/ares/gba/apu/wave.cpp @@ -6,7 +6,7 @@ auto APU::Wave::run() -> void { } output = patternsample; - static uint multiplier[] = {0, 4, 2, 1, 3, 3, 3, 3}; + static u32 multiplier[] = {0, 4, 2, 1, 3, 3, 3, 3}; output = (output * multiplier[volume]) / 4; if(enable == false) output = 0; } @@ -17,7 +17,7 @@ auto APU::Wave::clockLength() -> void { } } -auto APU::Wave::read(uint addr) const -> uint8 { +auto APU::Wave::read(u32 addr) const -> n8 { switch(addr) { case 0: return (mode << 5) | (bank << 6) | (dacenable << 7); case 1: return 0; @@ -28,7 +28,7 @@ auto APU::Wave::read(uint addr) const -> uint8 { return 0; } -auto APU::Wave::write(uint addr, uint8 byte) -> void { +auto APU::Wave::write(u32 addr, n8 byte) -> void { switch(addr) { case 0: //NR30 mode = byte >> 5; @@ -58,21 +58,21 @@ auto APU::Wave::write(uint addr, uint8 byte) -> void { enable = dacenable; period = 1 * (2048 - frequency); patternaddr = 0; - patternbank = mode ? (uint1)0 : bank; + patternbank = mode ? (n1)0 : bank; } break; } } -auto APU::Wave::readRAM(uint addr) const -> uint8 { - uint8 byte = 0; +auto APU::Wave::readRAM(u32 addr) const -> n8 { + n8 byte = 0; byte |= pattern[!bank << 5 | addr << 1 | 0] << 4; byte |= pattern[!bank << 5 | addr << 1 | 1] << 0; return byte; } -auto APU::Wave::writeRAM(uint addr, uint8 byte) -> void { +auto APU::Wave::writeRAM(u32 addr, n8 byte) -> void { pattern[!bank << 5 | addr << 1 | 0] = byte >> 4; pattern[!bank << 5 | addr << 1 | 1] = byte >> 0; } diff --git a/ares/gba/cartridge/cartridge.cpp b/ares/gba/cartridge/cartridge.cpp index f21b497ddf..4933f28a3e 100644 --- a/ares/gba/cartridge/cartridge.cpp +++ b/ares/gba/cartridge/cartridge.cpp @@ -11,10 +11,10 @@ Cartridge& cartridge = cartridgeSlot.cartridge; #include "serialization.cpp" Cartridge::Cartridge() { - mrom.data = new uint8[mrom.size = 32 * 1024 * 1024]; - sram.data = new uint8[sram.size = 32 * 1024]; - eeprom.data = new uint8[eeprom.size = 8 * 1024]; - flash.data = new uint8[flash.size = 128 * 1024]; + mrom.data = new n8[mrom.size = 32 * 1024 * 1024]; + sram.data = new n8[sram.size = 32 * 1024]; + eeprom.data = new n8[eeprom.size = 8 * 1024]; + flash.data = new n8[flash.size = 128 * 1024]; } Cartridge::~Cartridge() { @@ -99,10 +99,10 @@ auto Cartridge::connect() -> void { auto Cartridge::disconnect() -> void { if(!node) return; - memory::fill(mrom.data, mrom.size); - memory::fill(sram.data, sram.size); - memory::fill(eeprom.data, eeprom.size); - memory::fill(flash.data, flash.size); + memory::fill(mrom.data, mrom.size); + memory::fill(sram.data, sram.size); + memory::fill(eeprom.data, eeprom.size); + memory::fill(flash.data, flash.size); has = {}; node = {}; } @@ -139,7 +139,7 @@ auto Cartridge::power() -> void { #define RAM_ANALYZE -auto Cartridge::read(uint mode, uint32 address) -> uint32 { +auto Cartridge::read(u32 mode, n32 address) -> n32 { if(address < 0x0e00'0000) { if(has.eeprom && (address & eeprom.mask) == eeprom.test) return eeprom.read(); return mrom.read(mode, address); @@ -150,7 +150,7 @@ auto Cartridge::read(uint mode, uint32 address) -> uint32 { } } -auto Cartridge::write(uint mode, uint32 address, uint32 word) -> void { +auto Cartridge::write(u32 mode, n32 address, n32 word) -> void { if(address < 0x0e00'0000) { if(has.eeprom && (address & eeprom.mask) == eeprom.test) return eeprom.write(word & 1); return mrom.write(mode, address, word); diff --git a/ares/gba/cartridge/cartridge.hpp b/ares/gba/cartridge/cartridge.hpp index 9023f25eee..4122ba05f0 100644 --- a/ares/gba/cartridge/cartridge.hpp +++ b/ares/gba/cartridge/cartridge.hpp @@ -17,8 +17,8 @@ struct Cartridge { auto save() -> void; auto power() -> void; - auto read(uint mode, uint32 address) -> uint32; - auto write(uint mode, uint32 address, uint32 word) -> void; + auto read(u32 mode, n32 address) -> n32; + auto write(u32 mode, n32 address, n32 word) -> void; auto serialize(serializer&) -> void; @@ -29,9 +29,9 @@ struct Cartridge { } information; struct Has { - uint1 sram; - uint1 eeprom; - uint1 flash; + n1 sram; + n1 eeprom; + n1 flash; } has; }; diff --git a/ares/gba/cartridge/eeprom.cpp b/ares/gba/cartridge/eeprom.cpp index d3264f1c26..0a8902e331 100644 --- a/ares/gba/cartridge/eeprom.cpp +++ b/ares/gba/cartridge/eeprom.cpp @@ -1,8 +1,8 @@ -auto Cartridge::EEPROM::read(uint address) -> bool { +auto Cartridge::EEPROM::read(u32 address) -> bool { return data[address >> 3] & 0x80 >> (address & 7); } -auto Cartridge::EEPROM::write(uint address, bool bit) -> void { +auto Cartridge::EEPROM::write(u32 address, bool bit) -> void { if(bit == 0) data[address >> 3] &=~ (0x80 >> (address & 7)); if(bit == 1) data[address >> 3] |= (0x80 >> (address & 7)); } diff --git a/ares/gba/cartridge/flash.cpp b/ares/gba/cartridge/flash.cpp index e7dcda1ca7..cdf0de8335 100644 --- a/ares/gba/cartridge/flash.cpp +++ b/ares/gba/cartridge/flash.cpp @@ -7,7 +7,7 @@ //0x1362 128KB 32x4096 Sanyo //0x09c2 128KB 32x4096 Macronix -auto Cartridge::FLASH::read(uint16 address) -> uint8 { +auto Cartridge::FLASH::read(n16 address) -> n8 { if(idmode) { if(address == 0x0000) return id >> 0; if(address == 0x0001) return id >> 8; @@ -17,7 +17,7 @@ auto Cartridge::FLASH::read(uint16 address) -> uint8 { return data[bank << 16 | address]; } -auto Cartridge::FLASH::write(uint16 address, uint8 byte) -> void { +auto Cartridge::FLASH::write(n16 address, n8 byte) -> void { if(bankselect) { bankselect = false; //bank select is only applicable on 128KB chips @@ -42,7 +42,7 @@ auto Cartridge::FLASH::write(uint16 address, uint8 byte) -> void { if(byte == 0x10 && address == 0x5555) { if(erasemode) { erasemode = false; - for(uint n : range(size)) data[n] = 0xff; + for(u32 n : range(size)) data[n] = 0xff; } } @@ -50,8 +50,8 @@ auto Cartridge::FLASH::write(uint16 address, uint8 byte) -> void { //command only valid for non-Atmel chips if(erasemode && id != 0x3d1f) { erasemode = false; - uint offset = bank << 16 | (address & ~4095); - for(uint n : range(4096)) data[offset++] = 0xff; + u32 offset = bank << 16 | (address & ~4095); + for(u32 n : range(4096)) data[offset++] = 0xff; } } diff --git a/ares/gba/cartridge/memory.hpp b/ares/gba/cartridge/memory.hpp index 34f22047dc..265058da40 100644 --- a/ares/gba/cartridge/memory.hpp +++ b/ares/gba/cartridge/memory.hpp @@ -1,33 +1,33 @@ struct MROM { //mrom.cpp - auto read(uint mode, uint32 address) -> uint32; - auto write(uint mode, uint32 address, uint32 word) -> void; + auto read(u32 mode, n32 address) -> n32; + auto write(u32 mode, n32 address, n32 word) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8* data = nullptr; - uint size; - uint mask; + n8* data = nullptr; + u32 size; + u32 mask; } mrom; struct SRAM { //sram.cpp - auto read(uint mode, uint32 address) -> uint32; - auto write(uint mode, uint32 address, uint32 word) -> void; + auto read(u32 mode, n32 address) -> n32; + auto write(u32 mode, n32 address, n32 word) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8* data = nullptr; - uint size; - uint mask; + n8* data = nullptr; + u32 size; + u32 mask; } sram; struct EEPROM { //eeprom.cpp - auto read(uint address) -> bool; - auto write(uint address, bool bit) -> void; + auto read(u32 address) -> bool; + auto write(u32 address, bool bit) -> void; auto read() -> bool; auto write(bool bit) -> void; @@ -36,35 +36,35 @@ struct EEPROM { //serialization.cpp auto serialize(serializer&) -> void; - uint8* data = nullptr; - uint size; - uint mask; - uint test; - uint bits; + n8* data = nullptr; + u32 size; + u32 mask; + u32 test; + u32 bits; - enum class Mode : uint { + enum class Mode : u32 { Wait, Command, ReadAddress, ReadValidate, ReadData, WriteAddress, WriteData, WriteValidate } mode; - uint offset; - uint address; - uint addressbits; + u32 offset; + u32 address; + u32 addressbits; } eeprom; struct FLASH { //flash.cpp - auto read(uint16 address) -> uint8; - auto write(uint16 address, uint8 byte) -> void; + auto read(n16 address) -> n8; + auto write(n16 address, n8 byte) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8* data = nullptr; - uint size; + n8* data = nullptr; + u32 size; string manufacturer; - uint16 id; + n16 id; bool unlockhi; bool unlocklo; diff --git a/ares/gba/cartridge/mrom.cpp b/ares/gba/cartridge/mrom.cpp index 15e1013ff1..baf041c86c 100644 --- a/ares/gba/cartridge/mrom.cpp +++ b/ares/gba/cartridge/mrom.cpp @@ -1,13 +1,13 @@ -auto Cartridge::MROM::read(uint mode, uint32 address) -> uint32 { +auto Cartridge::MROM::read(u32 mode, n32 address) -> n32 { if(mode & Word) { - uint32 word = 0; + n32 word = 0; word |= read(mode & ~Word | Half, (address & ~3) + 0) << 0; word |= read(mode & ~Word | Half, (address & ~3) + 2) << 16; return word; } address &= 0x01ff'ffff; - if(address >= size) return (uint16)(address >> 1); + if(address >= size) return (n16)(address >> 1); if(mode & Half) address &= ~1; auto p = data + address; @@ -16,5 +16,5 @@ auto Cartridge::MROM::read(uint mode, uint32 address) -> uint32 { return 0; //should never occur } -auto Cartridge::MROM::write(uint mode, uint32 address, uint32 word) -> void { +auto Cartridge::MROM::write(u32 mode, n32 address, n32 word) -> void { } diff --git a/ares/gba/cartridge/serialization.cpp b/ares/gba/cartridge/serialization.cpp index b3a4f80f13..5f351d7e5e 100644 --- a/ares/gba/cartridge/serialization.cpp +++ b/ares/gba/cartridge/serialization.cpp @@ -11,25 +11,25 @@ auto Cartridge::MROM::serialize(serializer& s) -> void { } auto Cartridge::SRAM::serialize(serializer& s) -> void { - s(array_span{data, size}); + s(array_span{data, size}); s(size); s(mask); } auto Cartridge::EEPROM::serialize(serializer& s) -> void { - s(array_span{data, size}); + s(array_span{data, size}); s(size); s(mask); s(test); s(bits); - s((uint&)mode); + s((u32&)mode); s(offset); s(address); s(addressbits); } auto Cartridge::FLASH::serialize(serializer& s) -> void { - s(array_span{data, size}); + s(array_span{data, size}); s(size); s(id); s(unlockhi); diff --git a/ares/gba/cartridge/sram.cpp b/ares/gba/cartridge/sram.cpp index 6706f4e12b..0a29ec916d 100644 --- a/ares/gba/cartridge/sram.cpp +++ b/ares/gba/cartridge/sram.cpp @@ -1,10 +1,10 @@ -auto Cartridge::SRAM::read(uint mode, uint32 address) -> uint32 { - uint32 word = data[address & mask]; +auto Cartridge::SRAM::read(u32 mode, n32 address) -> n32 { + n32 word = data[address & mask]; word |= word << 8; word |= word << 16; return word; } -auto Cartridge::SRAM::write(uint mode, uint32 address, uint32 word) -> void { +auto Cartridge::SRAM::write(u32 mode, n32 address, n32 word) -> void { data[address & mask] = word; } diff --git a/ares/gba/cpu/bus.cpp b/ares/gba/cpu/bus.cpp index e66339c6e5..5f551b6af8 100644 --- a/ares/gba/cpu/bus.cpp +++ b/ares/gba/cpu/bus.cpp @@ -2,9 +2,9 @@ auto CPU::sleep() -> void { prefetchStep(1); } -auto CPU::get(uint mode, uint32 addr) -> uint32 { - uint clocks = _wait(mode, addr); - uint word = pipeline.fetch.instruction; +auto CPU::get(u32 mode, n32 addr) -> n32 { + u32 clocks = _wait(mode, addr); + u32 word = pipeline.fetch.instruction; if(context.dmaActive) word = dmabus.data; if(addr >= 0x1000'0000) { @@ -35,8 +35,8 @@ auto CPU::get(uint mode, uint32 addr) -> uint32 { return word; } -auto CPU::set(uint mode, uint32 addr, uint32 word) -> void { - uint clocks = _wait(mode, addr); +auto CPU::set(u32 mode, n32 addr, n32 word) -> void { + u32 clocks = _wait(mode, addr); if(addr >= 0x1000'0000) { prefetchStep(clocks); @@ -57,7 +57,7 @@ auto CPU::set(uint mode, uint32 addr, uint32 word) -> void { } } -auto CPU::_wait(uint mode, uint32 addr) -> uint { +auto CPU::_wait(u32 mode, n32 addr) -> u32 { if(addr >= 0x1000'0000) return 1; //unmapped if(addr < 0x0200'0000) return 1; if(addr < 0x0300'0000) return (16 - memory.ewramWait) * (mode & Word ? 2 : 1); @@ -65,9 +65,9 @@ auto CPU::_wait(uint mode, uint32 addr) -> uint { if(addr < 0x0700'0000) return mode & Word ? 2 : 1; if(addr < 0x0800'0000) return 1; - static uint timings[] = {5, 4, 3, 9}; - uint n = timings[wait.nwait[addr >> 25 & 3]]; - uint s = wait.swait[addr >> 25 & 3]; + static u32 timings[] = {5, 4, 3, 9}; + u32 n = timings[wait.nwait[addr >> 25 & 3]]; + u32 s = wait.swait[addr >> 25 & 3]; switch(addr & 0x0e00'0000) { case 0x0800'0000: s = s ? 2 : 3; break; @@ -79,7 +79,7 @@ auto CPU::_wait(uint mode, uint32 addr) -> uint { bool sequential = (mode & Sequential); if((addr & 0x1fffe) == 0) sequential = false; //N cycle on 16-bit ROM crossing 128KB page boundary (RAM S==N) - uint clocks = sequential ? s : n; + u32 clocks = sequential ? s : n; if(mode & Word) clocks += s; //16-bit bus requires two transfers for words return clocks; } diff --git a/ares/gba/cpu/cpu.cpp b/ares/gba/cpu/cpu.cpp index 98da73f9ae..4d4f54f364 100644 --- a/ares/gba/cpu/cpu.cpp +++ b/ares/gba/cpu/cpu.cpp @@ -51,13 +51,13 @@ auto CPU::main() -> void { instruction(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { if(!clocks) return; - dma[0].waiting = max(0, dma[0].waiting - (int)clocks); - dma[1].waiting = max(0, dma[1].waiting - (int)clocks); - dma[2].waiting = max(0, dma[2].waiting - (int)clocks); - dma[3].waiting = max(0, dma[3].waiting - (int)clocks); + dma[0].waiting = max(0, dma[0].waiting - (s32)clocks); + dma[1].waiting = max(0, dma[1].waiting - (s32)clocks); + dma[2].waiting = max(0, dma[2].waiting - (s32)clocks); + dma[3].waiting = max(0, dma[3].waiting - (s32)clocks); if(!context.dmaActive) { context.dmaActive = true; @@ -75,7 +75,7 @@ auto CPU::step(uint clocks) -> void { #if defined(PROFILE_PERFORMANCE) //20% speedup by only synchronizing other components every 64 clock cycles - static uint counter = 0; + static u32 counter = 0; counter += clocks; if(counter < 64) return; clocks = counter; @@ -122,13 +122,13 @@ auto CPU::power() -> void { dma[3].target.setBits(28); dma[3].latch.target.setBits(28); dma[3].length.setBits(16); dma[3].latch.length.setBits(16); - for(uint n = 0x0b0; n <= 0x0df; n++) bus.io[n] = this; //DMA - for(uint n = 0x100; n <= 0x10f; n++) bus.io[n] = this; //Timers - for(uint n = 0x120; n <= 0x12b; n++) bus.io[n] = this; //Serial - for(uint n = 0x130; n <= 0x133; n++) bus.io[n] = this; //Keypad - for(uint n = 0x134; n <= 0x159; n++) bus.io[n] = this; //Serial - for(uint n = 0x200; n <= 0x209; n++) bus.io[n] = this; //System - for(uint n = 0x300; n <= 0x301; n++) bus.io[n] = this; //System + for(u32 n = 0x0b0; n <= 0x0df; n++) bus.io[n] = this; //DMA + for(u32 n = 0x100; n <= 0x10f; n++) bus.io[n] = this; //Timers + for(u32 n = 0x120; n <= 0x12b; n++) bus.io[n] = this; //Serial + for(u32 n = 0x130; n <= 0x133; n++) bus.io[n] = this; //Keypad + for(u32 n = 0x134; n <= 0x159; n++) bus.io[n] = this; //Serial + for(u32 n = 0x200; n <= 0x209; n++) bus.io[n] = this; //System + for(u32 n = 0x300; n <= 0x301; n++) bus.io[n] = this; //System //0x080-0x083 mirrored via gba/memory/memory.cpp //System } diff --git a/ares/gba/cpu/cpu.hpp b/ares/gba/cpu/cpu.hpp index b7cd8b8e2a..1b53bdb786 100644 --- a/ares/gba/cpu/cpu.hpp +++ b/ares/gba/cpu/cpu.hpp @@ -1,7 +1,7 @@ struct CPU : ARM7TDMI, Thread, IO { Node::Object node; - Memory::Writable iwram; // 32KB - Memory::Writable ewram; //256KB + Memory::Writable iwram; // 32KB + Memory::Writable ewram; //256KB struct Debugger { //debugger.cpp @@ -20,7 +20,7 @@ struct CPU : ARM7TDMI, Thread, IO { } tracer; } debugger; - struct Interrupt { enum : uint { + struct Interrupt { enum : u32 { VBlank = 0x0001, HBlank = 0x0002, VCoincidence = 0x0004, @@ -37,7 +37,7 @@ struct CPU : ARM7TDMI, Thread, IO { Cartridge = 0x2000, };}; - auto clock() const -> uint { return context.clock; } + auto clock() const -> u32 { return context.clock; } auto halted() const -> bool { return context.halted; } auto stopped() const -> bool { return context.stopped; } @@ -46,30 +46,30 @@ struct CPU : ARM7TDMI, Thread, IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto power() -> void; //prefetch.cpp - auto prefetchSync(uint32 addr) -> void; - auto prefetchStep(uint clocks) -> void; + auto prefetchSync(n32 address) -> void; + auto prefetchStep(u32 clocks) -> void; auto prefetchWait() -> void; - auto prefetchRead() -> uint16; + auto prefetchRead() -> n16; //bus.cpp auto sleep() -> void override; - auto get(uint mode, uint32 addr) -> uint32 override; - auto set(uint mode, uint32 addr, uint32 word) -> void override; - auto _wait(uint mode, uint32 addr) -> uint; + auto get(u32 mode, n32 address) -> n32 override; + auto set(u32 mode, n32 address, n32 word) -> void override; + auto _wait(u32 mode, n32 address) -> u32; //io.cpp - auto readIO(uint32 addr) -> uint8; - auto writeIO(uint32 addr, uint8 byte) -> void; + auto readIO(n32 address) -> n8 override; + auto writeIO(n32 address, n8 byte) -> void override; - auto readIWRAM(uint mode, uint32 addr) -> uint32; - auto writeIWRAM(uint mode, uint32 addr, uint32 word) -> void; + auto readIWRAM(u32 mode, n32 address) -> n32; + auto writeIWRAM(u32 mode, n32 address, n32 word) -> void; - auto readEWRAM(uint mode, uint32 addr) -> uint32; - auto writeEWRAM(uint mode, uint32 addr, uint32 word) -> void; + auto readEWRAM(u32 mode, n32 address) -> n32; + auto writeEWRAM(u32 mode, n32 address, n32 word) -> void; //dma.cpp auto dmaVblank() -> void; @@ -77,23 +77,23 @@ struct CPU : ARM7TDMI, Thread, IO { auto dmaHDMA() -> void; //timer.cpp - auto runFIFO(uint n) -> void; + auto runFIFO(u32 n) -> void; //serialization.cpp auto serialize(serializer&) -> void; //private: struct uintVN { - auto operator()() const -> uint32 { return data & mask; } - auto setBits(uint bits) -> void { mask = (1 << bits) - 1; } + auto operator()() const -> n32 { return data & mask; } + auto setBits(u32 bits) -> void { mask = (1 << bits) - 1; } - uint32 data; - uint32 mask; + n32 data; + n32 mask; }; //DMA data bus shared between all DMA channels struct DMABus { - uint32 data; + n32 data; } dmabus; struct DMA { @@ -101,19 +101,19 @@ struct CPU : ARM7TDMI, Thread, IO { auto run() -> bool; auto transfer() -> void; - uint2 id; + n2 id; - uint1 active; - int32 waiting; + n1 active; + i32 waiting; - uint2 targetMode; - uint2 sourceMode; - uint1 repeat; - uint1 size; - uint1 drq; - uint2 timingMode; - uint1 irq; - uint1 enable; + n2 targetMode; + n2 sourceMode; + n1 repeat; + n1 size; + n1 drq; + n2 timingMode; + n1 irq; + n1 enable; uintVN source; uintVN target; @@ -131,104 +131,104 @@ struct CPU : ARM7TDMI, Thread, IO { auto run() -> void; auto step() -> void; - uint2 id; + n2 id; - uint1 pending; + n1 pending; - uint16 period; - uint16 reload; + n16 period; + n16 reload; - uint2 frequency; - uint1 cascade; - uint1 irq; - uint1 enable; + n2 frequency; + n1 cascade; + n1 irq; + n1 enable; } timer[4]; struct Serial { - uint1 shiftClockSelect; - uint1 shiftClockFrequency; - uint1 transferEnableReceive; - uint1 transferEnableSend; - uint1 startBit; - uint1 transferLength; - uint1 irqEnable; - - uint16 data[4]; - uint8 data8; + n1 shiftClockSelect; + n1 shiftClockFrequency; + n1 transferEnableReceive; + n1 transferEnableSend; + n1 startBit; + n1 transferLength; + n1 irqEnable; + + n16 data[4]; + n8 data8; } serial; struct Keypad { //keypad.cpp auto run() -> void; - uint1 enable; - uint1 condition; - uint1 flag[10]; + n1 enable; + n1 condition; + n1 flag[10]; } keypad; struct Joybus { - uint1 sc; - uint1 sd; - uint1 si; - uint1 so; - uint1 scMode; - uint1 sdMode; - uint1 siMode; - uint1 soMode; - uint1 siIRQEnable; - uint2 mode; - - uint1 resetSignal; - uint1 receiveComplete; - uint1 sendComplete; - uint1 resetIRQEnable; - - uint32 receive; - uint32 transmit; - - uint1 receiveFlag; - uint1 sendFlag; - uint2 generalFlag; + n1 sc; + n1 sd; + n1 si; + n1 so; + n1 scMode; + n1 sdMode; + n1 siMode; + n1 soMode; + n1 siIRQEnable; + n2 mode; + + n1 resetSignal; + n1 receiveComplete; + n1 sendComplete; + n1 resetIRQEnable; + + n32 receive; + n32 transmit; + + n1 receiveFlag; + n1 sendFlag; + n2 generalFlag; } joybus; struct IRQ { - uint1 ime; - uint16 enable; - uint16 flag; + n1 ime; + n16 enable; + n16 flag; } irq; struct Wait { - uint2 nwait[4]; - uint1 swait[4]; - uint2 phi; - uint1 prefetch; - uint1 gameType; + n2 nwait[4]; + n1 swait[4]; + n2 phi; + n1 prefetch; + n1 gameType; } wait; struct Memory { - uint1 disable; - uint3 unknown1; - uint1 ewram = 1; - uint4 ewramWait = 13; - uint4 unknown2; + n1 disable; + n3 unknown1; + n1 ewram = 1; + n4 ewramWait = 13; + n4 unknown2; } memory; struct { auto empty() const { return addr == load; } auto full() const { return load - addr == 16; } - uint16 slot[8]; - uint32 addr; //read location of slot buffer - uint32 load; //write location of slot buffer - int32 wait = 1; //number of clocks before next slot load + n16 slot[8]; + n32 addr; //read location of slot buffer + n32 load; //write location of slot buffer + i32 wait = 1; //number of clocks before next slot load } prefetch; struct Context { - uint32 clock; - uint1 halted; - uint1 stopped; - uint1 booted; //set to true by the GBA BIOS - uint1 dmaActive; + n32 clock; + n1 halted; + n1 stopped; + n1 booted; //set to true by the GBA BIOS + n1 dmaActive; } context; }; diff --git a/ares/gba/cpu/dma.cpp b/ares/gba/cpu/dma.cpp index bd4373c6e8..375f094227 100644 --- a/ares/gba/cpu/dma.cpp +++ b/ares/gba/cpu/dma.cpp @@ -8,8 +8,8 @@ inline auto CPU::DMA::run() -> bool { } auto CPU::DMA::transfer() -> void { - uint seek = size ? 4 : 2; - uint mode = size ? Word : Half; + u32 seek = size ? 4 : 2; + u32 mode = size ? Word : Half; mode |= latch.length() == length() ? Nonsequential : Sequential; if(mode & Nonsequential) { @@ -24,7 +24,7 @@ auto CPU::DMA::transfer() -> void { if(latch.source() < 0x0200'0000) { cpu.idle(); //cannot access BIOS } else { - uint32 addr = latch.source(); + n32 addr = latch.source(); if(mode & Word) addr &= ~3; if(mode & Half) addr &= ~1; cpu.dmabus.data = cpu.get(mode, addr); @@ -34,7 +34,7 @@ auto CPU::DMA::transfer() -> void { if(latch.target() < 0x0200'0000) { cpu.idle(); //cannot access BIOS } else { - uint32 addr = latch.target(); + n32 addr = latch.target(); if(mode & Word) addr &= ~3; if(mode & Half) addr &= ~1; cpu.set(mode, addr, cpu.dmabus.data); diff --git a/ares/gba/cpu/io.cpp b/ares/gba/cpu/io.cpp index 0c199c07c8..f4355bb2fe 100644 --- a/ares/gba/cpu/io.cpp +++ b/ares/gba/cpu/io.cpp @@ -1,4 +1,4 @@ -auto CPU::readIO(uint32 addr) -> uint8 { +auto CPU::readIO(n32 addr) -> n8 { auto dma = [&]() -> DMA& { return this->dma[addr / 12 & 3]; }; auto timer = [&]() -> Timer& { return this->timer[addr.bit(2,3)]; }; @@ -69,7 +69,7 @@ auto CPU::readIO(uint32 addr) -> uint8 { if(auto result = player.keyinput()) return result() >> 0; } system.controls.poll(); - uint8 result; + n8 result; result.bit(0) = !system.controls.a->value(); result.bit(1) = !system.controls.b->value(); result.bit(2) = !system.controls.select->value(); @@ -105,7 +105,7 @@ auto CPU::readIO(uint32 addr) -> uint8 { if(auto result = player.keyinput()) return result() >> 8; } system.controls.poll(); - uint8 result; + n8 result; result.bit(0) = !system.controls.r->value(); result.bit(1) = !system.controls.l->value(); return result; @@ -231,7 +231,7 @@ auto CPU::readIO(uint32 addr) -> uint8 { return cpu.pipeline.fetch.instruction.byte(addr & 1); } -auto CPU::writeIO(uint32 addr, uint8 data) -> void { +auto CPU::writeIO(n32 addr, n8 data) -> void { auto dma = [&]() -> DMA& { return this->dma[addr / 12 & 3]; }; auto timer = [&]() -> Timer& { return this->timer[addr.bit(2,3)]; }; diff --git a/ares/gba/cpu/keypad.cpp b/ares/gba/cpu/keypad.cpp index 87b77b43e1..0ff869601f 100644 --- a/ares/gba/cpu/keypad.cpp +++ b/ares/gba/cpu/keypad.cpp @@ -16,7 +16,7 @@ auto CPU::Keypad::run() -> void { }; bool test = condition; //0 = OR, 1 = AND - for(uint index : range(10)) { + for(u32 index : range(10)) { if(!flag[index]) continue; bool input = lookup[index]; if(condition == 0) test |= input; diff --git a/ares/gba/cpu/memory.cpp b/ares/gba/cpu/memory.cpp index b3dbce41fc..fcf2ccf083 100644 --- a/ares/gba/cpu/memory.cpp +++ b/ares/gba/cpu/memory.cpp @@ -1,4 +1,4 @@ -auto CPU::readIWRAM(uint mode, uint32 addr) -> uint32 { +auto CPU::readIWRAM(u32 mode, n32 addr) -> n32 { if(memory.disable) return cpu.pipeline.fetch.instruction; if(mode & Word) return readIWRAM(Half, addr &~ 2) << 0 | readIWRAM(Half, addr | 2) << 16; @@ -7,7 +7,7 @@ auto CPU::readIWRAM(uint mode, uint32 addr) -> uint32 { return iwram[addr & 0x7fff]; } -auto CPU::writeIWRAM(uint mode, uint32 addr, uint32 word) -> void { +auto CPU::writeIWRAM(u32 mode, n32 addr, n32 word) -> void { if(memory.disable) return; if(mode & Word) { @@ -25,7 +25,7 @@ auto CPU::writeIWRAM(uint mode, uint32 addr, uint32 word) -> void { iwram[addr & 0x7fff] = word; } -auto CPU::readEWRAM(uint mode, uint32 addr) -> uint32 { +auto CPU::readEWRAM(u32 mode, n32 addr) -> n32 { if(memory.disable) return cpu.pipeline.fetch.instruction; if(!memory.ewram) return readIWRAM(mode, addr); @@ -35,7 +35,7 @@ auto CPU::readEWRAM(uint mode, uint32 addr) -> uint32 { return ewram[addr & 0x3ffff]; } -auto CPU::writeEWRAM(uint mode, uint32 addr, uint32 word) -> void { +auto CPU::writeEWRAM(u32 mode, n32 addr, n32 word) -> void { if(memory.disable) return; if(!memory.ewram) return writeIWRAM(mode, addr, word); diff --git a/ares/gba/cpu/prefetch.cpp b/ares/gba/cpu/prefetch.cpp index e4b7cf4ecc..1908c06c33 100644 --- a/ares/gba/cpu/prefetch.cpp +++ b/ares/gba/cpu/prefetch.cpp @@ -1,4 +1,4 @@ -auto CPU::prefetchSync(uint32 addr) -> void { +auto CPU::prefetchSync(n32 addr) -> void { if(addr == prefetch.addr) return; prefetch.addr = addr; @@ -6,7 +6,7 @@ auto CPU::prefetchSync(uint32 addr) -> void { prefetch.wait = _wait(Half | Nonsequential, prefetch.load); } -auto CPU::prefetchStep(uint clocks) -> void { +auto CPU::prefetchStep(u32 clocks) -> void { step(clocks); if(!wait.prefetch || context.dmaActive) return; @@ -25,13 +25,13 @@ auto CPU::prefetchWait() -> void { prefetch.wait = _wait(Half | Nonsequential, prefetch.load); } -auto CPU::prefetchRead() -> uint16 { +auto CPU::prefetchRead() -> n16 { if(prefetch.empty()) prefetchStep(prefetch.wait); else prefetchStep(1); if(prefetch.full()) prefetch.wait = _wait(Half | Sequential, prefetch.load); - uint16 half = prefetch.slot[prefetch.addr >> 1 & 7]; + n16 half = prefetch.slot[prefetch.addr >> 1 & 7]; prefetch.addr += 2; return half; } diff --git a/ares/gba/cpu/timer.cpp b/ares/gba/cpu/timer.cpp index e37551df4d..6d3a0b817e 100644 --- a/ares/gba/cpu/timer.cpp +++ b/ares/gba/cpu/timer.cpp @@ -7,7 +7,7 @@ inline auto CPU::Timer::run() -> void { if(!enable || cascade) return; - static const uint mask[] = {0, 63, 255, 1023}; + static const u32 mask[] = {0, 63, 255, 1023}; if((cpu.clock() & mask[frequency]) == 0) step(); } @@ -26,7 +26,7 @@ auto CPU::Timer::step() -> void { } } -auto CPU::runFIFO(uint n) -> void { +auto CPU::runFIFO(u32 n) -> void { synchronize(apu); apu.fifo[n].read(); if(apu.fifo[n].size > 16) return; diff --git a/ares/gba/gba.hpp b/ares/gba/gba.hpp index 93c090a255..f2cf54890a 100644 --- a/ares/gba/gba.hpp +++ b/ares/gba/gba.hpp @@ -7,9 +7,10 @@ namespace ares::GameBoyAdvance { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; - enum : uint { //mode flags for bus read, write: + enum : u32 { //mode flags for bus read, write: Nonsequential = 1, //N cycle Sequential = 2, //S cycle Prefetch = 4, //instruction fetch (eligible for prefetch) diff --git a/ares/gba/memory/memory.cpp b/ares/gba/memory/memory.cpp index 6d8b9ff513..c6f84cf43f 100644 --- a/ares/gba/memory/memory.cpp +++ b/ares/gba/memory/memory.cpp @@ -4,8 +4,8 @@ namespace ares::GameBoyAdvance { Bus bus; -auto IO::readIO(uint mode, uint32 address) -> uint32 { - uint32 word; +auto IO::readIO(u32 mode, n32 address) -> n32 { + n32 word; if(mode & Word) { address &= ~3; @@ -24,7 +24,7 @@ auto IO::readIO(uint mode, uint32 address) -> uint32 { return word; } -auto IO::writeIO(uint mode, uint32 address, uint32 word) -> void { +auto IO::writeIO(u32 mode, n32 address, n32 word) -> void { if(mode & Word) { address &= ~3; writeIO(address + 0, word.byte(0)); @@ -41,20 +41,20 @@ auto IO::writeIO(uint mode, uint32 address, uint32 word) -> void { } struct UnmappedIO : IO { - auto readIO(uint32 address) -> uint8 override { + auto readIO(n32 address) -> n8 override { return cpu.pipeline.fetch.instruction.byte(address & 1); } - auto writeIO(uint32 address, uint8 byte) -> void override { + auto writeIO(n32 address, n8 byte) -> void override { } }; static UnmappedIO unmappedIO; -auto Bus::mirror(uint32 address, uint32 size) -> uint32 { - uint32 base = 0; +auto Bus::mirror(n32 address, n32 size) -> n32 { + n32 base = 0; if(size) { - uint32 mask = 1 << 27; //28-bit bus + n32 mask = 1 << 27; //28-bit bus while(address >= size) { while(!(address & mask)) mask >>= 1; address -= mask; @@ -70,7 +70,7 @@ auto Bus::mirror(uint32 address, uint32 size) -> uint32 { } auto Bus::power() -> void { - for(uint n : range(0x400)) io[n] = &unmappedIO; + for(u32 n : range(0x400)) io[n] = &unmappedIO; } } diff --git a/ares/gba/memory/memory.hpp b/ares/gba/memory/memory.hpp index f4e9d06399..c8165e7f0a 100644 --- a/ares/gba/memory/memory.hpp +++ b/ares/gba/memory/memory.hpp @@ -1,12 +1,12 @@ struct IO { - virtual auto readIO(uint32 address) -> uint8 = 0; - virtual auto writeIO(uint32 address, uint8 data) -> void = 0; - auto readIO(uint mode, uint32 address) -> uint32; - auto writeIO(uint mode, uint32 address, uint32 word) -> void; + virtual auto readIO(n32 address) -> n8 = 0; + virtual auto writeIO(n32 address, n8 data) -> void = 0; + auto readIO(u32 mode, n32 address) -> n32; + auto writeIO(u32 mode, n32 address, n32 word) -> void; }; struct Bus { - static auto mirror(uint32 address, uint32 size) -> uint32; + static auto mirror(n32 address, n32 size) -> n32; auto power() -> void; diff --git a/ares/gba/player/player.cpp b/ares/gba/player/player.cpp index 8954223753..23c914bc2c 100644 --- a/ares/gba/player/player.cpp +++ b/ares/gba/player/player.cpp @@ -12,7 +12,7 @@ auto Player::main() -> void { step(1); } -auto Player::step(uint clocks) -> void { +auto Player::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -35,7 +35,7 @@ auto Player::power() -> void { auto Player::frame() -> void { //todo: this is not a very performant way of detecting the GBP logo ... - uint32 hash = Hash::CRC32({ppu.screen->pixels().data(), 240 * 160 * sizeof(uint32)}).value(); + u32 hash = Hash::CRC32({ppu.screen->pixels().data(), 240 * 160 * sizeof(u32)}).value(); status.logoDetected = (hash == 0x7776eb55); if(status.logoDetected) { @@ -90,7 +90,7 @@ auto Player::frame() -> void { } } -auto Player::keyinput() -> maybe { +auto Player::keyinput() -> maybe { if(status.logoDetected) { switch(status.logoCounter) { case 0: return {0x03ff}; @@ -101,15 +101,15 @@ auto Player::keyinput() -> maybe { return nothing; } -auto Player::read() -> maybe { +auto Player::read() -> maybe { if(status.enable) return status.send; return nothing; } -auto Player::write(uint2 addr, uint8 byte) -> void { +auto Player::write(n2 addr, n8 byte) -> void { if(!status.enable) return; - uint shift = addr << 3; + u32 shift = addr << 3; status.recv &= ~(255 << shift); status.recv |= byte << shift; diff --git a/ares/gba/player/player.hpp b/ares/gba/player/player.hpp index c3aabacac6..c7c804306e 100644 --- a/ares/gba/player/player.hpp +++ b/ares/gba/player/player.hpp @@ -1,29 +1,29 @@ struct Player : Thread { auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; auto frame() -> void; - auto keyinput() -> maybe; - auto read() -> maybe; - auto write(uint2 addr, uint8 byte) -> void; + auto keyinput() -> maybe; + auto read() -> maybe; + auto write(n2 address, n8 byte) -> void; auto serialize(serializer& s) -> void; private: struct Status { - uint1 enable; - uint1 rumble; + n1 enable; + n1 rumble; - uint1 logoDetected; - uint32 logoCounter; + n1 logoDetected; + n32 logoCounter; - uint32 packet; - uint32 send; - uint32 recv; + n32 packet; + n32 send; + n32 recv; - uint32 timeout; + n32 timeout; } status; }; diff --git a/ares/gba/ppu/background.cpp b/ares/gba/ppu/background.cpp index 71b46b16be..d220857123 100644 --- a/ares/gba/ppu/background.cpp +++ b/ares/gba/ppu/background.cpp @@ -1,14 +1,14 @@ //I/O settings shared by all background layers -uint3 PPU::Background::IO::mode; -uint1 PPU::Background::IO::frame; -uint5 PPU::Background::IO::mosaicWidth; -uint5 PPU::Background::IO::mosaicHeight; +n3 PPU::Background::IO::mode; +n1 PPU::Background::IO::frame; +n5 PPU::Background::IO::mosaicWidth; +n5 PPU::Background::IO::mosaicHeight; -auto PPU::Background::scanline(uint y) -> void { +auto PPU::Background::scanline(u32 y) -> void { mosaicOffset = 0; } -auto PPU::Background::run(uint x, uint y) -> void { +auto PPU::Background::run(u32 x, u32 y) -> void { output = {}; if(ppu.blank() || !io.enable) { mosaic = {}; @@ -43,7 +43,7 @@ auto PPU::Background::run(uint x, uint y) -> void { } } -auto PPU::Background::linear(uint x, uint y) -> void { +auto PPU::Background::linear(u32 x, u32 y) -> void { if(x == 0) { if(!io.mosaic || (y % (1 + io.mosaicHeight)) == 0) { vmosaic = y; @@ -52,19 +52,19 @@ auto PPU::Background::linear(uint x, uint y) -> void { fy = vmosaic + io.voffset; } - uint3 px = fx; - uint3 py = fy; + n3 px = fx; + n3 py = fy; if(x == 0 || px == 0) { - uint6 tx = fx >> 3; - uint6 ty = fy >> 3; + n6 tx = fx >> 3; + n6 ty = fy >> 3; - uint offset = (ty & 31) << 5 | (tx & 31); + u32 offset = (ty & 31) << 5 | (tx & 31); if(io.screenSize.bit(0) && (tx & 32)) offset += 32 << 5; if(io.screenSize.bit(1) && (ty & 32)) offset += 32 << 5 + io.screenSize.bit(0); offset = (io.screenBase << 11) + (offset << 1); - uint16 tilemap = ppu.readVRAM(Half, offset); + n16 tilemap = ppu.readVRAM(Half, offset); latch.character = tilemap.bit(0,9); latch.hflip = tilemap.bit(10); latch.vflip = tilemap.bit(11); @@ -75,15 +75,15 @@ auto PPU::Background::linear(uint x, uint y) -> void { if(latch.vflip) py = ~py; if(io.colorMode == 0) { - uint offset = (io.characterBase << 14) + (latch.character << 5) + (py << 2) + (px >> 1); - if(uint4 color = ppu.readVRAM(Byte, offset) >> (px & 1 ? 4 : 0)) { + u32 offset = (io.characterBase << 14) + (latch.character << 5) + (py << 2) + (px >> 1); + if(n4 color = ppu.readVRAM(Byte, offset) >> (px & 1 ? 4 : 0)) { output.enable = true; output.priority = io.priority; output.color = ppu.pram[latch.palette << 4 | color]; } } else { - uint offset = (io.characterBase << 14) + (latch.character << 6) + (py << 3) + (px); - if(uint8 color = ppu.readVRAM(Byte, offset)) { + u32 offset = (io.characterBase << 14) + (latch.character << 6) + (py << 3) + (px); + if(n8 color = ppu.readVRAM(Byte, offset)) { output.enable = true; output.priority = io.priority; output.color = ppu.pram[color]; @@ -93,7 +93,7 @@ auto PPU::Background::linear(uint x, uint y) -> void { fx++; } -auto PPU::Background::affine(uint x, uint y) -> void { +auto PPU::Background::affine(u32 x, u32 y) -> void { if(x == 0) { if(!io.mosaic || (y % (1 + io.mosaicHeight)) == 0) { hmosaic = io.lx; @@ -103,21 +103,21 @@ auto PPU::Background::affine(uint x, uint y) -> void { fy = vmosaic; } - uint screenSize = 16 << io.screenSize; - uint screenWrap = (1 << (io.affineWrap ? 7 + io.screenSize : 20)) - 1; + u32 screenSize = 16 << io.screenSize; + u32 screenWrap = (1 << (io.affineWrap ? 7 + io.screenSize : 20)) - 1; - uint cx = (fx >> 8) & screenWrap; - uint cy = (fy >> 8) & screenWrap; + u32 cx = (fx >> 8) & screenWrap; + u32 cy = (fy >> 8) & screenWrap; - uint tx = cx >> 3; - uint ty = cy >> 3; + u32 tx = cx >> 3; + u32 ty = cy >> 3; - uint3 px = cx; - uint3 py = cy; + n3 px = cx; + n3 py = cy; if(tx < screenSize && ty < screenSize) { - uint8 character = ppu.vram[(io.screenBase << 11) + ty * screenSize + tx]; - if(uint8 color = ppu.vram[(io.characterBase << 14) + (character << 6) + (py << 3) + px]) { + n8 character = ppu.vram[(io.screenBase << 11) + ty * screenSize + tx]; + if(n8 color = ppu.vram[(io.characterBase << 14) + (character << 6) + (py << 3) + px]) { output.enable = true; output.priority = io.priority; output.color = ppu.pram[color]; @@ -133,7 +133,7 @@ auto PPU::Background::affine(uint x, uint y) -> void { } } -auto PPU::Background::bitmap(uint x, uint y) -> void { +auto PPU::Background::bitmap(u32 x, u32 y) -> void { if(x == 0) { if(!io.mosaic || (y % (1 + io.mosaicHeight)) == 0) { hmosaic = io.lx; @@ -143,19 +143,19 @@ auto PPU::Background::bitmap(uint x, uint y) -> void { fy = vmosaic; } - uint1 depth = io.mode != 4; //0 = 8-bit (mode 4); 1 = 15-bit (mode 3, mode 5) - uint width = io.mode == 5 ? 160 : 240; - uint height = io.mode == 5 ? 128 : 160; - uint mode = depth ? Half : Byte; + n1 depth = io.mode != 4; //0 = 8-bit (mode 4); 1 = 15-bit (mode 3, mode 5) + u32 width = io.mode == 5 ? 160 : 240; + u32 height = io.mode == 5 ? 128 : 160; + u32 mode = depth ? Half : Byte; - uint baseAddress = io.mode == 3 ? 0 : 0xa000 * io.frame; + u32 baseAddress = io.mode == 3 ? 0 : 0xa000 * io.frame; - uint px = fx >> 8; - uint py = fy >> 8; + u32 px = fx >> 8; + u32 py = fy >> 8; if(px < width && py < height) { - uint offset = py * width + px; - uint15 color = ppu.readVRAM(mode, baseAddress + (offset << depth)); + u32 offset = py * width + px; + n15 color = ppu.readVRAM(mode, baseAddress + (offset << depth)); if(depth || color) { //8bpp color 0 is transparent; 15bpp color is always opaque if(depth == 0) color = ppu.pram[color]; @@ -174,7 +174,7 @@ auto PPU::Background::bitmap(uint x, uint y) -> void { } } -auto PPU::Background::power(uint id) -> void { +auto PPU::Background::power(u32 id) -> void { this->id = id; io = {}; diff --git a/ares/gba/ppu/color.cpp b/ares/gba/ppu/color.cpp index e7c07ab01c..7f177f0a6f 100644 --- a/ares/gba/ppu/color.cpp +++ b/ares/gba/ppu/color.cpp @@ -1,17 +1,17 @@ -auto PPU::color(uint32 color) -> uint64 { - uint R = color.bit( 0, 4); - uint G = color.bit( 5, 9); - uint B = color.bit(10,14); +auto PPU::color(n32 color) -> n64 { + n32 R = color.bit( 0, 4); + n32 G = color.bit( 5, 9); + n32 B = color.bit(10,14); - uint64 r = image::normalize(R, 5, 16); - uint64 g = image::normalize(G, 5, 16); - uint64 b = image::normalize(B, 5, 16); + n64 r = image::normalize(R, 5, 16); + n64 g = image::normalize(G, 5, 16); + n64 b = image::normalize(B, 5, 16); if(colorEmulation->value()) { - double lcdGamma = 4.0, outGamma = 2.2; - double lb = pow(B / 31.0, lcdGamma); - double lg = pow(G / 31.0, lcdGamma); - double lr = pow(R / 31.0, lcdGamma); + f64 lcdGamma = 4.0, outGamma = 2.2; + f64 lb = pow(B / 31.0, lcdGamma); + f64 lg = pow(G / 31.0, lcdGamma); + f64 lr = pow(R / 31.0, lcdGamma); r = pow(( 0 * lb + 50 * lg + 255 * lr) / 255, 1 / outGamma) * (0xffff * 255 / 280); g = pow(( 30 * lb + 230 * lg + 10 * lr) / 255, 1 / outGamma) * (0xffff * 255 / 280); b = pow((220 * lb + 10 * lg + 50 * lr) / 255, 1 / outGamma) * (0xffff * 255 / 280); diff --git a/ares/gba/ppu/dac.cpp b/ares/gba/ppu/dac.cpp index b2ea0b08e7..2f905ce9f4 100644 --- a/ares/gba/ppu/dac.cpp +++ b/ares/gba/ppu/dac.cpp @@ -1,8 +1,8 @@ -auto PPU::DAC::run(uint x, uint y) -> uint15 { +auto PPU::DAC::run(u32 x, u32 y) -> n15 { if(ppu.blank()) return 0x7fff; //determine active window - uint1 active[6] = {true, true, true, true, true, true}; //enable all layers if no windows are enabled + n1 active[6] = {true, true, true, true, true, true}; //enable all layers if no windows are enabled if(ppu.window0.io.enable || ppu.window1.io.enable || ppu.window2.io.enable) { memory::copy(&active, &ppu.window3.io.active, sizeof(active)); if(ppu.window2.io.enable && ppu.window2.output) memory::copy(&active, &ppu.window2.io.active, sizeof(active)); @@ -20,9 +20,9 @@ auto PPU::DAC::run(uint x, uint y) -> uint15 { {true, 3, ppu.pram[0]}, }; - uint aboveLayer = 5, belowLayer = 5; - for(int priority = 3; priority >= 0; priority--) { - for(int layer = 5; layer >= 0; layer--) { + u32 aboveLayer = 5, belowLayer = 5; + for(s32 priority = 3; priority >= 0; priority--) { + for(s32 layer = 5; layer >= 0; layer--) { if(layers[layer].enable && layers[layer].priority == priority && active[layer]) { belowLayer = aboveLayer; aboveLayer = layer; @@ -32,10 +32,10 @@ auto PPU::DAC::run(uint x, uint y) -> uint15 { auto above = layers[aboveLayer]; auto below = layers[belowLayer]; - auto eva = min(16u, (uint)io.blendEVA); - auto evb = min(16u, (uint)io.blendEVB); - auto evy = min(16u, (uint)io.blendEVY); - uint15 color = above.color; + auto eva = min(16u, (u32)io.blendEVA); + auto evb = min(16u, (u32)io.blendEVB); + auto evy = min(16u, (u32)io.blendEVY); + n15 color = above.color; //color blending if(active[SFX]) { @@ -53,13 +53,13 @@ auto PPU::DAC::run(uint x, uint y) -> uint15 { return color; } -auto PPU::DAC::blend(uint15 above, uint eva, uint15 below, uint evb) -> uint15 { - uint5 ar = above >> 0, ag = above >> 5, ab = above >> 10; - uint5 br = below >> 0, bg = below >> 5, bb = below >> 10; +auto PPU::DAC::blend(n15 above, u32 eva, n15 below, u32 evb) -> n15 { + n5 ar = above >> 0, ag = above >> 5, ab = above >> 10; + n5 br = below >> 0, bg = below >> 5, bb = below >> 10; - uint r = (ar * eva + br * evb) >> 4; - uint g = (ag * eva + bg * evb) >> 4; - uint b = (ab * eva + bb * evb) >> 4; + u32 r = (ar * eva + br * evb) >> 4; + u32 g = (ag * eva + bg * evb) >> 4; + u32 b = (ab * eva + bb * evb) >> 4; return min(31u, r) << 0 | min(31u, g) << 5 | min(31u, b) << 10; } diff --git a/ares/gba/ppu/io.cpp b/ares/gba/ppu/io.cpp index b98fe03748..417c572671 100644 --- a/ares/gba/ppu/io.cpp +++ b/ares/gba/ppu/io.cpp @@ -1,4 +1,4 @@ -auto PPU::readIO(uint32 addr) -> uint8 { +auto PPU::readIO(n32 addr) -> n8 { switch(addr) { //DISPCNT @@ -103,7 +103,7 @@ auto PPU::readIO(uint32 addr) -> uint8 { return cpu.pipeline.fetch.instruction.byte(addr & 1); } -auto PPU::writeIO(uint32 addr, uint8 data) -> void { +auto PPU::writeIO(n32 addr, n8 data) -> void { switch(addr) { //DISPCNT diff --git a/ares/gba/ppu/memory.cpp b/ares/gba/ppu/memory.cpp index b74ccd9f13..a8cb02b985 100644 --- a/ares/gba/ppu/memory.cpp +++ b/ares/gba/ppu/memory.cpp @@ -1,4 +1,4 @@ -auto PPU::readVRAM(uint mode, uint32 addr) -> uint32 { +auto PPU::readVRAM(u32 mode, n32 addr) -> n32 { addr &= (addr & 0x10000) ? 0x17fff : 0x0ffff; if(mode & Word) { @@ -14,7 +14,7 @@ auto PPU::readVRAM(uint mode, uint32 addr) -> uint32 { unreachable; } -auto PPU::writeVRAM(uint mode, uint32 addr, uint32 word) -> void { +auto PPU::writeVRAM(u32 mode, n32 addr, n32 word) -> void { addr &= (addr & 0x10000) ? 0x17fff : 0x0ffff; if(mode & Word) { @@ -33,18 +33,18 @@ auto PPU::writeVRAM(uint mode, uint32 addr, uint32 word) -> void { if(Background::IO::mode <= 5 && addr >= 0x14000) return; addr &= ~1; - vram[addr + 0] = (uint8)word; - vram[addr + 1] = (uint8)word; + vram[addr + 0] = (n8)word; + vram[addr + 1] = (n8)word; } } -auto PPU::readPRAM(uint mode, uint32 addr) -> uint32 { +auto PPU::readPRAM(u32 mode, n32 addr) -> n32 { if(mode & Word) return readPRAM(Half, addr & ~2) << 0 | readPRAM(Half, addr | 2) << 16; if(mode & Byte) return readPRAM(Half, addr) >> ((addr & 1) * 8); return pram[addr >> 1 & 511]; } -auto PPU::writePRAM(uint mode, uint32 addr, uint32 word) -> void { +auto PPU::writePRAM(u32 mode, n32 addr, n32 word) -> void { if(mode & Word) { writePRAM(Half, addr & ~2, word >> 0); writePRAM(Half, addr | 2, word >> 16); @@ -52,14 +52,14 @@ auto PPU::writePRAM(uint mode, uint32 addr, uint32 word) -> void { } if(mode & Byte) { - word = (uint8)word; + word = (n8)word; return writePRAM(Half, addr, word << 8 | word << 0); } - pram[addr >> 1 & 511] = (uint16)word; + pram[addr >> 1 & 511] = (n16)word; } -auto PPU::readOAM(uint mode, uint32 addr) -> uint32 { +auto PPU::readOAM(u32 mode, n32 addr) -> n32 { if(mode & Word) return readOAM(Half, addr & ~2) << 0 | readOAM(Half, addr | 2) << 16; if(mode & Byte) return readOAM(Half, addr) >> ((addr & 1) * 8); @@ -105,7 +105,7 @@ auto PPU::readOAM(uint mode, uint32 addr) -> uint32 { unreachable; } -auto PPU::writeOAM(uint mode, uint32 addr, uint32 word) -> void { +auto PPU::writeOAM(u32 mode, n32 addr, n32 word) -> void { if(mode & Word) { writeOAM(Half, addr & ~2, word >> 0); writeOAM(Half, addr | 2, word >> 16); @@ -152,14 +152,14 @@ auto PPU::writeOAM(uint mode, uint32 addr, uint32 word) -> void { } - static uint widths[] = { + static u32 widths[] = { 8, 16, 32, 64, 16, 32, 32, 64, 8, 8, 16, 32, 8, 8, 8, 8, //invalid modes }; - static uint heights[] = { + static u32 heights[] = { 8, 16, 32, 64, 8, 8, 16, 32, 16, 32, 32, 64, @@ -170,7 +170,7 @@ auto PPU::writeOAM(uint mode, uint32 addr, uint32 word) -> void { obj.height = heights[obj.shape * 4 + obj.size]; } -auto PPU::readObjectVRAM(uint addr) const -> uint8 { +auto PPU::readObjectVRAM(u32 addr) const -> n8 { if(Background::IO::mode == 3 || Background::IO::mode == 4 || Background::IO::mode == 5) { if(addr <= 0x3fff) return 0u; } diff --git a/ares/gba/ppu/object.cpp b/ares/gba/ppu/object.cpp index ee2b431699..a0e383d136 100644 --- a/ares/gba/ppu/object.cpp +++ b/ares/gba/ppu/object.cpp @@ -1,40 +1,40 @@ -auto PPU::Objects::scanline(uint y) -> void { +auto PPU::Objects::scanline(u32 y) -> void { mosaicOffset = 0; for(auto& pixel : buffer) pixel = {}; if(ppu.blank() || !io.enable) return; for(auto& object : ppu.object) { - uint8 py = y - object.y; + n8 py = y - object.y; if(object.affine == 0 && object.affineSize == 1) continue; //hidden if(py >= object.height << object.affineSize) continue; //offscreen - uint rowSize = io.mapping == 0 ? 32 >> object.colors : object.width >> 3; - uint baseAddress = object.character << 5; + u32 rowSize = io.mapping == 0 ? 32 >> object.colors : object.width >> 3; + u32 baseAddress = object.character << 5; if(object.mosaic && io.mosaicHeight) { - int mosaicY = (y / (1 + io.mosaicHeight)) * (1 + io.mosaicHeight); - py = object.y >= 160 || mosaicY - object.y >= 0 ? uint(mosaicY - object.y) : 0; + s32 mosaicY = (y / (1 + io.mosaicHeight)) * (1 + io.mosaicHeight); + py = object.y >= 160 || mosaicY - object.y >= 0 ? u32(mosaicY - object.y) : 0; } - int16 pa = ppu.objectParam[object.affineParam].pa; - int16 pb = ppu.objectParam[object.affineParam].pb; - int16 pc = ppu.objectParam[object.affineParam].pc; - int16 pd = ppu.objectParam[object.affineParam].pd; + i16 pa = ppu.objectParam[object.affineParam].pa; + i16 pb = ppu.objectParam[object.affineParam].pb; + i16 pc = ppu.objectParam[object.affineParam].pc; + i16 pd = ppu.objectParam[object.affineParam].pd; //center-of-sprite coordinates - int16 centerX = object.width >> 1; - int16 centerY = object.height >> 1; + i16 centerX = object.width >> 1; + i16 centerY = object.height >> 1; //origin coordinates (top-left of sprite) - int28 originX = -(centerX << object.affineSize); - int28 originY = -(centerY << object.affineSize) + py; + i28 originX = -(centerX << object.affineSize); + i28 originY = -(centerY << object.affineSize) + py; //fractional pixel coordinates - int28 fx = originX * pa + originY * pb; - int28 fy = originX * pc + originY * pd; + i28 fx = originX * pa + originY * pb; + i28 fy = originX * pc + originY * pd; - for(uint px : range(object.width << object.affineSize)) { - uint sx, sy; + for(u32 px : range(object.width << object.affineSize)) { + u32 sx, sy; if(!object.affine) { sx = px ^ (object.hflip ? object.width - 1 : 0); sy = py ^ (object.vflip ? object.height - 1 : 0); @@ -43,12 +43,12 @@ auto PPU::Objects::scanline(uint y) -> void { sy = (fy >> 8) + centerY; } - uint9 bx = object.x + px; + n9 bx = object.x + px; if(bx < 240 && sx < object.width && sy < object.height) { - uint offset = (sy >> 3) * rowSize + (sx >> 3); + u32 offset = (sy >> 3) * rowSize + (sx >> 3); offset = offset * 64 + (sy & 7) * 8 + (sx & 7); - uint8 color = ppu.readObjectVRAM(baseAddress + (offset >> !object.colors)); + n8 color = ppu.readObjectVRAM(baseAddress + (offset >> !object.colors)); if(object.colors == 0) color = sx & 1 ? color >> 4 : color & 15; if(object.mode & 2) { if(color) { @@ -72,7 +72,7 @@ auto PPU::Objects::scanline(uint y) -> void { } } -auto PPU::Objects::run(uint x, uint y) -> void { +auto PPU::Objects::run(u32 x, u32 y) -> void { output = {}; if(ppu.blank() || !io.enable) { mosaic = {}; diff --git a/ares/gba/ppu/ppu.cpp b/ares/gba/ppu/ppu.cpp index 5e10087010..ccc5abb57a 100644 --- a/ares/gba/ppu/ppu.cpp +++ b/ares/gba/ppu/ppu.cpp @@ -74,7 +74,7 @@ inline auto PPU::blank() -> bool { return io.forceBlank || cpu.stopped(); } -auto PPU::step(uint clocks) -> void { +auto PPU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -105,14 +105,14 @@ auto PPU::main() -> void { } if(io.vcounter < 160) { - uint y = io.vcounter; + u32 y = io.vcounter; bg0.scanline(y); bg1.scanline(y); bg2.scanline(y); bg3.scanline(y); objects.scanline(y); auto line = screen->pixels().data() + y * 240; - for(uint x : range(240)) { + for(u32 x : range(240)) { bg0.run(x, y); bg1.run(x, y); bg2.run(x, y); @@ -122,7 +122,7 @@ auto PPU::main() -> void { window1.run(x, y); window2.output = objects.output.window; window3.output = true; - uint15 color = dac.run(x, y); + n15 color = dac.run(x, y); line[x] = color; step(4); } @@ -151,11 +151,11 @@ auto PPU::power() -> void { Thread::create(system.frequency(), {&PPU::main, this}); screen->power(); - for(uint n = 0x000; n <= 0x055; n++) bus.io[n] = this; + for(u32 n = 0x000; n <= 0x055; n++) bus.io[n] = this; - for(uint n = 0; n < 96 * 1024; n++) vram[n] = 0x00; - for(uint n = 0; n < 1024; n += 2) writePRAM(n, Half, 0x0000); - for(uint n = 0; n < 1024; n += 2) writeOAM(n, Half, 0x0000); + for(u32 n = 0; n < 96 * 1024; n++) vram[n] = 0x00; + for(u32 n = 0; n < 1024; n += 2) writePRAM(n, Half, 0x0000); + for(u32 n = 0; n < 1024; n += 2) writeOAM(n, Half, 0x0000); io = {}; for(auto& object : this->object) object = {}; diff --git a/ares/gba/ppu/ppu.hpp b/ares/gba/ppu/ppu.hpp index 25512eeff1..6238d9acf9 100644 --- a/ares/gba/ppu/ppu.hpp +++ b/ares/gba/ppu/ppu.hpp @@ -4,8 +4,8 @@ struct PPU : Thread, IO { Node::Setting::Boolean colorEmulation; Node::Setting::Boolean interframeBlending; Node::Setting::String rotation; - Memory::Writable vram; //96KB - Memory::Writable pram; + Memory::Writable vram; //96KB + Memory::Writable pram; struct Debugger { //debugger.cpp @@ -23,7 +23,7 @@ struct PPU : Thread, IO { auto blank() -> bool; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto main() -> void; auto frame() -> void; @@ -31,23 +31,23 @@ struct PPU : Thread, IO { auto power() -> void; //io.cpp - auto readIO(uint32 addr) -> uint8; - auto writeIO(uint32 addr, uint8 byte) -> void; + auto readIO(n32 address) -> n8; + auto writeIO(n32 address, n8 byte) -> void; //memory.cpp - auto readVRAM(uint mode, uint32 addr) -> uint32; - auto writeVRAM(uint mode, uint32 addr, uint32 word) -> void; + auto readVRAM(u32 mode, n32 address) -> n32; + auto writeVRAM(u32 mode, n32 address, n32 word) -> void; - auto readPRAM(uint mode, uint32 addr) -> uint32; - auto writePRAM(uint mode, uint32 addr, uint32 word) -> void; + auto readPRAM(u32 mode, n32 address) -> n32; + auto writePRAM(u32 mode, n32 address, n32 word) -> void; - auto readOAM(uint mode, uint32 addr) -> uint32; - auto writeOAM(uint mode, uint32 addr, uint32 word) -> void; + auto readOAM(u32 mode, n32 address) -> n32; + auto writeOAM(u32 mode, n32 address, n32 word) -> void; - auto readObjectVRAM(uint addr) const -> uint8; + auto readObjectVRAM(u32 address) const -> n8; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; @@ -55,166 +55,166 @@ struct PPU : Thread, IO { private: //note: I/O register order is {BG0-BG3, OBJ, SFX} //however; layer ordering is {OBJ, BG0-BG3, SFX} - enum : uint { OBJ = 0, BG0 = 1, BG1 = 2, BG2 = 3, BG3 = 4, SFX = 5 }; - enum : uint { IN0 = 0, IN1 = 1, IN2 = 2, OUT = 3 }; + enum : u32 { OBJ = 0, BG0 = 1, BG1 = 2, BG2 = 3, BG3 = 4, SFX = 5 }; + enum : u32 { IN0 = 0, IN1 = 1, IN2 = 2, OUT = 3 }; struct IO { - uint1 gameBoyColorMode; - uint1 forceBlank; - uint1 greenSwap; - - uint1 vblank; - uint1 hblank; - uint1 vcoincidence; - uint1 irqvblank; - uint1 irqhblank; - uint1 irqvcoincidence; - uint8 vcompare; - - uint16 vcounter; + n1 gameBoyColorMode; + n1 forceBlank; + n1 greenSwap; + + n1 vblank; + n1 hblank; + n1 vcoincidence; + n1 irqvblank; + n1 irqhblank; + n1 irqvcoincidence; + n8 vcompare; + + n16 vcounter; } io; struct Pixel { - uint1 enable; - uint2 priority; - uint15 color; + n1 enable; + n2 priority; + n15 color; //OBJ only - uint1 translucent; - uint1 mosaic; - uint1 window; //IN2 + n1 translucent; + n1 mosaic; + n1 window; //IN2 }; struct Background { //background.cpp - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; - auto linear(uint x, uint y) -> void; - auto affine(uint x, uint y) -> void; - auto bitmap(uint x, uint y) -> void; - auto power(uint id) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; + auto linear(u32 x, u32 y) -> void; + auto affine(u32 x, u32 y) -> void; + auto bitmap(u32 x, u32 y) -> void; + auto power(u32 id) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint id; //BG0, BG1, BG2, BG3 + u32 id; //BG0, BG1, BG2, BG3 struct IO { - static uint3 mode; - static uint1 frame; - static uint5 mosaicWidth; - static uint5 mosaicHeight; + static n3 mode; + static n1 frame; + static n5 mosaicWidth; + static n5 mosaicHeight; - uint1 enable; + n1 enable; - uint2 priority; - uint2 characterBase; - uint2 unused; - uint1 mosaic; - uint1 colorMode; - uint5 screenBase; - uint1 affineWrap; //BG2, BG3 only - uint2 screenSize; + n2 priority; + n2 characterBase; + n2 unused; + n1 mosaic; + n1 colorMode; + n5 screenBase; + n1 affineWrap; //BG2, BG3 only + n2 screenSize; - uint9 hoffset; - uint9 voffset; + n9 hoffset; + n9 voffset; //BG2, BG3 only - int16 pa; - int16 pb; - int16 pc; - int16 pd; - int28 x; - int28 y; + i16 pa; + i16 pb; + i16 pc; + i16 pd; + i28 x; + i28 y; //internal - int28 lx; - int28 ly; + i28 lx; + i28 ly; } io; struct Latch { - uint10 character; - uint1 hflip; - uint1 vflip; - uint4 palette; + n10 character; + n1 hflip; + n1 vflip; + n4 palette; } latch; Pixel output; Pixel mosaic; - uint mosaicOffset; + u32 mosaicOffset; - uint hmosaic; - uint vmosaic; + u32 hmosaic; + u32 vmosaic; - int28 fx; - int28 fy; + i28 fx; + i28 fy; } bg0, bg1, bg2, bg3; struct Objects { //object.cpp - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; auto power() -> void; //object.cpp auto serialize(serializer&) -> void; struct IO { - uint1 enable; + n1 enable; - uint1 hblank; //1 = allow access to OAM during Hblank - uint1 mapping; //0 = two-dimensional, 1 = one-dimensional - uint5 mosaicWidth; - uint5 mosaicHeight; + n1 hblank; //1 = allow access to OAM during Hblank + n1 mapping; //0 = two-dimensional, 1 = one-dimensional + n5 mosaicWidth; + n5 mosaicHeight; } io; Pixel buffer[240]; Pixel output; Pixel mosaic; - uint mosaicOffset; + u32 mosaicOffset; } objects; struct Window { //window.cpp - auto run(uint x, uint y) -> void; - auto power(uint id) -> void; + auto run(u32 x, u32 y) -> void; + auto power(u32 id) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint id; //IN0, IN1, IN2, OUT + u32 id; //IN0, IN1, IN2, OUT struct IO { - uint1 enable; - uint1 active[6]; + n1 enable; + n1 active[6]; //IN0, IN1 only - uint8 x1; - uint8 x2; - uint8 y1; - uint8 y2; + n8 x1; + n8 x2; + n8 y1; + n8 y2; } io; - uint1 output; //IN0, IN1, IN2 only + n1 output; //IN0, IN1, IN2 only } window0, window1, window2, window3; struct DAC { //dac.cpp - auto run(uint x, uint y) -> uint15; - auto blend(uint15 above, uint eva, uint15 below, uint evb) -> uint15; + auto run(u32 x, u32 y) -> n15; + auto blend(n15 above, u32 eva, n15 below, u32 evb) -> n15; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; struct IO { - uint2 blendMode; - uint1 blendAbove[6]; - uint1 blendBelow[6]; + n2 blendMode; + n1 blendAbove[6]; + n1 blendBelow[6]; - uint5 blendEVA; - uint5 blendEVB; - uint5 blendEVY; + n5 blendEVA; + n5 blendEVB; + n5 blendEVY; } io; } dac; @@ -222,37 +222,37 @@ struct PPU : Thread, IO { //serialization.cpp auto serialize(serializer&) -> void; - uint8 y; - uint1 affine; - uint1 affineSize; - uint2 mode; - uint1 mosaic; - uint1 colors; //0 = 16, 1 = 256 - uint2 shape; //0 = square, 1 = horizontal, 2 = vertical + n8 y; + n1 affine; + n1 affineSize; + n2 mode; + n1 mosaic; + n1 colors; //0 = 16, 1 = 256 + n2 shape; //0 = square, 1 = horizontal, 2 = vertical - uint9 x; - uint5 affineParam; - uint1 hflip; - uint1 vflip; - uint2 size; + n9 x; + n5 affineParam; + n1 hflip; + n1 vflip; + n2 size; - uint10 character; - uint2 priority; - uint4 palette; + n10 character; + n2 priority; + n4 palette; //ancillary data - uint32 width; - uint32 height; + n32 width; + n32 height; } object[128]; struct ObjectParam { //serialization.cpp auto serialize(serializer&) -> void; - int16 pa; - int16 pb; - int16 pc; - int16 pd; + i16 pa; + i16 pb; + i16 pc; + i16 pd; } objectParam[32]; }; diff --git a/ares/gba/ppu/window.cpp b/ares/gba/ppu/window.cpp index af768d13f1..f555ac5bd6 100644 --- a/ares/gba/ppu/window.cpp +++ b/ares/gba/ppu/window.cpp @@ -1,4 +1,4 @@ -auto PPU::Window::run(uint x, uint y) -> void { +auto PPU::Window::run(u32 x, u32 y) -> void { auto x1 = io.x1, x2 = io.x2; auto y1 = io.y1, y2 = io.y2; @@ -8,7 +8,7 @@ auto PPU::Window::run(uint x, uint y) -> void { output = (x >= x1 && x < x2 && y >= y1 && y < y2); } -auto PPU::Window::power(uint id) -> void { +auto PPU::Window::power(u32 id) -> void { this->id = id; io = {}; diff --git a/ares/gba/system/bios.cpp b/ares/gba/system/bios.cpp index 253188f659..9696288389 100644 --- a/ares/gba/system/bios.cpp +++ b/ares/gba/system/bios.cpp @@ -2,14 +2,14 @@ BIOS bios; BIOS::BIOS() { size = 16384; - data = new uint8[size](); + data = new n8[size](); } BIOS::~BIOS() { delete[] data; } -auto BIOS::read(uint mode, uint32 addr) -> uint32 { +auto BIOS::read(u32 mode, n32 addr) -> n32 { //unmapped memory if(addr >= 0x0000'4000) { if(cpu.context.dmaActive) return cpu.dmabus.data; @@ -26,5 +26,5 @@ auto BIOS::read(uint mode, uint32 addr) -> uint32 { return mdr = data[addr]; } -auto BIOS::write(uint mode, uint32 addr, uint32 word) -> void { +auto BIOS::write(u32 mode, n32 addr, n32 word) -> void { } diff --git a/ares/gba/system/bios.hpp b/ares/gba/system/bios.hpp index 1e0b02ab89..3e5786e81b 100644 --- a/ares/gba/system/bios.hpp +++ b/ares/gba/system/bios.hpp @@ -2,12 +2,12 @@ struct BIOS { BIOS(); ~BIOS(); - auto read(uint mode, uint32 addr) -> uint32; - auto write(uint mode, uint32 addr, uint32 word) -> void; + auto read(u32 mode, n32 address) -> n32; + auto write(u32 mode, n32 address, n32 word) -> void; - uint8* data = nullptr; - uint size = 0; - uint32 mdr = 0; + n8* data = nullptr; + u32 size = 0; + n32 mdr = 0; }; extern BIOS bios; diff --git a/ares/gba/system/serialization.cpp b/ares/gba/system/serialization.cpp index c28c6aec7b..d3970d059a 100644 --- a/ares/gba/system/serialization.cpp +++ b/ares/gba/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/gba/system/system.cpp b/ares/gba/system/system.cpp index ee746a2793..a0f7d47f7d 100644 --- a/ares/gba/system/system.cpp +++ b/ares/gba/system/system.cpp @@ -2,7 +2,15 @@ namespace ares::GameBoyAdvance { +auto enumerate() -> vector { + return { + "[Nintendo] Game Boy Advance", + "[Nintendo] Game Boy Player", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -29,10 +37,16 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "Game Boy Advance") information.model = Model::GameBoyAdvance; - if(name == "Game Boy Player" ) information.model = Model::GameBoyPlayer; + if(name.find("Game Boy Advance")) { + information.name = "Game Boy Advance"; + information.model = Model::GameBoyAdvance; + } + if(name.find("Game Boy Player")) { + information.name = "Game Boy Player"; + information.model = Model::GameBoyPlayer; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); diff --git a/ares/gba/system/system.hpp b/ares/gba/system/system.hpp index 19147d7641..d9ef91aed2 100644 --- a/ares/gba/system/system.hpp +++ b/ares/gba/system/system.hpp @@ -29,11 +29,11 @@ struct System { bool rightLatch = 0; } controls; - enum class Model : uint { GameBoyAdvance, GameBoyPlayer }; + enum class Model : u32 { GameBoyAdvance, GameBoyPlayer }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } - auto frequency() const -> double { return 16 * 1024 * 1024; } + auto frequency() const -> f64 { return 16 * 1024 * 1024; } //system.cpp auto game() -> string; @@ -50,6 +50,7 @@ struct System { private: struct Information { + string name = "Game Boy Advance"; Model model = Model::GameBoyAdvance; } information; diff --git a/ares/md/apu/apu.cpp b/ares/md/apu/apu.cpp index e60cbe7ba2..43c8de26f0 100644 --- a/ares/md/apu/apu.cpp +++ b/ares/md/apu/apu.cpp @@ -39,7 +39,7 @@ auto APU::main() -> void { instruction(); } -auto APU::step(uint clocks) -> void { +auto APU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu, vdp, psg, ym2612); } diff --git a/ares/md/apu/apu.hpp b/ares/md/apu/apu.hpp index e4f49f05cd..eea2c964ef 100644 --- a/ares/md/apu/apu.hpp +++ b/ares/md/apu/apu.hpp @@ -26,7 +26,7 @@ struct APU : Z80, Z80::Bus, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto enable(bool) -> void; auto power(bool reset) -> void; @@ -36,26 +36,26 @@ struct APU : Z80, Z80::Bus, Thread { auto setINT(bool value) -> void; //bus.cpp - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto in(uint16 address) -> uint8 override; - auto out(uint16 address, uint8 data) -> void override; + auto in(n16 address) -> n8 override; + auto out(n16 address, n8 data) -> void override; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; private: - Memory::Writable ram; + Memory::Writable ram; struct IO { - uint9 bank; + n9 bank; } io; struct State { - uint1 enabled; - uint1 nmiLine; - uint1 intLine; + n1 enabled; + n1 nmiLine; + n1 intLine; } state; }; diff --git a/ares/md/apu/bus.cpp b/ares/md/apu/bus.cpp index 75676d6fc3..a03aea88ea 100644 --- a/ares/md/apu/bus.cpp +++ b/ares/md/apu/bus.cpp @@ -5,7 +5,7 @@ * for now, assume that only the cartridge and expansion buses are also accessible. */ -auto APU::read(uint16 address) -> uint8 { +auto APU::read(n16 address) -> n8 { //$2000-3fff mirrors $0000-1fff if(address >= 0x0000 && address <= 0x3fff) return ram.read(address); if(address >= 0x4000 && address <= 0x4003) return ym2612.readStatus(); @@ -19,7 +19,7 @@ auto APU::read(uint16 address) -> uint8 { cpu.idle(11); step(3); - uint24 location = io.bank << 15 | (uint15)address & ~1; + n24 location = io.bank << 15 | (n15)address & ~1; if(location >= 0xa00000 && location <= 0xffffff) { //todo: apparently *some* I/O addresses can be read or written from the Z80. //it is not currently known which addresses are accepted. @@ -34,7 +34,7 @@ auto APU::read(uint16 address) -> uint8 { return 0x00; } -auto APU::write(uint16 address, uint8 data) -> void { +auto APU::write(n16 address, n8 data) -> void { //$2000-3fff mirrors $0000-1fff if(address >= 0x0000 && address <= 0x3fff) return ram.write(address, data); if(address == 0x4000) return ym2612.writeAddress(0 << 8 | data); @@ -56,7 +56,7 @@ auto APU::write(uint16 address, uint8 data) -> void { cpu.idle(11); step(3); - uint24 location = io.bank << 15 | (uint15)address; + n24 location = io.bank << 15 | (n15)address; if(location >= 0xa00000 && location <= 0xdfffff) return; if(address & 1) { return cpu.write(0, 1, location & ~1, data << 8 | data << 0); @@ -67,10 +67,10 @@ auto APU::write(uint16 address, uint8 data) -> void { } //unused on Mega Drive -auto APU::in(uint16 address) -> uint8 { +auto APU::in(n16 address) -> n8 { return 0x00; } //unused on Mega Drive -auto APU::out(uint16 address, uint8 data) -> void { +auto APU::out(n16 address, n8 data) -> void { } diff --git a/ares/md/cartridge/board/banked.cpp b/ares/md/cartridge/board/banked.cpp index 475ac25614..6f33fdc441 100644 --- a/ares/md/cartridge/board/banked.cpp +++ b/ares/md/cartridge/board/banked.cpp @@ -1,6 +1,6 @@ struct Banked : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -11,19 +11,19 @@ struct Banked : Interface { auto board = document["game/board"]; } - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 override { - uint25 offset = romBank[address >> 19] << 19 | (uint19)address; + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16 override { + n25 offset = romBank[address >> 19] << 19 | (n19)address; return data = rom[offset >> 1]; } - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void override { + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void override { } - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 override { + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 override { return data; } - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override { + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void override { if(!lower) return; //todo: unconfirmed if(address == 0xa130f2) romBank[1] = data.bit(0,5); if(address == 0xa130f4) romBank[2] = data.bit(0,5); @@ -35,12 +35,12 @@ struct Banked : Interface { } auto power() -> void override { - for(uint index : range(8)) romBank[index] = index; + for(u32 index : range(8)) romBank[index] = index; } auto serialize(serializer& s) -> void override { s(romBank); } - uint6 romBank[8]; + n6 romBank[8]; }; diff --git a/ares/md/cartridge/board/board.cpp b/ares/md/cartridge/board/board.cpp index 830cf6cb22..56eb7d09d5 100644 --- a/ares/md/cartridge/board/board.cpp +++ b/ares/md/cartridge/board/board.cpp @@ -5,62 +5,62 @@ namespace Board { #include "lock-on.cpp" #include "game-genie.cpp" -auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural() >> 1); auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); if(auto fp = platform->open(cartridge->node, name, File::Read, File::Required)) { - for(uint address : range(memory.size())) memory.program(address, fp->readm(2)); + for(u32 address : range(memory.size())) memory.program(address, fp->readm(2)); return true; } return false; } -auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["mode"].string() != "word") return false; memory.allocate(node["size"].natural() >> 1); if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); if(auto fp = platform->open(cartridge->node, name, File::Read)) { - for(uint address : range(memory.size())) memory.write(address, fp->readm(2)); + for(u32 address : range(memory.size())) memory.write(address, fp->readm(2)); return true; } return false; } -auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["mode"].string() == "word") return false; memory.allocate(node["size"].natural()); if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); if(auto fp = platform->open(cartridge->node, name, File::Read)) { - for(uint address : range(memory.size())) memory.write(address, fp->readm(1)); + for(u32 address : range(memory.size())) memory.write(address, fp->readm(1)); return true; } return false; } -auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["mode"].string() != "word") return false; if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); if(auto fp = platform->open(cartridge->node, name, File::Write)) { - for(uint address : range(memory.size())) fp->writem(memory[address], 2); + for(u32 address : range(memory.size())) fp->writem(memory[address], 2); return true; } return false; } -auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["mode"].string() == "word") return false; if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); if(auto fp = platform->open(cartridge->node, name, File::Write)) { - for(uint address : range(memory.size())) fp->writem(memory[address], 1); + for(u32 address : range(memory.size())) fp->writem(memory[address], 1); return true; } return false; diff --git a/ares/md/cartridge/board/board.hpp b/ares/md/cartridge/board/board.hpp index 8df43ccb42..6a61a7372f 100644 --- a/ares/md/cartridge/board/board.hpp +++ b/ares/md/cartridge/board/board.hpp @@ -5,19 +5,19 @@ struct Interface { virtual ~Interface() = default; virtual auto load(Markup::Node) -> void {} virtual auto save(Markup::Node) -> void {} - virtual auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 { return 0; } - virtual auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void {} - virtual auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { return 0; } - virtual auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void {} + virtual auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16 { return 0; } + virtual auto write(n1 upper, n1 lower, n22 address, n16 data) -> void {} + virtual auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { return 0; } + virtual auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void {} virtual auto power() -> void {} virtual auto serialize(serializer&) -> void {} - auto load(Memory::Readable& memory, Markup::Node node) -> bool; - auto load(Memory::Writable& memory, Markup::Node node) -> bool; - auto load(Memory::Writable< uint8>& memory, Markup::Node node) -> bool; + auto load(Memory::Readable& memory, Markup::Node node) -> bool; + auto load(Memory::Writable& memory, Markup::Node node) -> bool; + auto load(Memory::Writable& memory, Markup::Node node) -> bool; - auto save(Memory::Writable& memory, Markup::Node node) -> bool; - auto save(Memory::Writable< uint8>& memory, Markup::Node node) -> bool; + auto save(Memory::Writable& memory, Markup::Node node) -> bool; + auto save(Memory::Writable& memory, Markup::Node node) -> bool; maybe cartridge; }; diff --git a/ares/md/cartridge/board/game-genie.cpp b/ares/md/cartridge/board/game-genie.cpp index 9a294e6b68..a08acb07da 100644 --- a/ares/md/cartridge/board/game-genie.cpp +++ b/ares/md/cartridge/board/game-genie.cpp @@ -1,6 +1,6 @@ struct GameGenie : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; CartridgeSlot slot{"Cartridge Slot"}; auto load(Markup::Node document) -> void override { @@ -14,7 +14,7 @@ struct GameGenie : Interface { auto board = document["game/board"]; } - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 override { + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16 override { if(enable) { for(auto& code : codes) { if(code.enable && code.address == address) return data = code.data; @@ -24,7 +24,7 @@ struct GameGenie : Interface { return data = rom[address >> 1]; } - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void override { + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void override { if(enable) { if(slot.connected()) return slot.cartridge.write(upper, lower, address, data); } @@ -40,12 +40,12 @@ struct GameGenie : Interface { } } - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 override { + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 override { if(slot.connected()) slot.cartridge.readIO(upper, lower, address, data); return data; } - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override { + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void override { if(slot.connected()) slot.cartridge.writeIO(upper, lower, address, data); } @@ -55,7 +55,7 @@ struct GameGenie : Interface { for(auto& code : codes) code = {}; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { if(slot.connected()) s(slot.cartridge); s(enable); for(auto& code : codes) { @@ -65,10 +65,10 @@ struct GameGenie : Interface { } } - uint1 enable; + n1 enable; struct Code { - uint1 enable; - uint24 address; - uint16 data; + n1 enable; + n24 address; + n16 data; } codes[5]; }; diff --git a/ares/md/cartridge/board/linear.cpp b/ares/md/cartridge/board/linear.cpp index 66539eaf59..daf1576c13 100644 --- a/ares/md/cartridge/board/linear.cpp +++ b/ares/md/cartridge/board/linear.cpp @@ -1,8 +1,8 @@ struct Linear : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable wram; - Memory::Writable< uint8> bram; + Memory::Readable rom; + Memory::Writable wram; + Memory::Writable bram; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -17,7 +17,7 @@ struct Linear : Interface { Interface::save(bram, board["memory(type=RAM,content=Save)"]); } - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 override { + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16 override { if(address >= 0x200000 && ramEnable) { if(wram) return data = wram[address >> 1]; if(bram) return data = bram[address >> 1] * 0x0101; //todo: unconfirmed @@ -25,7 +25,7 @@ struct Linear : Interface { return data = rom[address >> 1]; } - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void override { + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void override { //emulating ramWritable will break commercial software: //it does not appear that many (any?) games actually connect $a130f1.d1 to /WE; //hence RAM ends up always being writable, and many games fail to set d1=1 @@ -42,11 +42,11 @@ struct Linear : Interface { } } - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 override { + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 override { return data; } - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override { + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void override { if(!lower) return; //todo: unconfirmed if(address == 0xa130f0) { ramEnable = data.bit(0); @@ -66,6 +66,6 @@ struct Linear : Interface { s(ramWritable); } - uint1 ramEnable = 1; - uint1 ramWritable = 1; + n1 ramEnable = 1; + n1 ramWritable = 1; }; diff --git a/ares/md/cartridge/board/lock-on.cpp b/ares/md/cartridge/board/lock-on.cpp index bd23b97dae..cd9f68587a 100644 --- a/ares/md/cartridge/board/lock-on.cpp +++ b/ares/md/cartridge/board/lock-on.cpp @@ -1,7 +1,7 @@ struct LockOn : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Readable patch; + Memory::Readable rom; + Memory::Readable patch; CartridgeSlot slot{"Cartridge Slot"}; auto load(Markup::Node document) -> void override { @@ -16,23 +16,23 @@ struct LockOn : Interface { auto board = document["game/board"]; } - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 override { + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16 override { if(address < 0x200000) return data = rom[address >> 1]; if(address >= 0x300000 && patchEnable) return data = patch[address >> 1]; if(slot.connected()) return data = slot.cartridge.read(upper, lower, address, data); return data; } - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void override { + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void override { if(slot.connected()) slot.cartridge.write(upper, lower, address, data); } - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 override { + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 override { if(slot.connected()) slot.cartridge.readIO(upper, lower, address, data); return data; } - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override { + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void override { if(slot.connected()) slot.cartridge.writeIO(upper, lower, address, data); if(!lower) return; //todo: unconfirmed if(address == 0xa130f0) patchEnable = data.bit(0); @@ -48,5 +48,5 @@ struct LockOn : Interface { s(patchEnable); } - uint1 patchEnable; + n1 patchEnable; }; diff --git a/ares/md/cartridge/cartridge.cpp b/ares/md/cartridge/cartridge.cpp index e9ce17e55f..2156397120 100644 --- a/ares/md/cartridge/cartridge.cpp +++ b/ares/md/cartridge/cartridge.cpp @@ -56,19 +56,19 @@ auto Cartridge::power() -> void { board->power(); } -auto Cartridge::read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 { +auto Cartridge::read(n1 upper, n1 lower, n22 address, n16 data) -> n16 { return board->read(upper, lower, address, data); } -auto Cartridge::write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void { +auto Cartridge::write(n1 upper, n1 lower, n22 address, n16 data) -> void { return board->write(upper, lower, address, data); } -auto Cartridge::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto Cartridge::readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { return board->readIO(upper, lower, address, data); } -auto Cartridge::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto Cartridge::writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void { return board->writeIO(upper, lower, address, data); } diff --git a/ares/md/cartridge/cartridge.hpp b/ares/md/cartridge/cartridge.hpp index 3c6d982021..2d59be6438 100644 --- a/ares/md/cartridge/cartridge.hpp +++ b/ares/md/cartridge/cartridge.hpp @@ -17,11 +17,11 @@ struct Cartridge { auto save() -> void; auto power() -> void; - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16; - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void; + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16; + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void; - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16; - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void; + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16; + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/md/controller/control-pad/control-pad.cpp b/ares/md/controller/control-pad/control-pad.cpp index bcd30c010a..8ba778c3af 100644 --- a/ares/md/controller/control-pad/control-pad.cpp +++ b/ares/md/controller/control-pad/control-pad.cpp @@ -11,8 +11,8 @@ ControlPad::ControlPad(Node::Port parent) { start = node->append("Start"); } -auto ControlPad::readData() -> uint8 { - uint6 data; +auto ControlPad::readData() -> n8 { + n6 data; platform->input(up); platform->input(down); @@ -54,7 +54,7 @@ auto ControlPad::readData() -> uint8 { return latch << 7 | select << 6 | data; } -auto ControlPad::writeData(uint8 data) -> void { +auto ControlPad::writeData(n8 data) -> void { select = data.bit(6); latch = data.bit(7); } diff --git a/ares/md/controller/control-pad/control-pad.hpp b/ares/md/controller/control-pad/control-pad.hpp index 185be85bab..0f4d4b86c5 100644 --- a/ares/md/controller/control-pad/control-pad.hpp +++ b/ares/md/controller/control-pad/control-pad.hpp @@ -10,17 +10,17 @@ struct ControlPad : Controller { ControlPad(Node::Port); - auto readData() -> uint8 override; - auto writeData(uint8 data) -> void override; + auto readData() -> n8 override; + auto writeData(n8 data) -> void override; private: - uint1 select = 1; - uint1 latch; + n1 select = 1; + n1 latch; - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/md/controller/controller.hpp b/ares/md/controller/controller.hpp index b6f5d985a2..56d5194bc2 100644 --- a/ares/md/controller/controller.hpp +++ b/ares/md/controller/controller.hpp @@ -3,8 +3,8 @@ struct Controller { virtual ~Controller() = default; - virtual auto readData() -> uint8 { return 0xff; } - virtual auto writeData(uint8 data) -> void {} + virtual auto readData() -> n8 { return 0xff; } + virtual auto writeData(n8 data) -> void {} }; #include "port.hpp" diff --git a/ares/md/controller/fighting-pad/fighting-pad.cpp b/ares/md/controller/fighting-pad/fighting-pad.cpp index 35457fa615..0ba82778d2 100644 --- a/ares/md/controller/fighting-pad/fighting-pad.cpp +++ b/ares/md/controller/fighting-pad/fighting-pad.cpp @@ -27,7 +27,7 @@ auto FightingPad::main() -> void { Thread::synchronize(cpu); } -auto FightingPad::readData() -> uint8 { +auto FightingPad::readData() -> n8 { platform->input(up); platform->input(down); platform->input(left); @@ -53,7 +53,7 @@ auto FightingPad::readData() -> uint8 { xHold = 1, swap(leftLatch, rightLatch); } - uint6 data; + n6 data; if(select == 0) { if(counter == 0 || counter == 1 || counter == 4) { @@ -95,7 +95,7 @@ auto FightingPad::readData() -> uint8 { return latch << 7 | select << 6 | data; } -auto FightingPad::writeData(uint8 data) -> void { +auto FightingPad::writeData(n8 data) -> void { if(!select && data.bit(6)) { //0->1 transition if(++counter == 5) counter = 0; } diff --git a/ares/md/controller/fighting-pad/fighting-pad.hpp b/ares/md/controller/fighting-pad/fighting-pad.hpp index b692d70256..d541a507da 100644 --- a/ares/md/controller/fighting-pad/fighting-pad.hpp +++ b/ares/md/controller/fighting-pad/fighting-pad.hpp @@ -14,19 +14,19 @@ struct FightingPad : Controller, Thread { FightingPad(Node::Port); auto main() -> void; - auto readData() -> uint8 override; - auto writeData(uint8 data) -> void override; + auto readData() -> n8 override; + auto writeData(n8 data) -> void override; private: - uint1 select = 1; - uint1 latch; - uint3 counter; - uint32 timeout; + n1 select = 1; + n1 latch; + n3 counter; + n32 timeout; - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/md/controller/port.hpp b/ares/md/controller/port.hpp index 418bd26b11..5072bca584 100644 --- a/ares/md/controller/port.hpp +++ b/ares/md/controller/port.hpp @@ -11,18 +11,18 @@ struct ControllerPort { auto connect(Node::Peripheral) -> void; auto disconnect() -> void; - auto readControl() -> uint8 { return control; } - auto writeControl(uint8 data) -> void { control = data; } + auto readControl() -> n8 { return control; } + auto writeControl(n8 data) -> void { control = data; } - auto readData() -> uint8 { if(device) return device->readData(); return 0xff; } - auto writeData(uint8 data) -> void { if(device) return device->writeData(data); } + auto readData() -> n8 { if(device) return device->readData(); return 0xff; } + auto writeData(n8 data) -> void { if(device) return device->writeData(data); } auto power() -> void; auto serialize(serializer&) -> void; protected: const string name; - uint8 control; + n8 control; friend class Controller; }; diff --git a/ares/md/cpu/bus.cpp b/ares/md/cpu/bus.cpp index b84286e8b6..943bedca0b 100644 --- a/ares/md/cpu/bus.cpp +++ b/ares/md/cpu/bus.cpp @@ -3,7 +3,7 @@ * byte writes to word memory areas that are addressable as bytes cannot enjoy this optimization. */ -auto CPU::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto CPU::read(n1 upper, n1 lower, n24 address, n16 data) -> n16 { if(address >= 0x000000 && address <= 0x3fffff) { //if(refresh.external >= 126) idle(min(2, 128 - refresh.external)); if(!io.romEnable) return tmss[address >> 1]; @@ -57,7 +57,7 @@ auto CPU::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 return data; } -auto CPU::write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto CPU::write(n1 upper, n1 lower, n24 address, n16 data) -> void { if(address >= 0x000000 && address <= 0x3fffff) { //if(refresh.external >= 126) idle(min(2, 128 - refresh.external)); if(cartridge.bootable()) { diff --git a/ares/md/cpu/cpu.cpp b/ares/md/cpu/cpu.cpp index f045a119f4..a06ee9a9b0 100644 --- a/ares/md/cpu/cpu.cpp +++ b/ares/md/cpu/cpu.cpp @@ -21,8 +21,8 @@ auto CPU::unload() -> void { auto CPU::main() -> void { if(state.interruptPending) { - if(state.interruptPending.bit((uint)Interrupt::Reset)) { - state.interruptPending.bit((uint)Interrupt::Reset) = 0; + if(state.interruptPending.bit((u32)Interrupt::Reset)) { + state.interruptPending.bit((u32)Interrupt::Reset) = 0; r.a[7] = read(1, 1, 0) << 16 | read(1, 1, 2) << 0; r.pc = read(1, 1, 4) << 16 | read(1, 1, 6) << 0; prefetch(); @@ -30,17 +30,17 @@ auto CPU::main() -> void { debugger.interrupt("Reset"); } - if(state.interruptPending.bit((uint)Interrupt::HorizontalBlank)) { + if(state.interruptPending.bit((u32)Interrupt::HorizontalBlank)) { if(4 > r.i) { - state.interruptPending.bit((uint)Interrupt::HorizontalBlank) = 0; + state.interruptPending.bit((u32)Interrupt::HorizontalBlank) = 0; debugger.interrupt("Hblank"); return interrupt(Vector::Level4, 4); } } - if(state.interruptPending.bit((uint)Interrupt::VerticalBlank)) { + if(state.interruptPending.bit((u32)Interrupt::VerticalBlank)) { if(6 > r.i) { - state.interruptPending.bit((uint)Interrupt::VerticalBlank) = 0; + state.interruptPending.bit((u32)Interrupt::VerticalBlank) = 0; debugger.interrupt("Vblank"); return interrupt(Vector::Level6, 6); } @@ -51,18 +51,18 @@ auto CPU::main() -> void { instruction(); } -inline auto CPU::step(uint clocks) -> void { +inline auto CPU::step(u32 clocks) -> void { refresh.ram += clocks; while(refresh.ram >= 133) refresh.ram -= 133; refresh.external += clocks; Thread::step(clocks); } -inline auto CPU::idle(uint clocks) -> void { +inline auto CPU::idle(u32 clocks) -> void { step(clocks); } -auto CPU::wait(uint clocks) -> void { +auto CPU::wait(u32 clocks) -> void { while(vdp.dma.active) { Thread::step(1); Thread::synchronize(vdp); @@ -73,15 +73,15 @@ auto CPU::wait(uint clocks) -> void { } auto CPU::raise(Interrupt interrupt) -> void { - if(!state.interruptLine.bit((uint)interrupt)) { - state.interruptLine.bit((uint)interrupt) = 1; - state.interruptPending.bit((uint)interrupt) = 1; + if(!state.interruptLine.bit((u32)interrupt)) { + state.interruptLine.bit((u32)interrupt) = 1; + state.interruptPending.bit((u32)interrupt) = 1; } } auto CPU::lower(Interrupt interrupt) -> void { - state.interruptLine.bit((uint)interrupt) = 0; - state.interruptPending.bit((uint)interrupt) = 0; + state.interruptLine.bit((u32)interrupt) = 0; + state.interruptPending.bit((u32)interrupt) = 0; } auto CPU::power(bool reset) -> void { @@ -94,7 +94,7 @@ auto CPU::power(bool reset) -> void { if(system.tmss->value()) { tmss.allocate(2_KiB >> 1); if(auto fp = platform->open(system.node, "tmss.rom", File::Read, File::Required)) { - for(uint address : range(tmss.size())) tmss.program(address, fp->readm(2)); + for(u32 address : range(tmss.size())) tmss.program(address, fp->readm(2)); tmssEnable = true; } } @@ -110,7 +110,7 @@ auto CPU::power(bool reset) -> void { refresh = {}; state = {}; - state.interruptPending.bit((uint)Interrupt::Reset) = 1; + state.interruptPending.bit((u32)Interrupt::Reset) = 1; } } diff --git a/ares/md/cpu/cpu.hpp b/ares/md/cpu/cpu.hpp index a80ae24104..aecc7f252b 100644 --- a/ares/md/cpu/cpu.hpp +++ b/ares/md/cpu/cpu.hpp @@ -19,7 +19,7 @@ struct CPU : M68K, Thread { } tracer; } debugger; - enum class Interrupt : uint { + enum class Interrupt : u32 { Reset, HorizontalBlank, VerticalBlank, @@ -30,9 +30,9 @@ struct CPU : M68K, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; - auto idle(uint clocks) -> void override; - auto wait(uint clocks) -> void override; + auto step(u32 clocks) -> void; + auto idle(u32 clocks) -> void override; + auto wait(u32 clocks) -> void override; auto raise(Interrupt) -> void; auto lower(Interrupt) -> void; @@ -40,35 +40,35 @@ struct CPU : M68K, Thread { auto power(bool reset) -> void; //bus.cpp - auto read(uint1 upper, uint1 lower, uint24 address, uint16 data = 0) -> uint16 override; - auto write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override; + auto read(n1 upper, n1 lower, n24 address, n16 data = 0) -> n16 override; + auto write(n1 upper, n1 lower, n24 address, n16 data) -> void override; //io.cpp - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16; - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void; + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16; + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; private: - Memory::Writable ram; - Memory::Readable tmss; - uint1 tmssEnable; + Memory::Writable ram; + Memory::Readable tmss; + n1 tmssEnable; struct IO { - boolean version; //0 = Model 1; 1 = Model 2+ - boolean romEnable; - boolean vdpEnable[2]; + b1 version; //0 = Model 1; 1 = Model 2+ + b1 romEnable; + b1 vdpEnable[2]; } io; struct Refresh { - uint32 ram; - uint7 external; + n32 ram; + n7 external; } refresh; struct State { - uint32 interruptLine; - uint32 interruptPending; + n32 interruptLine; + n32 interruptPending; } state; }; diff --git a/ares/md/cpu/debugger.cpp b/ares/md/cpu/debugger.cpp index 1292a00307..395186f32c 100644 --- a/ares/md/cpu/debugger.cpp +++ b/ares/md/cpu/debugger.cpp @@ -2,10 +2,10 @@ auto CPU::Debugger::load(Node::Object parent) -> void { memory.ram = parent->append("CPU RAM"); memory.ram->setSize(32_KiB << 1); memory.ram->setRead([&](u32 address) -> u8 { - return cpu.ram[uint15(address >> 1)].byte(!(address & 1)); + return cpu.ram[n15(address >> 1)].byte(!(address & 1)); }); memory.ram->setWrite([&](u32 address, u8 data) -> void { - cpu.ram[uint15(address >> 1)].byte(!(address & 1)) = data; + cpu.ram[n15(address >> 1)].byte(!(address & 1)) = data; }); tracer.instruction = parent->append("Instruction", "CPU"); diff --git a/ares/md/cpu/io.cpp b/ares/md/cpu/io.cpp index 18990485d6..0294399a27 100644 --- a/ares/md/cpu/io.cpp +++ b/ares/md/cpu/io.cpp @@ -1,6 +1,6 @@ /* $a10000-bfffff */ -auto CPU::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto CPU::readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { if(address >= 0xa10000 && address <= 0xa100ff) { if(!lower) return data; //even byte writes ignored address.bit(5,7) = 0; //a10020-a100ff mirrors a10000-a1001f @@ -49,7 +49,7 @@ auto CPU::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 return data; } -auto CPU::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto CPU::writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void { if(address >= 0xa10000 && address <= 0xa100ff) { if(!lower) return; //even byte writes ignored address.bit(5,7) = 0; //a10020-a100ff mirrors a10000-a1001f diff --git a/ares/md/expansion/expansion.cpp b/ares/md/expansion/expansion.cpp index 19b615ca23..979fcfe099 100644 --- a/ares/md/expansion/expansion.cpp +++ b/ares/md/expansion/expansion.cpp @@ -42,20 +42,20 @@ auto Expansion::power() -> void { /* the only existing expansion port device is the Mega CD, which is hard-coded below for now */ -auto Expansion::read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 { +auto Expansion::read(n1 upper, n1 lower, n22 address, n16 data) -> n16 { return mcd.external_read(upper, lower, address, data); } -auto Expansion::write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void { +auto Expansion::write(n1 upper, n1 lower, n22 address, n16 data) -> void { return mcd.external_write(upper, lower, address, data); } -auto Expansion::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto Expansion::readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { if(!node) return data; return mcd.external_readIO(upper, lower, address, data); } -auto Expansion::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto Expansion::writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void { if(!node) return; return mcd.external_writeIO(upper, lower, address, data); } diff --git a/ares/md/expansion/expansion.hpp b/ares/md/expansion/expansion.hpp index a917343176..77a6a56164 100644 --- a/ares/md/expansion/expansion.hpp +++ b/ares/md/expansion/expansion.hpp @@ -17,11 +17,11 @@ struct Expansion { auto save() -> void; auto power() -> void; - auto read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16; - auto write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void; + auto read(n1 upper, n1 lower, n22 address, n16 data) -> n16; + auto write(n1 upper, n1 lower, n22 address, n16 data) -> void; - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16; - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void; + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16; + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/md/mcd/bus-external.cpp b/ares/md/mcd/bus-external.cpp index c34cb87422..0683b24afa 100644 --- a/ares/md/mcd/bus-external.cpp +++ b/ares/md/mcd/bus-external.cpp @@ -1,4 +1,4 @@ -auto MCD::external_read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16 { +auto MCD::external_read(n1 upper, n1 lower, n22 address, n16 data) -> n16 { address.bit(18,20) = 0; //mirrors if(address >= 0x000000 && address <= 0x01ffff) { @@ -6,16 +6,16 @@ auto MCD::external_read(uint1 upper, uint1 lower, uint22 address, uint16 data) - } if(address >= 0x020000 && address <= 0x03ffff) { - address = io.pramBank << 17 | (uint17)address; + address = io.pramBank << 17 | (n17)address; return pram[address >> 1]; } if(address >= 0x200000 && address <= 0x23ffff) { if(io.wramMode == 0) { //if(io.wramSwitch == 1) return data; - address = (uint18)address; + address = (n18)address; } else { - address = (uint17)address << 1 | io.wramSelect == 0; + address = (n17)address << 1 | io.wramSelect == 0; } if(!vdp.active()) return wram[address >> 1]; @@ -30,11 +30,11 @@ auto MCD::external_read(uint1 upper, uint1 lower, uint22 address, uint16 data) - return data; } -auto MCD::external_write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void { +auto MCD::external_write(n1 upper, n1 lower, n22 address, n16 data) -> void { address.bit(18,20) = 0; //mirrors if(address >= 0x020000 && address <= 0x03ffff) { - address = io.pramBank << 17 | (uint17)address; + address = io.pramBank << 17 | (n17)address; if(upper) pram[address >> 1].byte(1) = data.byte(1); if(lower) pram[address >> 1].byte(0) = data.byte(0); return; @@ -43,9 +43,9 @@ auto MCD::external_write(uint1 upper, uint1 lower, uint22 address, uint16 data) if(address >= 0x200000 && address <= 0x23ffff) { if(io.wramMode == 0) { //if(io.wramSwitch == 1) return; - address = (uint18)address; + address = (n18)address; } else { - address = (uint17)address << 1 | io.wramSelect == 0; + address = (n17)address << 1 | io.wramSelect == 0; } if(upper) wram[address >> 1].byte(1) = data.byte(1); if(lower) wram[address >> 1].byte(0) = data.byte(0); diff --git a/ares/md/mcd/bus.cpp b/ares/md/mcd/bus.cpp index f0d01cb7a7..975daef61c 100644 --- a/ares/md/mcd/bus.cpp +++ b/ares/md/mcd/bus.cpp @@ -1,4 +1,4 @@ -auto MCD::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto MCD::read(n1 upper, n1 lower, n24 address, n16 data) -> n16 { address.bit(20,23) = 0; //mirroring if(address >= 0x000000 && address <= 0x07ffff) { @@ -8,9 +8,9 @@ auto MCD::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 if(address >= 0x080000 && address <= 0x0dffff) { if(io.wramMode == 0) { //if(io.wramSwitch == 0) return data; - address = (uint18)address; + address = (n18)address; } else { - address = (uint17)address << 1 | io.wramSelect == 1; + address = (n17)address << 1 | io.wramSelect == 1; } return wram[address >> 1]; } @@ -32,7 +32,7 @@ auto MCD::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 return data; //unreachable } -auto MCD::write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto MCD::write(n1 upper, n1 lower, n24 address, n16 data) -> void { address.bit(20,23) = 0; //mirroring if(address >= 0x000000 && address <= 0x07ffff) { @@ -44,9 +44,9 @@ auto MCD::write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { if(address >= 0x080000 && address <= 0x0dffff) { if(io.wramMode == 0) { //if(io.wramSwitch == 0) return; - address = (uint18)address; + address = (n18)address; } else { - address = (uint17)address << 1 | io.wramSelect == 1; + address = (n17)address << 1 | io.wramSelect == 1; } if(upper) wram[address >> 1].byte(1) = data.byte(1); if(lower) wram[address >> 1].byte(0) = data.byte(0); diff --git a/ares/md/mcd/cdc-transfer.cpp b/ares/md/mcd/cdc-transfer.cpp index 7ec6d45dc4..a2c442aaaa 100644 --- a/ares/md/mcd/cdc-transfer.cpp +++ b/ares/md/mcd/cdc-transfer.cpp @@ -2,20 +2,20 @@ auto MCD::CDC::Transfer::dma() -> void { if(!active) return; if(destination != 4 && destination != 5 && destination != 7) return; - uint16 data = mcd.cdc.ram[uint13(source >> 1)]; + n16 data = mcd.cdc.ram[n13(source >> 1)]; switch(destination) { case 4: //PCM (0x1000 - 0x1fff = PCM RAM active 4KB bank) - mcd.pcm.write(0x1000 | uint12(address >> 1) | 1, data.byte(1)); - mcd.pcm.write(0x1000 | uint12(address >> 1) | 0, data.byte(0)); + mcd.pcm.write(0x1000 | n12(address >> 1) | 1, data.byte(1)); + mcd.pcm.write(0x1000 | n12(address >> 1) | 0, data.byte(0)); address += 2; //PCM DMA requires two 8-bit writes per transfer break; case 5: //PRAM - mcd.write(1, 1, 0x000000 | (uint19)address & ~1, data); + mcd.write(1, 1, 0x000000 | (n19)address & ~1, data); break; case 7: //WRAM - mcd.write(1, 1, 0x080000 | (uint18)address & ~1, data); + mcd.write(1, 1, 0x080000 | (n18)address & ~1, data); break; } @@ -25,10 +25,10 @@ auto MCD::CDC::Transfer::dma() -> void { if(!length--) complete(); } -auto MCD::CDC::Transfer::read() -> uint16 { +auto MCD::CDC::Transfer::read() -> n16 { if(!ready) return 0xffff; - uint16 data = mcd.cdc.ram[uint13(source >> 1)]; + n16 data = mcd.cdc.ram[n13(source >> 1)]; source += 2; if(!length--) complete(); if(!length--) complete(); diff --git a/ares/md/mcd/cdc.cpp b/ares/md/mcd/cdc.cpp index fbd8548cb7..23ba112ff1 100644 --- a/ares/md/mcd/cdc.cpp +++ b/ares/md/mcd/cdc.cpp @@ -14,7 +14,7 @@ auto MCD::CDC::clock() -> void { stopwatch++; } -auto MCD::CDC::decode(int sector) -> void { +auto MCD::CDC::decode(s32 sector) -> void { if(!decoder.enable || !mcd.fd) return; auto [minute, second, frame] = CD::MSF(sector); @@ -33,19 +33,19 @@ auto MCD::CDC::decode(int sector) -> void { //the sync header is written at the tail instead of head. mcd.fd->seek((abs(mcd.cdd.session.leadIn.lba) + sector) * 2448); - for(uint index = 0; index < 12; index += 2) { - ram[uint13(transfer.pointer + index + 2340 >> 1)] = mcd.fd->readm(2); + for(u32 index = 0; index < 12; index += 2) { + ram[n13(transfer.pointer + index + 2340 >> 1)] = mcd.fd->readm(2); } - for(uint index = 0; index < 2340; index += 2) { - ram[uint13(transfer.pointer + index + 0 >> 1)] = mcd.fd->readm(2); + for(u32 index = 0; index < 2340; index += 2) { + ram[n13(transfer.pointer + index + 0 >> 1)] = mcd.fd->readm(2); } } } -auto MCD::CDC::read() -> uint8 { +auto MCD::CDC::read() -> n8 { //print("CDC ", hex(address), " ", "\n"); - uint8 data; + n8 data; switch(address) { @@ -198,7 +198,7 @@ auto MCD::CDC::read() -> uint8 { return data; } -auto MCD::CDC::write(uint8 data) -> void { +auto MCD::CDC::write(n8 data) -> void { //print("CDC ", hex(address), "=", hex(data), "\n"); switch(address) { diff --git a/ares/md/mcd/cdd-dac.cpp b/ares/md/mcd/cdd-dac.cpp index b18357f679..2a6bb76d94 100644 --- a/ares/md/mcd/cdd-dac.cpp +++ b/ares/md/mcd/cdd-dac.cpp @@ -10,9 +10,9 @@ auto MCD::CDD::DAC::unload() -> void { stream = {}; } -auto MCD::CDD::DAC::sample(int16 left, int16 right) -> void { - left = (left * (int)attenuated) / 0x4000 >> 1; - right = (right * (int)attenuated) / 0x4000 >> 1; +auto MCD::CDD::DAC::sample(i16 left, i16 right) -> void { + left = (left * (i32)attenuated) / 0x4000 >> 1; + right = (right * (i32)attenuated) / 0x4000 >> 1; stream->frame(left / 32768.0, right / 32768.0); @@ -23,7 +23,7 @@ auto MCD::CDD::DAC::sample(int16 left, int16 right) -> void { auto MCD::CDD::DAC::reconfigure() -> void { stream->resetFilters(); - double inputFrequency = 0.0; + f64 inputFrequency = 0.0; if(deemphasis == 0) return; //no de-emphasis if(deemphasis == 1) inputFrequency = 44100.0; if(deemphasis == 2) inputFrequency = 32000.0; //unverified behavior diff --git a/ares/md/mcd/cdd.cpp b/ares/md/mcd/cdd.cpp index ff3859be74..494151f7c2 100644 --- a/ares/md/mcd/cdd.cpp +++ b/ares/md/mcd/cdd.cpp @@ -68,8 +68,8 @@ auto MCD::CDD::advance() -> void { } auto MCD::CDD::sample() -> void { - int16 left = 0; - int16 right = 0; + i16 left = 0; + i16 right = 0; if(io.status == Status::Playing) { if(session.tracks[io.track].isAudio()) { mcd.fd->seek((abs(session.leadIn.lba) + io.sector) * 2448 + io.sample); @@ -83,11 +83,11 @@ auto MCD::CDD::sample() -> void { } //convert sector# to normalized sector position on the CD-ROM surface for seek latency calculation -auto MCD::CDD::position(int sector) -> double { - static const double sectors = 7500.0 + 330000.0 + 6750.0; - static const double radius = 0.058 - 0.024; - static const double innerRadius = 0.024 * 0.024; //in mm - static const double outerRadius = 0.058 * 0.058; //in mm +auto MCD::CDD::position(s32 sector) -> double { + static const f64 sectors = 7500.0 + 330000.0 + 6750.0; + static const f64 radius = 0.058 - 0.024; + static const f64 innerRadius = 0.024 * 0.024; //in mm + static const f64 outerRadius = 0.058 * 0.058; //in mm sector += session.leadIn.lba; //convert to natural return sqrt(sector / sectors * (outerRadius - innerRadius) + innerRadius) / radius; @@ -174,7 +174,7 @@ auto MCD::CDD::process() -> void { case Request::TrackStartTime: { if(command[4] > 9 || command[5] > 9) break; - uint track = command[4] * 10 + command[5]; + u32 track = command[4] * 10 + command[5]; auto [minute, second, frame] = CD::MSF(session.tracks[track].indices[1].lba); status[1] = command[3]; status[2] = minute / 10; status[3] = minute % 10; @@ -197,10 +197,10 @@ auto MCD::CDD::process() -> void { } break; case Command::SeekPlay: { - uint minute = command[2] * 10 + command[3]; - uint second = command[4] * 10 + command[5]; - uint frame = command[6] * 10 + command[7]; - int lba = minute * 60 * 75 + second * 75 + frame - 3; + u32 minute = command[2] * 10 + command[3]; + u32 second = command[4] * 10 + command[5]; + u32 frame = command[6] * 10 + command[7]; + s32 lba = minute * 60 * 75 + second * 75 + frame - 3; counter = 0; io.status = Status::Seeking; @@ -217,10 +217,10 @@ auto MCD::CDD::process() -> void { } break; case Command::SeekPause: { - uint minute = command[2] * 10 + command[3]; - uint second = command[4] * 10 + command[5]; - uint frame = command[6] * 10 + command[7]; - int lba = minute * 60 * 75 + second * 75 + frame - 3; + u32 minute = command[2] * 10 + command[3]; + u32 second = command[4] * 10 + command[5]; + u32 frame = command[6] * 10 + command[7]; + s32 lba = minute * 60 * 75 + second * 75 + frame - 3; counter = 0; io.status = Status::Seeking; @@ -252,15 +252,15 @@ auto MCD::CDD::process() -> void { } auto MCD::CDD::valid() -> bool { - uint4 checksum; - for(uint index : range(9)) checksum += command[index]; + n4 checksum; + for(u32 index : range(9)) checksum += command[index]; checksum = ~checksum; return checksum == command[9]; } auto MCD::CDD::checksum() -> void { - uint4 checksum; - for(uint index : range(9)) checksum += status[index]; + n4 checksum; + for(u32 index : range(9)) checksum += status[index]; checksum = ~checksum; status[9] = checksum; } @@ -272,10 +272,10 @@ auto MCD::CDD::insert() -> void { } //read TOC (table of contents) from disc lead-in - uint sectors = min(7500, mcd.fd->size() / 2448); - vector sub; + u32 sectors = mcd.fd->size() / 2448; + vector sub; sub.resize(sectors * 96); - for(uint sector : range(sectors)) { + for(u32 sector : range(sectors)) { mcd.fd->seek(sector * 2448 + 2352); mcd.fd->read(sub.data() + sector * 96, 96); } diff --git a/ares/md/mcd/gpu.cpp b/ares/md/mcd/gpu.cpp index d40125ca3c..9c00a9693c 100644 --- a/ares/md/mcd/gpu.cpp +++ b/ares/md/mcd/gpu.cpp @@ -1,6 +1,6 @@ //Graphics Processing Unit -auto MCD::GPU::step(uint clocks) -> void { +auto MCD::GPU::step(u32 clocks) -> void { if(!active) return; counter += clocks; @@ -15,28 +15,28 @@ auto MCD::GPU::step(uint clocks) -> void { } } -auto MCD::GPU::read(uint19 address) -> uint4 { - uint lo = 12 - ((address & 3) << 2), hi = lo + 3; +auto MCD::GPU::read(n19 address) -> n4 { + u32 lo = 12 - ((address & 3) << 2), hi = lo + 3; return mcd.wram[address >> 2].bit(lo, hi); } -auto MCD::GPU::write(uint19 address, uint4 data) -> void { - uint lo = 12 - ((address & 3) << 2), hi = lo + 3; +auto MCD::GPU::write(n19 address, n4 data) -> void { + u32 lo = 12 - ((address & 3) << 2), hi = lo + 3; mcd.wram[address >> 2].bit(lo, hi) = data; } -auto MCD::GPU::render(uint19 address, uint9 width) -> void { - uint8 stampShift = 11 + 4 + stamp.tile.size; - uint8 mapShift = (4 << stamp.map.size) - stamp.tile.size; +auto MCD::GPU::render(n19 address, n9 width) -> void { + n8 stampShift = 11 + 4 + stamp.tile.size; + n8 mapShift = (4 << stamp.map.size) - stamp.tile.size; - uint2 stampMask = !stamp.tile.size ? 1 : 3; - uint23 mapMask = !stamp.map.size ? 0x07ffff : 0x7fffff; + n2 stampMask = !stamp.tile.size ? 1 : 3; + n23 mapMask = !stamp.map.size ? 0x07ffff : 0x7fffff; - uint24 x = mcd.wram[vector.address++] << 8; //13.3 -> 13.11 - uint24 y = mcd.wram[vector.address++] << 8; //13.3 -> 13.11 + n24 x = mcd.wram[vector.address++] << 8; //13.3 -> 13.11 + n24 y = mcd.wram[vector.address++] << 8; //13.3 -> 13.11 - int16 xstep = mcd.wram[vector.address++]; - int16 ystep = mcd.wram[vector.address++]; + i16 xstep = mcd.wram[vector.address++]; + i16 ystep = mcd.wram[vector.address++]; while(width--) { if(stamp.repeat) { @@ -44,34 +44,34 @@ auto MCD::GPU::render(uint19 address, uint9 width) -> void { y &= mapMask; } - uint4 output; + n4 output; if(bool outside = (x | y) & ~mapMask; !outside) { auto xstamp = x >> stampShift; auto ystamp = y >> stampShift << mapShift; auto data = mcd.wram[stamp.map.address + xstamp + ystamp]; - auto index = uint10(data >> 0); - auto lroll = uint1(data >> 13); //0 = 0 degrees; 1 = 90 degrees - auto hroll = uint1(data >> 14); //0 = 0 degrees; 1 = 180 degrees - auto hflip = uint1(data >> 15); + auto index = n10(data >> 0); + auto lroll = n1 (data >> 13); //0 = 0 degrees; 1 = 90 degrees + auto hroll = n1 (data >> 14); //0 = 0 degrees; 1 = 180 degrees + auto hflip = n1 (data >> 15); if(index) { //stamp index 0 is not rendered - auto xpixel = uint6(x >> 11); - auto ypixel = uint6(y >> 11); + auto xpixel = n6(x >> 11); + auto ypixel = n6(y >> 11); if(hflip) { xpixel = ~xpixel; } if(hroll) { xpixel = ~xpixel; ypixel = ~ypixel; } if(lroll) { auto tpixel = xpixel; xpixel = ~ypixel; ypixel = tpixel; } - uint6 pixel = uint3(xpixel) + uint3(ypixel) * 8; + n6 pixel = n3(xpixel) + n3(ypixel) * 8; xpixel = xpixel >> 3 & stampMask; ypixel = ypixel >> 3 & stampMask; - uint4 cell = ypixel + xpixel * (1 + stampMask); + n4 cell = ypixel + xpixel * (1 + stampMask); output = read(index << 8 | cell << 6 | pixel); } } - uint4 input = read(address); + n4 input = read(address); switch(mcd.io.wramPriority) { case 0: output = output; break; case 1: output = input ? input : output; break; diff --git a/ares/md/mcd/io-external.cpp b/ares/md/mcd/io-external.cpp index d07757ff82..50d5ebbbf3 100644 --- a/ares/md/mcd/io-external.cpp +++ b/ares/md/mcd/io-external.cpp @@ -1,4 +1,4 @@ -auto MCD::external_readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { +auto MCD::external_readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { address.bit(6,7) = 0; //a12040-a120ff mirrors a12000-a1203f if(address == 0xa12000) { @@ -47,19 +47,19 @@ auto MCD::external_readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) } if(address >= 0xa12010 && address <= 0xa1201f) { - uint3 index = address - 0xa12010 >> 1; + n3 index = address - 0xa12010 >> 1; data = communication.command[index]; } if(address >= 0xa12020 && address <= 0xa1202f) { - uint3 index = address - 0xa12020 >> 1; + n3 index = address - 0xa12020 >> 1; data = communication.status[index]; } return data; } -auto MCD::external_writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { +auto MCD::external_writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void { address.bit(6,7) = 0; //a12040-a120ff mirrors a12000-a1203f if(address == 0xa12000) { @@ -112,7 +112,7 @@ auto MCD::external_writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data } if(address >= 0xa12010 && address <= 0xa1201f) { - uint3 index = address - 0xa12010 >> 1; + n3 index = address - 0xa12010 >> 1; if(lower) communication.command[index].byte(0) = data.byte(0); if(upper) communication.command[index].byte(1) = data.byte(1); } diff --git a/ares/md/mcd/io.cpp b/ares/md/mcd/io.cpp index 09f0b5936c..a14dc1ba33 100644 --- a/ares/md/mcd/io.cpp +++ b/ares/md/mcd/io.cpp @@ -1,5 +1,5 @@ -auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16 { - address = 0xff8000 | (uint9)address; +auto MCD::readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16 { + address = 0xff8000 | (n9)address; if(address == 0xff8000) { data.bit(0) = 1; //peripheral ready @@ -57,12 +57,12 @@ auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 } if(address >= 0xff8010 && address <= 0xff801f) { - uint3 index = address - 0xff8010 >> 1; + n3 index = address - 0xff8010 >> 1; data = communication.command[index]; } if(address >= 0xff8020 && address <= 0xff802f) { - uint3 index = address - 0xff8020 >> 1; + n3 index = address - 0xff8020 >> 1; data = communication.status[index]; } @@ -97,7 +97,7 @@ auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 } if(address >= 0xff8038 && address <= 0xff8041) { - uint index = address - 0xff8038; + u32 index = address - 0xff8038; data.bit( 0, 3) = cdd.status[index | 1]; data.bit( 4, 7) = Unmapped; data.bit( 8,11) = cdd.status[index | 0]; @@ -105,7 +105,7 @@ auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 } if(address >= 0xff8042 && address <= 0xff804b) { - uint index = address - 0xff8042; + u32 index = address - 0xff8042; data.bit( 0, 3) = cdd.command[index | 1]; data.bit( 4, 7) = Unmapped; data.bit( 8,11) = cdd.command[index | 0]; @@ -123,7 +123,7 @@ auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 } if(address >= 0xff8050 && address <= 0xff8057) { - uint index = 12 - (address - 0xff8050 << 1); + u32 index = 12 - (address - 0xff8050 << 1); auto foreground = gpu.font.color.foreground; auto background = gpu.font.color.background; data.bit( 0, 3) = gpu.font.data.bit(index | 0) ? foreground : background; @@ -183,8 +183,8 @@ auto MCD::readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint1 return data; } -auto MCD::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void { - address = 0xff8000 | (uint9)address; +auto MCD::writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void { + address = 0xff8000 | (n9)address; if(address == 0xff8000) { if(lower) { @@ -244,7 +244,7 @@ auto MCD::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void } if(address >= 0xff8020 && address <= 0xff802f) { - uint3 index = address - 0xff8020 >> 1; + n3 index = address - 0xff8020 >> 1; if(lower) communication.status[index].byte(0) = data.byte(0); if(upper) communication.status[index].byte(1) = data.byte(1); } @@ -288,7 +288,7 @@ auto MCD::writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void } if(address >= 0xff8042 && address <= 0xff804b) { - uint index = address - 0xff8042; + u32 index = address - 0xff8042; if(lower) cdd.command[index | 1] = data.bit(0, 3); if(upper) cdd.command[index | 0] = data.bit(8,11); if(lower && (index | 1) == 9) { //unconfirmed diff --git a/ares/md/mcd/mcd.cpp b/ares/md/mcd/mcd.cpp index 95df8b8ed7..d6a64ec18d 100644 --- a/ares/md/mcd/mcd.cpp +++ b/ares/md/mcd/mcd.cpp @@ -2,7 +2,7 @@ namespace ares::MegaDrive { -static uint16 Unmapped = 0; +static n16 Unmapped = 0; MCD mcd; #include "bus.cpp" @@ -140,7 +140,7 @@ auto MCD::main() -> void { instruction(); } -auto MCD::step(uint clocks) -> void { +auto MCD::step(u32 clocks) -> void { gpu.step(clocks); counter.divider += clocks; while(counter.divider >= 384) { @@ -164,18 +164,18 @@ auto MCD::step(uint clocks) -> void { Thread::step(clocks); } -auto MCD::idle(uint clocks) -> void { +auto MCD::idle(u32 clocks) -> void { step(clocks); } -auto MCD::wait(uint clocks) -> void { +auto MCD::wait(u32 clocks) -> void { step(clocks); Thread::synchronize(cpu); } auto MCD::power(bool reset) -> void { if(auto fp = platform->open(expansion.node, "program.rom", File::Read, File::Required)) { - for(uint address : range(bios.size())) bios.program(address, fp->readm(2)); + for(u32 address : range(bios.size())) bios.program(address, fp->readm(2)); } M68K::power(); diff --git a/ares/md/mcd/mcd.hpp b/ares/md/mcd/mcd.hpp index b6146ba01a..312a772165 100644 --- a/ares/md/mcd/mcd.hpp +++ b/ares/md/mcd/mcd.hpp @@ -5,10 +5,10 @@ struct MCD : M68K, Thread { Node::Port tray; Node::Peripheral disc; Shared::File fd; - Memory::Readable bios; //BIOS ROM - Memory::Writable pram; //program RAM - Memory::Writable wram; //work RAM - Memory::Writable< uint8> bram; //backup RAM + Memory::Readable bios; //BIOS ROM + Memory::Writable pram; //program RAM + Memory::Writable wram; //work RAM + Memory::Writable bram; //backup RAM struct Debugger { //debugger.cpp @@ -40,26 +40,26 @@ struct MCD : M68K, Thread { auto disconnect() -> void; auto main() -> void; - auto step(uint clocks) -> void; - auto idle(uint clocks) -> void override; - auto wait(uint clocks) -> void override; + auto step(u32 clocks) -> void; + auto idle(u32 clocks) -> void override; + auto wait(u32 clocks) -> void override; auto power(bool reset) -> void; //bus.cpp - auto read(uint1 upper, uint1 lower, uint24 address, uint16 data = 0) -> uint16 override; - auto write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void override; + auto read(n1 upper, n1 lower, n24 address, n16 data = 0) -> n16 override; + auto write(n1 upper, n1 lower, n24 address, n16 data) -> void override; //bus-external.cpp - auto external_read(uint1 upper, uint1 lower, uint22 address, uint16 data) -> uint16; - auto external_write(uint1 upper, uint1 lower, uint22 address, uint16 data) -> void; + auto external_read(n1 upper, n1 lower, n22 address, n16 data) -> n16; + auto external_write(n1 upper, n1 lower, n22 address, n16 data) -> void; //io.cpp - auto readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16; - auto writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void; + auto readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16; + auto writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void; //io-external.cpp - auto external_readIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16; - auto external_writeIO(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void; + auto external_readIO(n1 upper, n1 lower, n24 address, n16 data) -> n16; + auto external_writeIO(n1 upper, n1 lower, n24 address, n16 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -70,28 +70,28 @@ struct MCD : M68K, Thread { } information; struct Counter { - uint16 divider; - uint16 dma; - double pcm = 0.0; + n16 divider; + n16 dma; + f64 pcm = 0.0; } counter; struct IO { - uint1 run; - uint1 request; - uint1 halt = 1; - - uint16 wramLatch; - uint1 wramMode; //MODE: 0 = 2mbit mode, 1 = 1mbit mode - uint1 wramSwitch; - uint1 wramSelect; - uint2 wramPriority; - uint2 pramBank; - uint8 pramProtect; + n1 run; + n1 request; + n1 halt = 1; + + n16 wramLatch; + n1 wramMode; //MODE: 0 = 2mbit mode, 1 = 1mbit mode + n1 wramSwitch; + n1 wramSelect; + n2 wramPriority; + n2 pramBank; + n8 pramProtect; } io; struct LED { - uint1 red; - uint1 green; + n1 red; + n1 green; } led; struct IRQ { @@ -103,12 +103,12 @@ struct MCD : M68K, Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint1 enable; - uint1 pending; + n1 enable; + n1 pending; }; struct IRQs { - uint1 pending; + n1 pending; IRQ reset; IRQ subcode; @@ -119,28 +119,28 @@ struct MCD : M68K, Thread { } external; struct Communcation { - uint8 cfm; - uint8 cfs; - uint16 command[8]; - uint16 status [8]; + n8 cfm; + n8 cfs; + n16 command[8]; + n16 status [8]; } communication; struct CDC { //cdc.cpp auto poll() -> void; auto clock() -> void; - auto decode(int sector) -> void; - auto read() -> uint8; - auto write(uint8 data) -> void; + auto decode(s32 sector) -> void; + auto read() -> n8; + auto write(n8 data) -> void; auto power(bool reset) -> void; //serialization.cpp auto serialize(serializer&) -> void; - Memory::Writable ram; + Memory::Writable ram; - uint4 address; - uint12 stopwatch; + n4 address; + n12 stopwatch; struct IRQ : MCD::IRQ { MCD::IRQ decoder; //DECEIN + DECI @@ -149,27 +149,27 @@ struct MCD : M68K, Thread { } irq; struct Command { - uint8 fifo[8]; //COMIN - uint3 read; - uint3 write; - uint1 empty = 1; + n8 fifo[8]; //COMIN + n3 read; + n3 write; + n1 empty = 1; } command; struct Status { - uint8 fifo[8]; //SBOUT - uint3 read; - uint3 write; - uint1 empty = 1; - uint1 enable; //SOUTEN - uint1 active; //STEN - uint1 busy; //STBSY - uint1 wait; //STWAI + n8 fifo[8]; //SBOUT + n3 read; + n3 write; + n1 empty = 1; + n1 enable; //SOUTEN + n1 active; //STEN + n1 busy; //STBSY + n1 wait; //STWAI } status; struct Transfer { //cdc-transfer.cpp auto dma() -> void; - auto read() -> uint16; + auto read() -> n16; auto start() -> void; auto complete() -> void; auto stop() -> void; @@ -177,70 +177,70 @@ struct MCD : M68K, Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint3 destination; - uint19 address; + n3 destination; + n19 address; - uint16 source; - uint16 target; - uint16 pointer; - uint12 length; + n16 source; + n16 target; + n16 pointer; + n12 length; - uint1 enable; //DOUTEN - uint1 active; //DTEN - uint1 busy; //DTBSY - uint1 wait; //DTWAI - uint1 ready; //DSR - uint1 completed; //EDT + n1 enable; //DOUTEN + n1 active; //DTEN + n1 busy; //DTBSY + n1 wait; //DTWAI + n1 ready; //DSR + n1 completed; //EDT } transfer; - enum : uint { Mode1 = 0, Mode2 = 1 }; - enum : uint { Form1 = 0, Form2 = 1 }; + enum : u32 { Mode1 = 0, Mode2 = 1 }; + enum : u32 { Form1 = 0, Form2 = 1 }; struct Decoder { - uint1 enable; //DECEN - uint1 mode; //MODE - uint1 form; //FORM - uint1 valid; //!VALST + n1 enable; //DECEN + n1 mode; //MODE + n1 form; //FORM + n1 valid; //!VALST } decoder; struct Header { - uint8 minute; - uint8 second; - uint8 frame; - uint8 mode; + n8 minute; + n8 second; + n8 frame; + n8 mode; } header; struct Subheader { - uint8 file; - uint8 channel; - uint8 submode; - uint8 coding; + n8 file; + n8 channel; + n8 submode; + n8 coding; } subheader; struct Control { - uint1 head; //SHDREN: 0 = read header, 1 = read subheader - uint1 mode; //MODE - uint1 form; //FORM - uint1 commandBreak; //CMDBK - uint1 modeByteCheck; //MBCKRQ - uint1 erasureRequest; //ERAMRQ - uint1 writeRequest; //WRRQ - uint1 pCodeCorrection; //PRQ - uint1 qCodeCorrection; //QRQ - uint1 autoCorrection; //AUTOQ - uint1 errorCorrection; //E01RQ - uint1 edcCorrection; //EDCRQ - uint1 correctionWrite; //COWREN - uint1 descramble; //DSCREN - uint1 syncDetection; //SYDEN - uint1 syncInterrupt; //SYIEN - uint1 erasureCorrection; //ERAMSL - uint1 statusTrigger; //STENTRG - uint1 statusControl; //STENCTL + n1 head; //SHDREN: 0 = read header, 1 = read subheader + n1 mode; //MODE + n1 form; //FORM + n1 commandBreak; //CMDBK + n1 modeByteCheck; //MBCKRQ + n1 erasureRequest; //ERAMRQ + n1 writeRequest; //WRRQ + n1 pCodeCorrection; //PRQ + n1 qCodeCorrection; //QRQ + n1 autoCorrection; //AUTOQ + n1 errorCorrection; //E01RQ + n1 edcCorrection; //EDCRQ + n1 correctionWrite; //COWREN + n1 descramble; //DSCREN + n1 syncDetection; //SYDEN + n1 syncInterrupt; //SYIEN + n1 erasureCorrection; //ERAMSL + n1 statusTrigger; //STENTRG + n1 statusControl; //STENCTL } control; } cdc; struct CDD { - struct Status { enum : uint { + struct Status { enum : u32 { Stopped = 0x0, //motor disabled Playing = 0x1, //data or audio playback in progress Seeking = 0x2, //move to specified time @@ -259,7 +259,7 @@ struct MCD : M68K, Thread { Test = 0xf, //in test mode };}; - struct Command { enum : uint { + struct Command { enum : u32 { Idle = 0x0, //no operation Stop = 0x1, //stop motor Request = 0x2, //change report type @@ -275,7 +275,7 @@ struct MCD : M68K, Thread { DoorOpen = 0xd, //open the door };}; - struct Request { enum : uint { + struct Request { enum : u32 { AbsoluteTime = 0x0, RelativeTime = 0x1, TrackInformation = 0x2, @@ -294,7 +294,7 @@ struct MCD : M68K, Thread { auto clock() -> void; auto advance() -> void; auto sample() -> void; - auto position(int sector) -> double; + auto position(s32 sector) -> double; auto process() -> void; auto valid() -> bool; auto checksum() -> void; @@ -307,7 +307,7 @@ struct MCD : M68K, Thread { CD::Session session; IRQ irq; - uint16 counter; + n16 counter; struct DAC { Node::Audio::Stream stream; @@ -316,29 +316,29 @@ struct MCD : M68K, Thread { auto load(Node::Object) -> void; auto unload() -> void; - auto sample(int16 left, int16 right) -> void; + auto sample(i16 left, i16 right) -> void; auto reconfigure() -> void; auto power(bool reset) -> void; - uint1 rate; //0 = normal, 1 = double - uint2 deemphasis; //0 = off, 1 = 44100hz, 2 = 32000hz, 3 = 48000hz - uint16 attenuator; //only d6-d15 are used for the coefficient - uint16 attenuated; //current coefficent + n1 rate; //0 = normal, 1 = double + n2 deemphasis; //0 = off, 1 = 44100hz, 2 = 32000hz, 3 = 48000hz + n16 attenuator; //only d6-d15 are used for the coefficient + n16 attenuated; //current coefficent } dac; struct IO { - uint4 status = Status::NoDisc; - uint4 seeking; //status after seeking (Playing or Paused) - uint16 latency; - int32 sector; //current frame# - uint16 sample; //current audio sample# within current frame - uint7 track; //current track# + n4 status = Status::NoDisc; + n4 seeking; //status after seeking (Playing or Paused) + n16 latency; + i32 sector; //current frame# + n16 sample; //current audio sample# within current frame + n7 track; //current track# } io; - uint1 hostClockEnable; - uint1 statusPending; - uint4 status [10]; - uint4 command[10]; + n1 hostClockEnable; + n1 statusPending; + n4 status [10]; + n4 command[10]; } cdd; struct Timer { @@ -350,15 +350,15 @@ struct MCD : M68K, Thread { auto serialize(serializer&) -> void; IRQ irq; - uint8 counter; + n8 counter; } timer; struct GPU { //gpu.cpp - auto step(uint clocks) -> void; - auto read(uint19 address) -> uint4; - auto write(uint19 address, uint4 data) -> void; - auto render(uint19 address, uint9 width) -> void; + auto step(u32 clocks) -> void; + auto read(n19 address) -> n4; + auto write(n19 address, n4 data) -> void; + auto render(n19 address, n9 width) -> void; auto start() -> void; auto power(bool reset) -> void; @@ -369,76 +369,76 @@ struct MCD : M68K, Thread { struct Font { struct Color { - uint4 background; - uint4 foreground; + n4 background; + n4 foreground; } color; - uint16 data; + n16 data; } font; struct Stamp { - uint1 repeat; + n1 repeat; struct Tile { - uint1 size; //0 = 16x16, 1 = 32x32 + n1 size; //0 = 16x16, 1 = 32x32 } tile; struct Map { - uint1 size; //0 = 1x1, 1 = 16x16 - uint18 base; - uint19 address; + n1 size; //0 = 1x1, 1 = 16x16 + n18 base; + n19 address; } map; } stamp; struct Image { - uint18 base; - uint6 offset; - uint5 vcells; - uint8 vdots; - uint9 hdots; - uint19 address; + n18 base; + n6 offset; + n5 vcells; + n8 vdots; + n9 hdots; + n19 address; } image; struct Vector { - uint18 base; - uint17 address; + n18 base; + n17 address; } vector; - uint1 active; - uint32 counter; - uint32 period; + n1 active; + n32 counter; + n32 period; } gpu; struct PCM { Node::Audio::Stream stream; - Memory::Writable ram; + Memory::Writable ram; //pcm.cpp auto load(Node::Object) -> void; auto unload() -> void; auto clock() -> void; - auto read(uint13 address, uint8 data) -> uint8; - auto write(uint13 address, uint8 data) -> void; + auto read(n13 address, n8 data) -> n8; + auto write(n13 address, n8 data) -> void; auto power(bool reset) -> void; //serialization.cpp auto serialize(serializer&) -> void; struct IO { - uint1 enable; - uint4 bank; - uint3 channel; + n1 enable; + n4 bank; + n3 channel; } io; struct Channel { //serialization.cpp auto serialize(serializer&) -> void; - uint1 enable; - uint8 envelope; - uint8 pan = 0xff; - uint16 step; - uint16 loop; - uint8 start; - uint27 address; + n1 enable; + n8 envelope; + n8 pan = 0xff; + n16 step; + n16 loop; + n8 start; + n27 address; } channels[8]; } pcm; }; diff --git a/ares/md/mcd/pcm.cpp b/ares/md/mcd/pcm.cpp index aa51c77d3b..63183731ef 100644 --- a/ares/md/mcd/pcm.cpp +++ b/ares/md/mcd/pcm.cpp @@ -15,13 +15,13 @@ auto MCD::PCM::unload() -> void { } auto MCD::PCM::clock() -> void { - int left = 0; - int right = 0; + s32 left = 0; + s32 right = 0; if(io.enable) for(auto& channel : channels) { if(!channel.enable) continue; - int data = ram[channel.address >> 11]; + s32 data = ram[channel.address >> 11]; if(data == 0xff) { //loop? channel.address = channel.loop << 11; data = ram[channel.loop]; @@ -33,8 +33,8 @@ auto MCD::PCM::clock() -> void { } else { data = -(data & 0x7f); } - left += data * channel.envelope * uint4(channel.pan >> 0) >> 5; - right += data * channel.envelope * uint4(channel.pan >> 4) >> 5; + left += data * channel.envelope * n4(channel.pan >> 0) >> 5; + right += data * channel.envelope * n4(channel.pan >> 4) >> 5; } //clamp to 10-bit DAC output rate @@ -43,15 +43,15 @@ auto MCD::PCM::clock() -> void { stream->frame(left / 32768.0, right / 32768.0); } -auto MCD::PCM::read(uint13 address, uint8 data) -> uint8 { +auto MCD::PCM::read(n13 address, n8 data) -> n8 { if(address >= 0x1000 && address <= 0x1fff) { - data = ram[io.bank << 12 | (uint12)address]; + data = ram[io.bank << 12 | (n12)address]; return data; } if(address >= 0x0010 && address <= 0x001f) { auto& channel = channels[address >> 1 & 7]; - uint16 offset = channel.address >> 11; + n16 offset = channel.address >> 11; data = offset.byte(address & 1); return data; } @@ -59,9 +59,9 @@ auto MCD::PCM::read(uint13 address, uint8 data) -> uint8 { return data = 0xff; } -auto MCD::PCM::write(uint13 address, uint8 data) -> void { +auto MCD::PCM::write(n13 address, n8 data) -> void { if(address >= 0x1000 && address <= 0x1fff) { - ram[io.bank << 12 | (uint12)address] = data; + ram[io.bank << 12 | (n12)address] = data; return; } diff --git a/ares/md/md.hpp b/ares/md/md.hpp index 91eaa2988e..db26c4399c 100644 --- a/ares/md/md.hpp +++ b/ares/md/md.hpp @@ -9,8 +9,10 @@ namespace ares::MegaDrive { #include + auto enumerate() -> vector; + auto load(Node::System& node, string name) -> bool; - enum : uint { + enum : u32 { Byte = 0, Word = 1, }; diff --git a/ares/md/psg/psg.cpp b/ares/md/psg/psg.cpp index 19c16dcd32..3071cade81 100644 --- a/ares/md/psg/psg.cpp +++ b/ares/md/psg/psg.cpp @@ -31,7 +31,7 @@ auto PSG::main() -> void { step(16); } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu, apu); } @@ -40,7 +40,7 @@ auto PSG::power(bool reset) -> void { SN76489::power(); Thread::create(system.frequency() / 15.0, {&PSG::main, this}); - for(uint level : range(15)) { + for(u32 level : range(15)) { volume[level] = pow(2, level * -2.0 / 6.0); } volume[15] = 0; diff --git a/ares/md/psg/psg.hpp b/ares/md/psg/psg.hpp index a652cb967a..da56bd323f 100644 --- a/ares/md/psg/psg.hpp +++ b/ares/md/psg/psg.hpp @@ -7,7 +7,7 @@ struct PSG : SN76489, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; diff --git a/ares/md/system/serialization.cpp b/ares/md/system/serialization.cpp index 4bd38e12bb..34b3a823dd 100644 --- a/ares/md/system/serialization.cpp +++ b/ares/md/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/md/system/system.cpp b/ares/md/system/system.cpp index 334878a249..27a2872370 100644 --- a/ares/md/system/system.cpp +++ b/ares/md/system/system.cpp @@ -2,7 +2,16 @@ namespace ares::MegaDrive { +auto enumerate() -> vector { + return { + "[Sega] Mega Drive (NTSC-J)", + "[Sega] Genesis (NTSC-U)", + "[Sega] Mega Drive (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -36,8 +45,26 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("Mega Drive")) { + information.name = "Mega Drive"; + } + if(name.find("Genesis")) { + information.name = "Mega Drive"; + } + if(name.find("NTSC-J")) { + information.region = Region::NTSCJ; + information.frequency = Constants::Colorburst::NTSC * 15.0; + } + if(name.find("NTSC-U")) { + information.region = Region::NTSCU; + information.frequency = Constants::Colorburst::NTSC * 15.0; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.frequency = Constants::Colorburst::PAL * 12.0; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -49,17 +76,6 @@ auto System::load(Node::System& root, string name) -> bool { tmss = node->append("TMSS", false); - regionNode = node->append("Region", "NTSC-J → NTSC-U → PAL"); - regionNode->setAllowedValues({ - "NTSC-J → NTSC-U → PAL", - "NTSC-U → NTSC-J → PAL", - "PAL → NTSC-J → NTSC-U", - "PAL → NTSC-U → NTSC-J", - "NTSC-J", - "NTSC-U", - "PAL" - }); - scheduler.reset(); controls.load(node); cpu.load(node); @@ -101,28 +117,6 @@ auto System::save() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC-J") { - information.region = Region::NTSCJ; - information.frequency = Constants::Colorburst::NTSC * 15.0; - } - if(region == "NTSC-U") { - information.region = Region::NTSCU; - information.frequency = Constants::Colorburst::NTSC * 15.0; - } - if(region == "PAL") { - information.region = Region::PAL; - information.frequency = Constants::Colorburst::PAL * 12.0; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - auto regionsWant = cartridge.bootable() ? cartridge.regions() : expansion.regions(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - for(auto& want : reverse(regionsWant)) { - if(have == want) setRegion(have); - } - } information.megaCD = (bool)expansion.node; random.entropy(Random::Entropy::Low); diff --git a/ares/md/system/system.hpp b/ares/md/system/system.hpp index e2288aa17b..b55d76a8a0 100644 --- a/ares/md/system/system.hpp +++ b/ares/md/system/system.hpp @@ -3,7 +3,6 @@ extern Random random; struct System { Node::System node; Node::Setting::Boolean tmss; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -14,9 +13,9 @@ struct System { auto poll() -> void; } controls; - enum class Region : uint { NTSCJ, NTSCU, PAL }; + enum class Region : u32 { NTSCJ, NTSCU, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto region() const -> Region { return information.region; } auto megaCD() const -> bool { return information.megaCD; } auto frequency() const -> double { return information.frequency; } @@ -35,6 +34,7 @@ struct System { private: struct Information { + string name = "Mega Drive"; Region region = Region::NTSCJ; bool megaCD = false; double frequency = Constants::Colorburst::NTSC * 15.0; diff --git a/ares/md/vdp-performance/background.cpp b/ares/md/vdp-performance/background.cpp index fd005cc5c3..b1d6a96e7b 100644 --- a/ares/md/vdp-performance/background.cpp +++ b/ares/md/vdp-performance/background.cpp @@ -1,31 +1,31 @@ -auto VDP::Background::renderScreen(uint from, uint to) -> void { - uint nametableWidth = 32 * (1 + io.nametableWidth); - uint nametableWidthMask = nametableWidth - 1; - uint nametableHeightMask = 32 * (1 + io.nametableHeight) - 1; +auto VDP::Background::renderScreen(u32 from, u32 to) -> void { + u32 nametableWidth = 32 * (1 + io.nametableWidth); + u32 nametableWidthMask = nametableWidth - 1; + u32 nametableHeightMask = 32 * (1 + io.nametableHeight) - 1; - static const uint mask[] = {0u, 7u, ~7u, ~0u}; - uint15 scrollAddress = io.horizontalScrollAddress; + static const u32 mask[] = {0u, 7u, ~7u, ~0u}; + n15 scrollAddress = io.horizontalScrollAddress; scrollAddress += (vdp.state.vcounter & mask[io.horizontalScrollMode]) << 1; - uint x = 0 - vdp.vram.memory[scrollAddress + (id == ID::PlaneB)]; + u32 x = 0 - vdp.vram.memory[scrollAddress + (id == ID::PlaneB)]; bool interlace = vdp.io.interlaceMode == 3; - uint tileShift = interlace ? 7 : 6; + u32 tileShift = interlace ? 7 : 6; auto vsram = &vdp.vsram.memory[id == ID::PlaneB]; - uint y = vdp.state.vcounter; + u32 y = vdp.state.vcounter; if(interlace) y = y << 1 | vdp.state.field; y += vdp.vsram.memory[id == ID::PlaneB]; - uint w = from; - uint tileX = x >> 3 & nametableWidthMask; - uint tileY = y >> 3 + interlace & nametableHeightMask; - uint tileY_x_width = tileY * nametableWidth; - uint maskY = interlace ? 15 : 7; - uint address = io.nametableAddress + (tileY_x_width + tileX & 0x0fff); - uint tileAttributes = vdp.vram.memory[address & 0x7fff]; - uint flipX = tileAttributes & 0x0800 ? 7 : 0; - uint flipY = tileAttributes & 0x1000 ? maskY : 0; - uint pixelY = y & maskY ^ flipY; + u32 w = from; + u32 tileX = x >> 3 & nametableWidthMask; + u32 tileY = y >> 3 + interlace & nametableHeightMask; + u32 tileY_x_width = tileY * nametableWidth; + u32 maskY = interlace ? 15 : 7; + u32 address = io.nametableAddress + (tileY_x_width + tileX & 0x0fff); + u32 tileAttributes = vdp.vram.memory[address & 0x7fff]; + u32 flipX = tileAttributes & 0x0800 ? 7 : 0; + u32 flipY = tileAttributes & 0x1000 ? maskY : 0; + u32 pixelY = y & maskY ^ flipY; auto tileData = &vdp.vram.pixels[(tileAttributes << tileShift) + (pixelY << 3) + (x & 7 ^ flipX) & 0x1ffff]; - int incrementX = flipX ? -1 : +1; + s32 incrementX = flipX ? -1 : +1; while(w < to) { pixels[w] = *tileData | tileAttributes >> 13; @@ -61,29 +61,29 @@ auto VDP::Background::renderScreen(uint from, uint to) -> void { } } -auto VDP::Background::renderWindow(uint from, uint to) -> void { +auto VDP::Background::renderWindow(u32 from, u32 to) -> void { bool interlace = vdp.io.interlaceMode == 3; - uint tileShift = interlace ? 7 : 6; + u32 tileShift = interlace ? 7 : 6; - uint y = vdp.state.vcounter; + u32 y = vdp.state.vcounter; if(interlace) y = y << 1 | vdp.state.field; - uint nametableAddress = io.nametableAddress & (vdp.io.displayWidth ? ~0x0400 : ~0); - uint widthSize = 32 << (bool)vdp.io.displayWidth; - uint widthMask = widthSize - 1; + u32 nametableAddress = io.nametableAddress & (vdp.io.displayWidth ? ~0x0400 : ~0); + u32 widthSize = 32 << (bool)vdp.io.displayWidth; + u32 widthMask = widthSize - 1; - uint x = from; - uint tileX = x >> 3 & widthMask; - uint tileY = y >> 3 + interlace & 31; - uint tileY_x_width = tileY * widthSize; - uint maskY = interlace ? 15 : 7; - uint address = nametableAddress + (tileY_x_width + tileX & 0x0fff); - uint tileAttributes = vdp.vram.memory[address & 0x7fff]; - uint flipX = tileAttributes & 0x0800 ? 7 : 0; - uint flipY = tileAttributes & 0x1000 ? maskY : 0; - uint pixelY = y & maskY ^ flipY; + u32 x = from; + u32 tileX = x >> 3 & widthMask; + u32 tileY = y >> 3 + interlace & 31; + u32 tileY_x_width = tileY * widthSize; + u32 maskY = interlace ? 15 : 7; + u32 address = nametableAddress + (tileY_x_width + tileX & 0x0fff); + u32 tileAttributes = vdp.vram.memory[address & 0x7fff]; + u32 flipX = tileAttributes & 0x0800 ? 7 : 0; + u32 flipY = tileAttributes & 0x1000 ? maskY : 0; + u32 pixelY = y & maskY ^ flipY; auto tileData = &vdp.vram.pixels[(tileAttributes << tileShift) + (pixelY << 3) + (x & 7 ^ flipX) & 0x1ffff]; - int incrementX = flipX ? -1 : +1; + s32 incrementX = flipX ? -1 : +1; while(x < to) { vdp.planeA.pixels[x] = *tileData | tileAttributes >> 13; diff --git a/ares/md/vdp-performance/color.cpp b/ares/md/vdp-performance/color.cpp index c586fe70aa..0960d574a5 100644 --- a/ares/md/vdp-performance/color.cpp +++ b/ares/md/vdp-performance/color.cpp @@ -1,18 +1,18 @@ -auto VDP::color(uint32 color) -> uint64 { - uint R = color.bit(0, 2); - uint G = color.bit(3, 5); - uint B = color.bit(6, 8); - uint M = color.bit(9,10); +auto VDP::color(n32 color) -> n64 { + u32 R = color.bit(0, 2); + u32 G = color.bit(3, 5); + u32 B = color.bit(6, 8); + u32 M = color.bit(9,10); - uint lookup[3][8] = { + u32 lookup[3][8] = { { 0, 29, 52, 70, 87, 101, 116, 130}, //shadow { 0, 52, 87, 116, 144, 172, 206, 255}, //normal {130, 144, 158, 172, 187, 206, 228, 255}, //highlight }; - uint64 r = image::normalize(lookup[M][R], 8, 16); - uint64 g = image::normalize(lookup[M][G], 8, 16); - uint64 b = image::normalize(lookup[M][B], 8, 16); + n64 r = image::normalize(lookup[M][R], 8, 16); + n64 g = image::normalize(lookup[M][G], 8, 16); + n64 b = image::normalize(lookup[M][B], 8, 16); return r << 32 | g << 16 | b << 0; } diff --git a/ares/md/vdp-performance/debugger.cpp b/ares/md/vdp-performance/debugger.cpp index 1ca6e99627..a8dc615a3c 100644 --- a/ares/md/vdp-performance/debugger.cpp +++ b/ares/md/vdp-performance/debugger.cpp @@ -2,10 +2,10 @@ auto VDP::Debugger::load(Node::Object parent) -> void { memory.vram = parent->append("VDP VRAM"); memory.vram->setSize(32_KiB << 1); memory.vram->setRead([&](u32 address) -> u8 { - return vdp.vram.memory[uint15(address >> 1)].byte(!(address & 1)); + return vdp.vram.memory[n15(address >> 1)].byte(!(address & 1)); }); memory.vram->setWrite([&](u32 address, u8 data) -> void { - vdp.vram.memory[uint15(address >> 1)].byte(!(address & 1)) = data; + vdp.vram.memory[n15(address >> 1)].byte(!(address & 1)) = data; }); memory.vsram = parent->append("VDP VSRAM"); @@ -22,9 +22,9 @@ auto VDP::Debugger::load(Node::Object parent) -> void { memory.cram = parent->append("VDP CRAM"); memory.cram->setSize(64 << 1); memory.cram->setRead([&](u32 address) -> u8 { - return vdp.cram.memory[uint6(address >> 1)].byte(!(address & 1)); + return vdp.cram.memory[n6(address >> 1)].byte(!(address & 1)); }); memory.cram->setWrite([&](u32 address, u8 data) -> void { - vdp.cram.memory[uint6(address >> 1)].byte(!(address & 1)) = data; + vdp.cram.memory[n6(address >> 1)].byte(!(address & 1)) = data; }); } diff --git a/ares/md/vdp-performance/io.cpp b/ares/md/vdp-performance/io.cpp index 619d2c26db..da44bd1d7e 100644 --- a/ares/md/vdp-performance/io.cpp +++ b/ares/md/vdp-performance/io.cpp @@ -1,4 +1,4 @@ -auto VDP::read(uint24 address, uint16) -> uint16 { +auto VDP::read(n24 address, n16) -> n16 { switch(address & 0xc0001e) { //data port @@ -26,7 +26,7 @@ auto VDP::read(uint24 address, uint16) -> uint16 { return 0x0000; } -auto VDP::write(uint24 address, uint16 data) -> void { +auto VDP::write(n24 address, n16 data) -> void { switch(address & 0xc0001e) { //data port @@ -44,7 +44,7 @@ auto VDP::write(uint24 address, uint16 data) -> void { // -auto VDP::readDataPort() -> uint16 { +auto VDP::readDataPort() -> n16 { io.commandPending = false; //VRAM read @@ -74,7 +74,7 @@ auto VDP::readDataPort() -> uint16 { return 0x0000; } -auto VDP::writeDataPort(uint16 data) -> void { +auto VDP::writeDataPort(n16 data) -> void { io.commandPending = false; //DMA VRAM fill @@ -115,10 +115,10 @@ auto VDP::writeDataPort(uint16 data) -> void { // -auto VDP::readControlPort() -> uint16 { +auto VDP::readControlPort() -> n16 { io.commandPending = false; - uint16 result; + n16 result; result.bit( 0) = Region::PAL(); result.bit( 1) = io.command.bit(5); //DMA active result.bit( 2) = state.hcounter >= 1280; //horizontal blank @@ -138,7 +138,7 @@ auto VDP::readControlPort() -> uint16 { return result; } -auto VDP::writeControlPort(uint16 data) -> void { +auto VDP::writeControlPort(n16 data) -> void { //command write (lo) if(io.commandPending) { io.commandPending = false; diff --git a/ares/md/vdp-performance/memory.cpp b/ares/md/vdp-performance/memory.cpp index c1845b4449..8e3bf24df0 100644 --- a/ares/md/vdp-performance/memory.cpp +++ b/ares/md/vdp-performance/memory.cpp @@ -1,22 +1,22 @@ -auto VDP::VRAM::read(uint16 address) const -> uint16 { +auto VDP::VRAM::read(n16 address) const -> n16 { if(mode == 0) { - return memory[(uint15)address]; + return memory[(n15)address]; } else { - uint15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; - uint8 data = memory[offset].byte(!address.bit(0)); + n15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; + n8 data = memory[offset].byte(!address.bit(0)); return data << 8 | data << 0; } } -auto VDP::VRAM::write(uint16 address, uint16 data) -> void { +auto VDP::VRAM::write(n16 address, n16 data) -> void { if(mode == 0) { - memory[(uint15)address] = data; + memory[(n15)address] = data; } else { - uint15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; + n15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; memory[offset].byte(!address.bit(0)) = data.byte(0); } - uint15 offset = address; + n15 offset = address; pixels[offset << 2 | 0] = data >> 9 & 0x78; pixels[offset << 2 | 1] = data >> 5 & 0x78; pixels[offset << 2 | 2] = data >> 1 & 0x78; @@ -27,35 +27,35 @@ auto VDP::VRAM::write(uint16 address, uint16 data) -> void { vdp.sprite.write(address - vdp.sprite.io.nametableAddress, data); } -auto VDP::VRAM::readByte(uint17 address) const -> uint8 { +auto VDP::VRAM::readByte(n17 address) const -> n8 { return read(address >> 1).byte(!address.bit(0)); } -auto VDP::VRAM::writeByte(uint17 address, uint8 data) -> void { +auto VDP::VRAM::writeByte(n17 address, n8 data) -> void { auto word = read(address >> 1); word.byte(!address.bit(0)) = data; write(address >> 1, word); } -auto VDP::VSRAM::read(uint6 address) const -> uint10 { +auto VDP::VSRAM::read(n6 address) const -> n10 { if(address >= 40) return 0x0000; return memory[address]; } -auto VDP::VSRAM::write(uint6 address, uint10 data) -> void { +auto VDP::VSRAM::write(n6 address, n10 data) -> void { if(address >= 40) return; memory[address] = data; } -auto VDP::CRAM::read(uint6 address) const -> uint9 { +auto VDP::CRAM::read(n6 address) const -> n9 { return memory[address]; } -auto VDP::CRAM::write(uint6 address, uint9 data) -> void { +auto VDP::CRAM::write(n6 address, n9 data) -> void { memory[address] = data; //ppcccc -> cccc-pp - uint7 offset = (address >> 4 | address << 3) & 0x7b; + n7 offset = (address >> 4 | address << 3) & 0x7b; palette[0 << 7 | 0 << 2 | offset] = palette[0 << 7 | 1 << 2 | offset] = 0 << 9 | data; palette[1 << 7 | 0 << 2 | offset] = palette[1 << 7 | 1 << 2 | offset] = 1 << 9 | data; palette[2 << 7 | 0 << 2 | offset] = palette[2 << 7 | 1 << 2 | offset] = 2 << 9 | data; diff --git a/ares/md/vdp-performance/object.cpp b/ares/md/vdp-performance/object.cpp index 74b57fb270..6a82c64d6f 100644 --- a/ares/md/vdp-performance/object.cpp +++ b/ares/md/vdp-performance/object.cpp @@ -1,7 +1,7 @@ -inline auto VDP::Object::width() const -> uint { +inline auto VDP::Object::width() const -> u32 { return 1 + tileWidth << 3; } -inline auto VDP::Object::height() const -> uint { +inline auto VDP::Object::height() const -> u32 { return 1 + tileHeight << 3 + (vdp.io.interlaceMode == 3); } diff --git a/ares/md/vdp-performance/sprite.cpp b/ares/md/vdp-performance/sprite.cpp index 9a9f23a4f6..d1a6eb2970 100644 --- a/ares/md/vdp-performance/sprite.cpp +++ b/ares/md/vdp-performance/sprite.cpp @@ -1,12 +1,12 @@ auto VDP::Sprite::render() -> void { bool interlace = vdp.io.interlaceMode == 3; - uint y = vdp.state.vcounter + 128; + u32 y = vdp.state.vcounter + 128; if(interlace) y = y << 1 | vdp.state.field; - uint link = 0; - uint tiles = 0; - uint count = 0; - uint objectSize = 0; + u32 link = 0; + u32 tiles = 0; + u32 count = 0; + u32 objectSize = 0; do { auto& object = oam[link]; @@ -24,23 +24,23 @@ auto VDP::Sprite::render() -> void { if(tiles >= tileLimit()) break; } while(++count < linkLimit()); - memory::fill(pixels, vdp.screenWidth()); - uint shiftY = interlace ? 4 : 3; - uint maskY = interlace ? 15 : 7; - uint tileShift = interlace ? 7 : 6; + memory::fill(pixels, vdp.screenWidth()); + u32 shiftY = interlace ? 4 : 3; + u32 maskY = interlace ? 15 : 7; + u32 tileShift = interlace ? 7 : 6; - for(int index = objectSize - 1; index >= 0; index--) { + for(s32 index = objectSize - 1; index >= 0; index--) { auto& object = objects[index]; - uint objectY = y - object.y; + u32 objectY = y - object.y; if(object.verticalFlip) objectY = (object.height() - 1) - objectY; - uint tileIncrement = (object.height() >> interlace) >> 3 << tileShift; - uint tileAddress = object.address + (objectY >> shiftY) << tileShift; + u32 tileIncrement = (object.height() >> interlace) >> 3 << tileShift; + u32 tileAddress = object.address + (objectY >> shiftY) << tileShift; tileAddress += (objectY & maskY) << 3; auto tileData = &vdp.vram.pixels[tileAddress & 0x1fff8]; - uint w = !object.horizontalFlip ? object.x - 128 : (object.x + object.width() - 1) - 128; - int incrementX = object.horizontalFlip ? -1 : +1; - for(uint objectX = 0; objectX < object.width();) { - if(uint color = tileData[objectX & 7]) { + u32 w = !object.horizontalFlip ? object.x - 128 : (object.x + object.width() - 1) - 128; + s32 incrementX = object.horizontalFlip ? -1 : +1; + for(u32 objectX = 0; objectX < object.width();) { + if(u32 color = tileData[objectX & 7]) { pixels[w & 511] = object.palette << 0 | object.priority << 2 | color; } w += incrementX; @@ -52,7 +52,7 @@ auto VDP::Sprite::render() -> void { } } -auto VDP::Sprite::write(uint9 address, uint16 data) -> void { +auto VDP::Sprite::write(n9 address, n16 data) -> void { if(address > 320) return; auto& object = oam[address >> 2]; diff --git a/ares/md/vdp-performance/vdp.cpp b/ares/md/vdp-performance/vdp.cpp index b166442831..64ffb58e2c 100644 --- a/ares/md/vdp-performance/vdp.cpp +++ b/ares/md/vdp-performance/vdp.cpp @@ -99,7 +99,7 @@ auto VDP::main() -> void { } } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { state.hcounter += clocks; if(!dma.io.enable || dma.io.wait) { @@ -128,7 +128,7 @@ auto VDP::render() -> void { planeB.renderScreen(0, screenWidth()); sprite.render(); - uint32_t* output = nullptr; + u32* output = nullptr; if(overscan->value() == 0 && io.overscan == 0) { if(state.vcounter >= 224) return; output = screen->pixels().data() + (state.vcounter - 0) * 2 * 320; @@ -150,24 +150,24 @@ auto VDP::render() -> void { auto A = &planeA.pixels[0]; auto B = &planeB.pixels[0]; auto S = &sprite.pixels[0]; - uint7 c[4] = {0, 0, 0, io.backgroundColor}; + n7 c[4] = {0, 0, 0, io.backgroundColor}; if(!io.shadowHighlightEnable) { auto p = &cram.palette[1 << 7]; - for(uint x : range(screenWidth())) { + for(u32 x : range(screenWidth())) { c[0] = *A++; c[1] = *B++; c[2] = *S++; - uint l = lookupFG[c[0] >> 2 << 10 | c[1] >> 2 << 5 | c[2] >> 2]; + u32 l = lookupFG[c[0] >> 2 << 10 | c[1] >> 2 << 5 | c[2] >> 2]; *output++ = p[c[l]]; } } else { auto p = &cram.palette[0 << 7]; - for(uint x : range(screenWidth())) { + for(u32 x : range(screenWidth())) { c[0] = *A++; c[1] = *B++; c[2] = *S++; - uint l = lookupFG[c[0] >> 2 << 10 | c[1] >> 2 << 5 | c[2] >> 2]; - uint mode = (c[0] | c[1]) >> 2 & 1; //0 = shadow, 1 = normal, 2 = highlight + u32 l = lookupFG[c[0] >> 2 << 10 | c[1] >> 2 << 5 | c[2] >> 2]; + u32 mode = (c[0] | c[1]) >> 2 & 1; //0 = shadow, 1 = normal, 2 = highlight if(l == 2) { if(c[2] >= 0x70) { if(c[2] <= 0x72) mode = 1; @@ -215,23 +215,23 @@ auto VDP::power(bool reset) -> void { if(!initialized) { initialized = true; - for(uint a = 0; a < 32; a++) { - for(uint b = 0; b < 32; b++) { - uint ap = a & 1, ac = a >> 1; - uint bp = b & 1, bc = b >> 1; - uint bg = (ap && ac) || ac && !(bp && bc) ? 0 : bc ? 1 : 3; + for(u32 a = 0; a < 32; a++) { + for(u32 b = 0; b < 32; b++) { + u32 ap = a & 1, ac = a >> 1; + u32 bp = b & 1, bc = b >> 1; + u32 bg = (ap && ac) || ac && !(bp && bc) ? 0 : bc ? 1 : 3; lookupBG[a << 5 | b] = bg; } } - for(uint a = 0; a < 32; a++) { - for(uint b = 0; b < 32; b++) { - for(uint s = 0; s < 32; s++) { - uint ap = a & 1, ac = a >> 1; - uint bp = b & 1, bc = b >> 1; - uint sp = s & 1, sc = s >> 1; - uint bg = (ap && ac) || ac && !(bp && bc) ? 0 : bc ? 1 : 3; - uint fg = (sp && sc) || sc && !(bp && bc) && !(ap && ac) ? 2 : bg; + for(u32 a = 0; a < 32; a++) { + for(u32 b = 0; b < 32; b++) { + for(u32 s = 0; s < 32; s++) { + u32 ap = a & 1, ac = a >> 1; + u32 bp = b & 1, bc = b >> 1; + u32 sp = s & 1, sc = s >> 1; + u32 bg = (ap && ac) || ac && !(bp && bc) ? 0 : bc ? 1 : 3; + u32 fg = (sp && sc) || sc && !(bp && bc) && !(ap && ac) ? 2 : bg; lookupFG[a << 10 | b << 5 | s] = fg; } } diff --git a/ares/md/vdp-performance/vdp.hpp b/ares/md/vdp-performance/vdp.hpp index 54b8e5fa8d..e71f784bd9 100644 --- a/ares/md/vdp-performance/vdp.hpp +++ b/ares/md/vdp-performance/vdp.hpp @@ -20,70 +20,70 @@ struct VDP : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto render() -> void; auto power(bool reset) -> void; //io.cpp - auto read(uint24 address, uint16 data) -> uint16; - auto write(uint24 address, uint16 data) -> void; + auto read(n24 address, n16 data) -> n16; + auto write(n24 address, n16 data) -> void; - auto readDataPort() -> uint16; - auto writeDataPort(uint16 data) -> void; + auto readDataPort() -> n16; + auto writeDataPort(n16 data) -> void; - auto readControlPort() -> uint16; - auto writeControlPort(uint16 data) -> void; + auto readControlPort() -> n16; + auto writeControlPort(n16 data) -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; private: - auto pixelWidth() const -> uint { return latch.displayWidth ? 4 : 5; } - auto screenWidth() const -> uint { return latch.displayWidth ? 320 : 256; } - auto screenHeight() const -> uint { return latch.overscan ? 240 : 224; } - auto frameHeight() const -> uint { return Region::PAL() ? 312 : 262; } + auto pixelWidth() const -> u32 { return latch.displayWidth ? 4 : 5; } + auto screenWidth() const -> u32 { return latch.displayWidth ? 320 : 256; } + auto screenHeight() const -> u32 { return latch.overscan ? 240 : 224; } + auto frameHeight() const -> u32 { return Region::PAL() ? 312 : 262; } struct VRAM { //memory.cpp - auto read(uint16 address) const -> uint16; - auto write(uint16 address, uint16 data) -> void; + auto read(n16 address) const -> n16; + auto write(n16 address, n16 data) -> void; - auto readByte(uint17 address) const -> uint8; - auto writeByte(uint17 address, uint8 data) -> void; + auto readByte(n17 address) const -> n8; + auto writeByte(n17 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8 pixels[131072]; - uint16 memory[65536]; - uint32 size = 32768; - uint1 mode; //0 = 64KB, 1 = 128KB + n8 pixels[131072]; + n16 memory[65536]; + n32 size = 32768; + n1 mode; //0 = 64KB, 1 = 128KB } vram; struct VSRAM { //memory.cpp - auto read(uint6 address) const -> uint10; - auto write(uint6 address, uint10 data) -> void; + auto read(n6 address) const -> n10; + auto write(n6 address, n10 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint10 memory[40]; + n10 memory[40]; } vsram; struct CRAM { //memory.cpp - auto read(uint6 address) const -> uint9; - auto write(uint6 address, uint9 data) -> void; + auto read(n6 address) const -> n9; + auto write(n6 address, n9 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint9 memory[64]; - uint32 palette[3 * 128]; + n9 memory[64]; + n32 palette[3 * 128]; } cram; struct DMA { @@ -98,48 +98,48 @@ struct VDP : Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint1 active; + n1 active; struct IO { - uint2 mode; - uint22 source; - uint16 length; - uint8 fill; - uint1 enable; - uint1 wait; + n2 mode; + n22 source; + n16 length; + n8 fill; + n1 enable; + n1 wait; } io; } dma; struct Background { - enum class ID : uint { PlaneA, Window, PlaneB } id; + enum class ID : u32 { PlaneA, Window, PlaneB } id; //background.cpp - auto renderScreen(uint from, uint to) -> void; - auto renderWindow(uint from, uint to) -> void; + auto renderScreen(u32 from, u32 to) -> void; + auto renderWindow(u32 from, u32 to) -> void; //serialization.cpp auto serialize(serializer&) -> void; struct IO { - uint16 generatorAddress; - uint16 nametableAddress; + n16 generatorAddress; + n16 nametableAddress; //PlaneA, PlaneB - uint2 nametableWidth; - uint2 nametableHeight; - uint15 horizontalScrollAddress; - uint2 horizontalScrollMode; - uint1 verticalScrollMode; + n2 nametableWidth; + n2 nametableHeight; + n15 horizontalScrollAddress; + n2 horizontalScrollMode; + n1 verticalScrollMode; //Window - uint10 horizontalOffset; - uint1 horizontalDirection; - uint10 verticalOffset; - uint1 verticalDirection; + n10 horizontalOffset; + n1 horizontalDirection; + n10 verticalOffset; + n1 verticalDirection; } io; //unserialized: - uint7 pixels[320]; + n7 pixels[320]; }; Background planeA{Background::ID::PlaneA}; Background window{Background::ID::Window}; @@ -147,113 +147,113 @@ struct VDP : Thread { struct Object { //object.cpp - auto width() const -> uint; - auto height() const -> uint; + auto width() const -> u32; + auto height() const -> u32; //serialization.cpp auto serialize(serializer&) -> void; - uint9 x; - uint10 y; - uint2 tileWidth; - uint2 tileHeight; - uint1 horizontalFlip; - uint1 verticalFlip; - uint2 palette; - uint1 priority; - uint11 address; - uint7 link; + n9 x; + n10 y; + n2 tileWidth; + n2 tileHeight; + n1 horizontalFlip; + n1 verticalFlip; + n2 palette; + n1 priority; + n11 address; + n7 link; }; struct Sprite { VDP& vdp; - auto objectLimit() const -> uint { return vdp.io.displayWidth ? 20 : 16; } - auto tileLimit() const -> uint { return vdp.io.displayWidth ? 40 : 32; } - auto linkLimit() const -> uint { return vdp.io.displayWidth ? 80 : 64; } + auto objectLimit() const -> u32 { return vdp.io.displayWidth ? 20 : 16; } + auto tileLimit() const -> u32 { return vdp.io.displayWidth ? 40 : 32; } + auto linkLimit() const -> u32 { return vdp.io.displayWidth ? 80 : 64; } //sprite.cpp auto render() -> void; - auto write(uint9 address, uint16 data) -> void; + auto write(n9 address, n16 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; struct IO { - uint16 generatorAddress; - uint16 nametableAddress; + n16 generatorAddress; + n16 nametableAddress; } io; Object oam[80]; Object objects[20]; //unserialized: - uint7 pixels[512]; + n7 pixels[512]; } sprite{*this}; struct State { - uint16 hdot; - uint16 hcounter; - uint16 vcounter; - uint1 field; + n16 hdot; + n16 hcounter; + n16 vcounter; + n1 field; } state; struct IO { //status - uint1 vblankIRQ; //true after VIRQ triggers; cleared at start of next frame + n1 vblankIRQ; //true after VIRQ triggers; cleared at start of next frame //command - uint6 command; - uint17 address; - uint1 commandPending; + n6 command; + n17 address; + n1 commandPending; //$00 mode register 1 - uint1 displayOverlayEnable; - uint1 counterLatch; - uint1 horizontalBlankInterruptEnable; - uint1 leftColumnBlank; + n1 displayOverlayEnable; + n1 counterLatch; + n1 horizontalBlankInterruptEnable; + n1 leftColumnBlank; //$01 mode register 2 - uint1 videoMode; //0 = Master System; 1 = Mega Drive - uint1 overscan; //0 = 224 lines; 1 = 240 lines - uint1 verticalBlankInterruptEnable; - uint1 displayEnable; + n1 videoMode; //0 = Master System; 1 = Mega Drive + n1 overscan; //0 = 224 lines; 1 = 240 lines + n1 verticalBlankInterruptEnable; + n1 displayEnable; //$07 background color - uint7 backgroundColor; + n7 backgroundColor; //$0a horizontal interrupt counter - uint8 horizontalInterruptCounter; + n8 horizontalInterruptCounter; //$0b mode register 3 - uint1 externalInterruptEnable; + n1 externalInterruptEnable; //$0c mode register 4 - uint2 displayWidth; - uint2 interlaceMode; - uint1 shadowHighlightEnable; - uint1 externalColorEnable; - uint1 horizontalSync; - uint1 verticalSync; + n2 displayWidth; + n2 interlaceMode; + n1 shadowHighlightEnable; + n1 externalColorEnable; + n1 horizontalSync; + n1 verticalSync; //$0f data port auto-increment value - uint8 dataIncrement; + n8 dataIncrement; } io; struct Latch { //per-frame - uint1 field; - uint1 interlace; - uint1 overscan; - uint8 horizontalInterruptCounter; + n1 field; + n1 interlace; + n1 overscan; + n8 horizontalInterruptCounter; //per-scanline - uint2 displayWidth; + n2 displayWidth; } latch; //unserialized: - uint8 lookupBG[1 << 10]; - uint8 lookupFG[1 << 15]; + n8 lookupBG[1 << 10]; + n8 lookupFG[1 << 15]; friend class CPU; friend class APU; diff --git a/ares/md/vdp/background.cpp b/ares/md/vdp/background.cpp index af4ee35cb7..ce257b1662 100644 --- a/ares/md/vdp/background.cpp +++ b/ares/md/vdp/background.cpp @@ -1,22 +1,22 @@ -auto VDP::Background::isWindowed(uint x, uint y) -> bool { +auto VDP::Background::isWindowed(u32 x, u32 y) -> bool { if((x < io.horizontalOffset) ^ io.horizontalDirection) return true; if((y < io.verticalOffset ) ^ io.verticalDirection ) return true; return false; } -auto VDP::Background::updateHorizontalScroll(uint y) -> void { +auto VDP::Background::updateHorizontalScroll(u32 y) -> void { if(id == ID::Window) return; - uint15 address = io.horizontalScrollAddress; + n15 address = io.horizontalScrollAddress; - static const uint mask[] = {0u, 7u, ~7u, ~0u}; + static const u32 mask[] = {0u, 7u, ~7u, ~0u}; address += (y & mask[io.horizontalScrollMode]) << 1; address += id == ID::PlaneB; state.horizontalScroll = vdp.vram.read(address).bit(0,9); } -auto VDP::Background::updateVerticalScroll(uint x) -> void { +auto VDP::Background::updateVerticalScroll(u32 x) -> void { if(id == ID::Window) return; auto address = (x >> 4 & 0 - io.verticalScrollMode) << 1; @@ -25,26 +25,26 @@ auto VDP::Background::updateVerticalScroll(uint x) -> void { state.verticalScroll = vdp.vsram.read(address); } -auto VDP::Background::nametableAddress() -> uint15 { +auto VDP::Background::nametableAddress() -> n15 { if(id == ID::Window && vdp.screenWidth() == 320) return io.nametableAddress & ~0x0400; return io.nametableAddress; } -auto VDP::Background::nametableWidth() -> uint { +auto VDP::Background::nametableWidth() -> u32 { if(id == ID::Window) return vdp.screenWidth() == 320 ? 64 : 32; return 32 * (1 + io.nametableWidth); } -auto VDP::Background::nametableHeight() -> uint { +auto VDP::Background::nametableHeight() -> u32 { if(id == ID::Window) return 32; return 32 * (1 + io.nametableHeight); } -auto VDP::Background::scanline(uint y) -> void { +auto VDP::Background::scanline(u32 y) -> void { updateHorizontalScroll(y); } -auto VDP::Background::run(uint x, uint y) -> void { +auto VDP::Background::run(u32 x, u32 y) -> void { updateVerticalScroll(x); bool interlace = vdp.io.interlaceMode == 3; @@ -53,23 +53,23 @@ auto VDP::Background::run(uint x, uint y) -> void { x -= state.horizontalScroll; y += state.verticalScroll; - uint tileX = x >> 3 & nametableWidth() - 1; - uint tileY = y >> 3 + interlace & nametableHeight() - 1; + u32 tileX = x >> 3 & nametableWidth() - 1; + u32 tileY = y >> 3 + interlace & nametableHeight() - 1; auto address = nametableAddress(); address += (tileY * nametableWidth() + tileX) & 0x0fff; - uint pixelX = x & 7; - uint pixelY = y & 7 + interlace * 8; + u32 pixelX = x & 7; + u32 pixelY = y & 7 + interlace * 8; - uint16 tileAttributes = vdp.vram.read(address); - uint15 tileAddress = tileAttributes.bit(0,10) << 4 + interlace; + n16 tileAttributes = vdp.vram.read(address); + n15 tileAddress = tileAttributes.bit(0,10) << 4 + interlace; if(tileAttributes.bit(11)) pixelX ^= 7; if(tileAttributes.bit(12)) pixelY ^= 7 + interlace * 8; tileAddress += pixelY << 1 | pixelX >> 2; - uint16 tileData = vdp.vram.read(io.generatorAddress | tileAddress); - uint4 color = tileData >> (((pixelX & 3) ^ 3) << 2); + n16 tileData = vdp.vram.read(io.generatorAddress | tileAddress); + n4 color = tileData >> (((pixelX & 3) ^ 3) << 2); output.color = color ? tileAttributes.bit(13,14) << 4 | color : 0; output.priority = tileAttributes.bit(15); } diff --git a/ares/md/vdp/color.cpp b/ares/md/vdp/color.cpp index c586fe70aa..8930d65a2f 100644 --- a/ares/md/vdp/color.cpp +++ b/ares/md/vdp/color.cpp @@ -1,18 +1,18 @@ -auto VDP::color(uint32 color) -> uint64 { - uint R = color.bit(0, 2); - uint G = color.bit(3, 5); - uint B = color.bit(6, 8); - uint M = color.bit(9,10); +auto VDP::color(n32 color) -> n64 { + n32 R = color.bit(0, 2); + n32 G = color.bit(3, 5); + n32 B = color.bit(6, 8); + n32 M = color.bit(9,10); - uint lookup[3][8] = { + u32 lookup[3][8] = { { 0, 29, 52, 70, 87, 101, 116, 130}, //shadow { 0, 52, 87, 116, 144, 172, 206, 255}, //normal {130, 144, 158, 172, 187, 206, 228, 255}, //highlight }; - uint64 r = image::normalize(lookup[M][R], 8, 16); - uint64 g = image::normalize(lookup[M][G], 8, 16); - uint64 b = image::normalize(lookup[M][B], 8, 16); + n64 r = image::normalize(lookup[M][R], 8, 16); + n64 g = image::normalize(lookup[M][G], 8, 16); + n64 b = image::normalize(lookup[M][B], 8, 16); return r << 32 | g << 16 | b << 0; } diff --git a/ares/md/vdp/debugger.cpp b/ares/md/vdp/debugger.cpp index 824ea71166..0e5868e515 100644 --- a/ares/md/vdp/debugger.cpp +++ b/ares/md/vdp/debugger.cpp @@ -2,10 +2,10 @@ auto VDP::Debugger::load(Node::Object parent) -> void { memory.vram = parent->append("VDP VRAM"); memory.vram->setSize(32_KiB << 1); memory.vram->setRead([&](u32 address) -> u8 { - return self.vram.memory[uint15(address >> 1)].byte(!(address & 1)); + return self.vram.memory[n15(address >> 1)].byte(!(address & 1)); }); memory.vram->setWrite([&](u32 address, u8 data) -> void { - self.vram.memory[uint15(address >> 1)].byte(!(address & 1)) = data; + self.vram.memory[n15(address >> 1)].byte(!(address & 1)) = data; }); memory.vsram = parent->append("VDP VSRAM"); @@ -22,10 +22,10 @@ auto VDP::Debugger::load(Node::Object parent) -> void { memory.cram = parent->append("VDP CRAM"); memory.cram->setSize(64 << 1); memory.cram->setRead([&](u32 address) -> u8 { - return self.cram.memory[uint6(address >> 1)].byte(!(address & 1)); + return self.cram.memory[n6(address >> 1)].byte(!(address & 1)); }); memory.cram->setWrite([&](u32 address, u8 data) -> void { - self.cram.memory[uint6(address >> 1)].byte(!(address & 1)) = data; + self.cram.memory[n6(address >> 1)].byte(!(address & 1)) = data; }); } diff --git a/ares/md/vdp/io.cpp b/ares/md/vdp/io.cpp index 6b1fffbe05..e8ad93cc7c 100644 --- a/ares/md/vdp/io.cpp +++ b/ares/md/vdp/io.cpp @@ -1,4 +1,4 @@ -auto VDP::read(uint24 address, uint16) -> uint16 { +auto VDP::read(n24 address, n16) -> n16 { switch(address & 0xc0001e) { //data port @@ -26,7 +26,7 @@ auto VDP::read(uint24 address, uint16) -> uint16 { return 0x0000; } -auto VDP::write(uint24 address, uint16 data) -> void { +auto VDP::write(n24 address, n16 data) -> void { switch(address & 0xc0001e) { //data port @@ -44,7 +44,7 @@ auto VDP::write(uint24 address, uint16 data) -> void { // -auto VDP::readDataPort() -> uint16 { +auto VDP::readDataPort() -> n16 { io.commandPending = false; //VRAM read @@ -74,7 +74,7 @@ auto VDP::readDataPort() -> uint16 { return 0x0000; } -auto VDP::writeDataPort(uint16 data) -> void { +auto VDP::writeDataPort(n16 data) -> void { io.commandPending = false; //DMA VRAM fill @@ -115,10 +115,10 @@ auto VDP::writeDataPort(uint16 data) -> void { // -auto VDP::readControlPort() -> uint16 { +auto VDP::readControlPort() -> n16 { io.commandPending = false; - uint16 result; + n16 result; result.bit( 0) = Region::PAL(); result.bit( 1) = io.command.bit(5); //DMA active result.bit( 2) = state.hcounter >= 1280; //horizontal blank @@ -138,7 +138,7 @@ auto VDP::readControlPort() -> uint16 { return result; } -auto VDP::writeControlPort(uint16 data) -> void { +auto VDP::writeControlPort(n16 data) -> void { //command write (lo) if(io.commandPending) { io.commandPending = false; diff --git a/ares/md/vdp/memory.cpp b/ares/md/vdp/memory.cpp index 750e4d4ec7..401fd38303 100644 --- a/ares/md/vdp/memory.cpp +++ b/ares/md/vdp/memory.cpp @@ -1,18 +1,18 @@ -auto VDP::VRAM::read(uint16 address) const -> uint16 { +auto VDP::VRAM::read(n16 address) const -> n16 { if(mode == 0) { - return memory[(uint15)address]; + return memory[(n15)address]; } else { - uint15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; - uint8 data = memory[offset].byte(!address.bit(0)); + n15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; + n8 data = memory[offset].byte(!address.bit(0)); return data << 8 | data << 0; } } -auto VDP::VRAM::write(uint16 address, uint16 data) -> void { +auto VDP::VRAM::write(n16 address, n16 data) -> void { if(mode == 0) { - memory[(uint15)address] = data; + memory[(n15)address] = data; } else { - uint15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; + n15 offset = address >> 1 & 0x7e00 | address & 0x01fe | address >> 9 & 1; memory[offset].byte(!address.bit(0)) = data.byte(0); } if(address < vdp.sprite.io.nametableAddress) return; @@ -20,30 +20,30 @@ auto VDP::VRAM::write(uint16 address, uint16 data) -> void { vdp.sprite.write(address - vdp.sprite.io.nametableAddress, data); } -auto VDP::VRAM::readByte(uint17 address) const -> uint8 { +auto VDP::VRAM::readByte(n17 address) const -> n8 { return read(address >> 1).byte(!address.bit(0)); } -auto VDP::VRAM::writeByte(uint17 address, uint8 data) -> void { +auto VDP::VRAM::writeByte(n17 address, n8 data) -> void { auto word = read(address >> 1); word.byte(!address.bit(0)) = data; write(address >> 1, word); } -auto VDP::VSRAM::read(uint6 address) const -> uint10 { +auto VDP::VSRAM::read(n6 address) const -> n10 { if(address >= 40) return 0x0000; return memory[address]; } -auto VDP::VSRAM::write(uint6 address, uint10 data) -> void { +auto VDP::VSRAM::write(n6 address, n10 data) -> void { if(address >= 40) return; memory[address] = data; } -auto VDP::CRAM::read(uint6 address) const -> uint9 { +auto VDP::CRAM::read(n6 address) const -> n9 { return memory[address]; } -auto VDP::CRAM::write(uint6 address, uint9 data) -> void { +auto VDP::CRAM::write(n6 address, n9 data) -> void { memory[address] = data; } diff --git a/ares/md/vdp/render.cpp b/ares/md/vdp/render.cpp index b09767ddc5..22b5b22f58 100644 --- a/ares/md/vdp/render.cpp +++ b/ares/md/vdp/render.cpp @@ -55,7 +55,7 @@ auto VDP::run() -> void { auto color = cram.read(fg.color); outputPixel(1 << 9 | color); } else { - uint mode = a.priority || b.priority; //0 = shadow, 1 = normal, 2 = highlight + u32 mode = a.priority || b.priority; //0 = shadow, 1 = normal, 2 = highlight if(&fg == &s) switch(s.color) { case 0x0e: @@ -71,8 +71,8 @@ auto VDP::run() -> void { } } -auto VDP::outputPixel(uint32 color) -> void { +auto VDP::outputPixel(n32 color) -> void { if(!state.output) return; - for(uint n : range(pixelWidth())) state.output[n] = color; + for(u32 n : range(pixelWidth())) state.output[n] = color; state.output += pixelWidth(); } diff --git a/ares/md/vdp/serialization.cpp b/ares/md/vdp/serialization.cpp index 41222aee13..9872f9c4c8 100644 --- a/ares/md/vdp/serialization.cpp +++ b/ares/md/vdp/serialization.cpp @@ -96,8 +96,8 @@ auto VDP::Sprite::serialize(serializer& s) -> void { s(output.color); s(output.priority); - for(uint n : range(80)) s(oam[n]); - for(uint n : range(20)) s(objects[n]); + for(u32 n : range(80)) s(oam[n]); + for(u32 n : range(20)) s(objects[n]); } auto VDP::VRAM::serialize(serializer& s) -> void { diff --git a/ares/md/vdp/sprite.cpp b/ares/md/vdp/sprite.cpp index e88c408484..19f046511b 100644 --- a/ares/md/vdp/sprite.cpp +++ b/ares/md/vdp/sprite.cpp @@ -1,12 +1,12 @@ -inline auto VDP::Object::width() const -> uint { +inline auto VDP::Object::width() const -> u32 { return 1 + tileWidth << 3; } -inline auto VDP::Object::height() const -> uint { +inline auto VDP::Object::height() const -> u32 { return 1 + tileHeight << 3 + (vdp.io.interlaceMode == 3); } -auto VDP::Sprite::write(uint9 address, uint16 data) -> void { +auto VDP::Sprite::write(n9 address, n16 data) -> void { if(address > 320) return; auto& object = oam[address >> 2]; @@ -41,15 +41,15 @@ auto VDP::Sprite::write(uint9 address, uint16 data) -> void { } } -auto VDP::Sprite::scanline(uint y) -> void { +auto VDP::Sprite::scanline(u32 y) -> void { bool interlace = vdp.io.interlaceMode == 3; y += 128; if(interlace) y = y << 1 | vdp.state.field; objects.reset(); - uint7 link = 0; - uint tiles = 0; - uint count = 0; + n7 link = 0; + u32 tiles = 0; + u32 count = 0; do { auto& object = oam[link]; @@ -68,7 +68,7 @@ auto VDP::Sprite::scanline(uint y) -> void { } while(++count < linkLimit()); } -auto VDP::Sprite::run(uint x, uint y) -> void { +auto VDP::Sprite::run(u32 x, u32 y) -> void { bool interlace = vdp.io.interlaceMode == 3; x += 128; y += 128; @@ -81,21 +81,21 @@ auto VDP::Sprite::run(uint x, uint y) -> void { if(x < object.x) continue; if(x >= object.x + object.width()) continue; - uint objectX = x - object.x; - uint objectY = y - object.y; + u32 objectX = x - object.x; + u32 objectY = y - object.y; if(object.horizontalFlip) objectX = (object.width() - 1) - objectX; if(object.verticalFlip) objectY = (object.height() - 1) - objectY; - uint tileX = objectX >> 3; - uint tileY = objectY >> 3 + interlace; - uint tileNumber = tileX * (object.height() >> 3 + interlace) + tileY; - uint15 tileAddress = object.address + tileNumber << 4 + interlace; - uint pixelX = objectX & 7; - uint pixelY = objectY & 7 + interlace * 8; + u32 tileX = objectX >> 3; + u32 tileY = objectY >> 3 + interlace; + u32 tileNumber = tileX * (object.height() >> 3 + interlace) + tileY; + n15 tileAddress = object.address + tileNumber << 4 + interlace; + u32 pixelX = objectX & 7; + u32 pixelY = objectY & 7 + interlace * 8; tileAddress += pixelY << 1 | pixelX >> 2; - uint16 tileData = vdp.vram.read(io.generatorAddress | tileAddress); - uint4 color = tileData >> (((pixelX & 3) ^ 3) << 2); + n16 tileData = vdp.vram.read(io.generatorAddress | tileAddress); + n4 color = tileData >> (((pixelX & 3) ^ 3) << 2); if(!color) continue; output.color = object.palette << 4 | color; diff --git a/ares/md/vdp/vdp.cpp b/ares/md/vdp/vdp.cpp index e55bceed76..d785c8abc6 100644 --- a/ares/md/vdp/vdp.cpp +++ b/ares/md/vdp/vdp.cpp @@ -94,7 +94,7 @@ auto VDP::main() -> void { latch.displayWidth = io.displayWidth; } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { state.hcounter += clocks; while(clocks--) { dma.run(); diff --git a/ares/md/vdp/vdp.hpp b/ares/md/vdp/vdp.hpp index e786e8d1a8..8b94e9bec7 100644 --- a/ares/md/vdp/vdp.hpp +++ b/ares/md/vdp/vdp.hpp @@ -27,19 +27,19 @@ struct VDP : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp - auto read(uint24 address, uint16 data) -> uint16; - auto write(uint24 address, uint16 data) -> void; + auto read(n24 address, n16 data) -> n16; + auto write(n24 address, n16 data) -> void; - auto readDataPort() -> uint16; - auto writeDataPort(uint16 data) -> void; + auto readDataPort() -> n16; + auto writeDataPort(n16 data) -> void; - auto readControlPort() -> uint16; - auto writeControlPort(uint16 data) -> void; + auto readControlPort() -> n16; + auto writeControlPort(n16 data) -> void; struct DMA { //dma.cpp @@ -53,46 +53,46 @@ struct VDP : Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint1 active; + n1 active; struct IO { - uint2 mode; - uint22 source; - uint16 length; - uint8 fill; - uint1 enable; - uint1 wait; + n2 mode; + n22 source; + n16 length; + n8 fill; + n1 enable; + n1 wait; } io; } dma; //render.cpp auto scanline() -> void; auto run() -> void; - auto outputPixel(uint32 color) -> void; + auto outputPixel(n32 color) -> void; struct Pixel { auto above() const -> bool { return priority == 1 && color; } auto below() const -> bool { return priority == 0 && color; } - uint6 color; - uint1 priority; + n6 color; + n1 priority; }; struct Background { - enum class ID : uint { PlaneA, Window, PlaneB } id; + enum class ID : u32 { PlaneA, Window, PlaneB } id; //background.cpp - auto isWindowed(uint x, uint y) -> bool; + auto isWindowed(u32 x, u32 y) -> bool; - auto updateHorizontalScroll(uint y) -> void; - auto updateVerticalScroll(uint x) -> void; + auto updateHorizontalScroll(u32 y) -> void; + auto updateVerticalScroll(u32 x) -> void; - auto nametableAddress() -> uint15; - auto nametableWidth() -> uint; - auto nametableHeight() -> uint; + auto nametableAddress() -> n15; + auto nametableWidth() -> u32; + auto nametableHeight() -> u32; - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; auto power() -> void; @@ -100,26 +100,26 @@ struct VDP : Thread { auto serialize(serializer&) -> void; struct IO { - uint16 generatorAddress; - uint16 nametableAddress; + n16 generatorAddress; + n16 nametableAddress; //PlaneA, PlaneB - uint2 nametableWidth; - uint2 nametableHeight; - uint15 horizontalScrollAddress; - uint2 horizontalScrollMode; - uint1 verticalScrollMode; + n2 nametableWidth; + n2 nametableHeight; + n15 horizontalScrollAddress; + n2 horizontalScrollMode; + n1 verticalScrollMode; //Window - uint10 horizontalOffset; - uint1 horizontalDirection; - uint10 verticalOffset; - uint1 verticalDirection; + n10 horizontalOffset; + n1 horizontalDirection; + n10 verticalOffset; + n1 verticalDirection; } io; struct State { - uint10 horizontalScroll; - uint10 verticalScroll; + n10 horizontalScroll; + n10 verticalScroll; } state; Pixel output; @@ -130,36 +130,36 @@ struct VDP : Thread { struct Object { //sprite.cpp - auto width() const -> uint; - auto height() const -> uint; + auto width() const -> u32; + auto height() const -> u32; //serialization.cpp auto serialize(serializer&) -> void; - uint9 x; - uint10 y; - uint2 tileWidth; - uint2 tileHeight; - uint1 horizontalFlip; - uint1 verticalFlip; - uint2 palette; - uint1 priority; - uint11 address; - uint7 link; + n9 x; + n10 y; + n2 tileWidth; + n2 tileHeight; + n1 horizontalFlip; + n1 verticalFlip; + n2 palette; + n1 priority; + n11 address; + n7 link; }; struct Sprite { VDP& vdp; //the per-scanline sprite limits are different between H40 and H32 modes - auto objectLimit() const -> uint { return vdp.io.displayWidth ? 20 : 16; } - auto tileLimit() const -> uint { return vdp.io.displayWidth ? 40 : 32; } - auto linkLimit() const -> uint { return vdp.io.displayWidth ? 80 : 64; } + auto objectLimit() const -> u32 { return vdp.io.displayWidth ? 20 : 16; } + auto tileLimit() const -> u32 { return vdp.io.displayWidth ? 40 : 32; } + auto linkLimit() const -> u32 { return vdp.io.displayWidth ? 80 : 64; } //sprite.cpp - auto write(uint9 addr, uint16 data) -> void; - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; + auto write(n9 address, n16 data) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; auto power() -> void; @@ -167,8 +167,8 @@ struct VDP : Thread { auto serialize(serializer&) -> void; struct IO { - uint16 generatorAddress; - uint16 nametableAddress; + n16 generatorAddress; + n16 nametableAddress; } io; Pixel output; @@ -179,119 +179,119 @@ struct VDP : Thread { Sprite sprite{*this}; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; private: - auto pixelWidth() const -> uint { return latch.displayWidth ? 4 : 5; } - auto screenWidth() const -> uint { return latch.displayWidth ? 320 : 256; } - auto screenHeight() const -> uint { return latch.overscan ? 240 : 224; } - auto frameHeight() const -> uint { return Region::PAL() ? 312 : 262; } + auto pixelWidth() const -> u32 { return latch.displayWidth ? 4 : 5; } + auto screenWidth() const -> u32 { return latch.displayWidth ? 320 : 256; } + auto screenHeight() const -> u32 { return latch.overscan ? 240 : 224; } + auto frameHeight() const -> u32 { return Region::PAL() ? 312 : 262; } //video RAM struct VRAM { //memory.cpp - auto read(uint16 address) const -> uint16; - auto write(uint16 address, uint16 data) -> void; + auto read(n16 address) const -> n16; + auto write(n16 address, n16 data) -> void; - auto readByte(uint17 address) const -> uint8; - auto writeByte(uint17 address, uint8 data) -> void; + auto readByte(n17 address) const -> n8; + auto writeByte(n17 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; //Mega Drive: 65536x4-bit (x2) = 64KB VRAM //Tera Drive: 65536x4-bit (x4) = 128KB VRAM - uint16 memory[65536]; //stored in 16-bit words - uint32 size = 32768; - uint1 mode; //0 = 64KB, 1 = 128KB + n16 memory[65536]; //stored in 16-bit words + n32 size = 32768; + n1 mode; //0 = 64KB, 1 = 128KB } vram; //vertical scroll RAM struct VSRAM { //memory.cpp - auto read(uint6 address) const -> uint10; - auto write(uint6 address, uint10 data) -> void; + auto read(n6 address) const -> n10; + auto write(n6 address, n10 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint10 memory[40]; + n10 memory[40]; } vsram; //color RAM struct CRAM { //memory.cpp - auto read(uint6 address) const -> uint9; - auto write(uint6 address, uint9 data) -> void; + auto read(n6 address) const -> n9; + auto write(n6 address, n9 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint9 memory[64]; + n9 memory[64]; } cram; struct IO { //status - uint1 vblankIRQ; //true after VIRQ triggers; cleared at start of next frame + n1 vblankIRQ; //true after VIRQ triggers; cleared at start of next frame //command - uint6 command; - uint17 address; - uint1 commandPending; + n6 command; + n17 address; + n1 commandPending; //$00 mode register 1 - uint1 displayOverlayEnable; - uint1 counterLatch; - uint1 horizontalBlankInterruptEnable; - uint1 leftColumnBlank; + n1 displayOverlayEnable; + n1 counterLatch; + n1 horizontalBlankInterruptEnable; + n1 leftColumnBlank; //$01 mode register 2 - uint1 videoMode; //0 = Master System; 1 = Mega Drive - uint1 overscan; //0 = 224 lines; 1 = 240 lines - uint1 verticalBlankInterruptEnable; - uint1 displayEnable; + n1 videoMode; //0 = Master System; 1 = Mega Drive + n1 overscan; //0 = 224 lines; 1 = 240 lines + n1 verticalBlankInterruptEnable; + n1 displayEnable; //$07 background color - uint6 backgroundColor; + n6 backgroundColor; //$0a horizontal interrupt counter - uint8 horizontalInterruptCounter; + n8 horizontalInterruptCounter; //$0b mode register 3 - uint1 externalInterruptEnable; + n1 externalInterruptEnable; //$0c mode register 4 - uint2 displayWidth; - uint2 interlaceMode; - uint1 shadowHighlightEnable; - uint1 externalColorEnable; - uint1 horizontalSync; - uint1 verticalSync; + n2 displayWidth; + n2 interlaceMode; + n1 shadowHighlightEnable; + n1 externalColorEnable; + n1 horizontalSync; + n1 verticalSync; //$0f data port auto-increment value - uint8 dataIncrement; + n8 dataIncrement; } io; struct Latch { //per-frame - uint1 field; - uint1 interlace; - uint1 overscan; - uint8 horizontalInterruptCounter; + n1 field; + n1 interlace; + n1 overscan; + n8 horizontalInterruptCounter; //per-scanline - uint2 displayWidth; + n2 displayWidth; } latch; struct State { - uint32_t* output = nullptr; - uint16 hdot; - uint16 hcounter; - uint16 vcounter; - uint1 field; + u32* output = nullptr; + n16 hdot; + n16 hcounter; + n16 vcounter; + n1 field; } state; friend class Interface; diff --git a/ares/md/ym2612/channel.cpp b/ares/md/ym2612/channel.cpp index 1f35ce138c..65edeb1059 100644 --- a/ares/md/ym2612/channel.cpp +++ b/ares/md/ym2612/channel.cpp @@ -27,15 +27,15 @@ auto YM2612::Channel::Operator::trigger(bool state) -> void { } auto YM2612::Channel::Operator::runEnvelope() -> void { - uint sustain = envelope.sustainLevel < 15 ? envelope.sustainLevel << 5 : 0x3f0; + u32 sustain = envelope.sustainLevel < 15 ? envelope.sustainLevel << 5 : 0x3f0; if(ym2612.envelope.clock & (1 << envelope.divider) - 1) return; - uint value = ym2612.envelope.clock >> envelope.divider; - uint step = envelope.steps >> ((~value & 7) << 2) & 0xf; + u32 value = ym2612.envelope.clock >> envelope.divider; + u32 step = envelope.steps >> ((~value & 7) << 2) & 0xf; if(ssg.enable) step <<= 2; //SSG results in a 4x faster envelope if(envelope.state == Attack) { - uint next = envelope.value + (~uint16(envelope.value) * step >> 4) & 0x3ff; + u32 next = envelope.value + (~u16(envelope.value) * step >> 4) & 0x3ff; if(next <= envelope.value) { envelope.value = next; } else { @@ -80,9 +80,9 @@ auto YM2612::Channel::Operator::runPhase() -> void { } auto YM2612::Channel::Operator::updateEnvelope() -> void { - uint key = min(max((uint)pitch.value, 0x300), 0x4ff); - uint ksr = (octave.value << 2) + ((key - 0x300) >> 7); - uint rate = 0; + u32 key = min(max((u32)pitch.value, 0x300), 0x4ff); + u32 ksr = (octave.value << 2) + ((key - 0x300) >> 7); + u32 rate = 0; if(envelope.state == Attack) rate += (envelope.attackRate << 1); if(envelope.state == Decay) rate += (envelope.decayRate << 1); @@ -110,13 +110,13 @@ auto YM2612::Channel::Operator::updatePitch() -> void { } auto YM2612::Channel::Operator::updatePhase() -> void { - uint key = min(max((uint)pitch.value, 0x300), 0x4ff); - uint ksr = (octave.value << 2) + ((key - 0x300) >> 7); - uint tuning = detune & 3 ? detunes[(detune & 3) - 1][ksr & 7] >> (3 - (ksr >> 3)) : 0; + u32 key = min(max((u32)pitch.value, 0x300), 0x4ff); + u32 ksr = (octave.value << 2) + ((key - 0x300) >> 7); + u32 tuning = detune & 3 ? detunes[(detune & 3) - 1][ksr & 7] >> (3 - (ksr >> 3)) : 0; - uint lfo = ym2612.lfo.clock >> 2 & 0x1f; - uint pm = 4 * vibratos[channel.vibrato][lfo & 15] * (-lfo >> 4); - uint msb = 10; + u32 lfo = ym2612.lfo.clock >> 2 & 0x1f; + u32 pm = 4 * vibratos[channel.vibrato][lfo & 15] * (-lfo >> 4); + u32 msb = 10; while(msb > 4 && ~pitch.value & 1 << msb) msb--; phase.delta = pitch.value + (pm >> 10 - msb) << 6 >> 7 - octave.value; @@ -125,11 +125,11 @@ auto YM2612::Channel::Operator::updatePhase() -> void { } auto YM2612::Channel::Operator::updateLevel() -> void { - uint lfo = ym2612.lfo.clock & 0x40 ? ym2612.lfo.clock & 0x3f : ~ym2612.lfo.clock & 0x3f; - uint depth = tremolos[channel.tremolo]; + u32 lfo = ym2612.lfo.clock & 0x40 ? ym2612.lfo.clock & 0x3f : ~ym2612.lfo.clock & 0x3f; + u32 depth = tremolos[channel.tremolo]; bool invert = ssg.attack != ssg.invert && envelope.state != Release; - uint10 value = ssg.enable && invert ? 0x200 - envelope.value : 0 + envelope.value; + n10 value = ssg.enable && invert ? 0x200 - envelope.value : 0 + envelope.value; outputLevel = ((totalLevel << 3) + value + (lfoEnable ? lfo << 1 >> depth : 0)) << 3; } diff --git a/ares/md/ym2612/constants.cpp b/ares/md/ym2612/constants.cpp index 0bcdc200c4..f91722372a 100644 --- a/ares/md/ym2612/constants.cpp +++ b/ares/md/ym2612/constants.cpp @@ -1,4 +1,4 @@ -const uint8_t YM2612::lfoDividers[8] = { +const u8 YM2612::lfoDividers[8] = { 108, 77, 71, @@ -9,7 +9,7 @@ const uint8_t YM2612::lfoDividers[8] = { 5, }; -const uint8_t YM2612::vibratos[8][16] = { +const u8 YM2612::vibratos[8][16] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 0, 0, 0}, @@ -20,14 +20,14 @@ const uint8_t YM2612::vibratos[8][16] = { {0, 0, 8,12,16,16,20,24,24,20,16,16,12, 8, 0, 0}, }; -const uint8_t YM2612::tremolos[4] = { +const u8 YM2612::tremolos[4] = { 7, 3, 1, 0, }; -const uint8_t YM2612::detunes[3][8] = { +const u8 YM2612::detunes[3][8] = { { 5, 6, 6, 7, 8, 8, 9, 10}, {11, 12, 13, 14, 16, 17, 18, 20}, {16, 17, 19, 20, 22, 24, 26, 28}, diff --git a/ares/md/ym2612/io.cpp b/ares/md/ym2612/io.cpp index 0a26f9d685..5a05b8b685 100644 --- a/ares/md/ym2612/io.cpp +++ b/ares/md/ym2612/io.cpp @@ -1,13 +1,13 @@ -auto YM2612::readStatus() -> uint8 { +auto YM2612::readStatus() -> n8 { //d7 = busy (not emulated, requires cycle timing accuracy) return timerA.line << 0 | timerB.line << 1; } -auto YM2612::writeAddress(uint9 data) -> void { +auto YM2612::writeAddress(n9 data) -> void { io.address = data; } -auto YM2612::writeData(uint8 data) -> void { +auto YM2612::writeData(n8 data) -> void { switch(io.address) { //LFO @@ -60,7 +60,7 @@ auto YM2612::writeData(uint8 data) -> void { //key on/off case 0x28: { //0,1,2,4,5,6 => 0,1,2,3,4,5 - uint index = data.bit(0,2); + u32 index = data.bit(0,2); if(index == 3 || index == 7) break; if(index >= 4) index--; @@ -87,8 +87,8 @@ auto YM2612::writeData(uint8 data) -> void { } if(io.address.bit(0,1) == 3) return; - uint3 voice = io.address.bit(8) * 3 + io.address.bit(0,1); - uint2 index = io.address.bit(2,3) >> 1 | io.address.bit(2,3) << 1; //0,1,2,3 => 0,2,1,3 + n3 voice = io.address.bit(8) * 3 + io.address.bit(0,1); + n2 index = io.address.bit(2,3) >> 1 | io.address.bit(2,3) << 1; //0,1,2,3 => 0,2,1,3 auto& channel = channels[voice]; auto& op = channel.operators[index]; @@ -160,7 +160,7 @@ auto YM2612::writeData(uint8 data) -> void { case 0x0a0: { channel[3].pitch.reload = channel[3].pitch.latch | data; channel[3].octave.reload = channel[3].octave.latch; - for(uint index : range(4)) channel[index].updatePitch(); + for(u32 index : range(4)) channel[index].updatePitch(); break; } @@ -205,7 +205,7 @@ auto YM2612::writeData(uint8 data) -> void { channel.tremolo = data.bit(4,5); channel.rightEnable = data.bit(6); channel.leftEnable = data.bit(7); - for(uint index : range(4)) { + for(u32 index : range(4)) { channel[index].updateLevel(); channel[index].updatePhase(); } diff --git a/ares/md/ym2612/serialization.cpp b/ares/md/ym2612/serialization.cpp index 6703a27556..c4b0b3b6ee 100644 --- a/ares/md/ym2612/serialization.cpp +++ b/ares/md/ym2612/serialization.cpp @@ -27,7 +27,7 @@ auto YM2612::serialize(serializer& s) -> void { s(timerB.counter); s(timerB.divider); - for(uint n : range(6)) s(channels[n]); + for(u32 n : range(6)) s(channels[n]); } auto YM2612::Channel::serialize(serializer& s) -> void { @@ -39,7 +39,7 @@ auto YM2612::Channel::serialize(serializer& s) -> void { s(tremolo); s(mode); - for(uint n : range(4)) s(operators[n]); + for(u32 n : range(4)) s(operators[n]); } auto YM2612::Channel::Operator::serialize(serializer& s) -> void { diff --git a/ares/md/ym2612/ym2612.cpp b/ares/md/ym2612/ym2612.cpp index 685416919f..13a980c1a6 100644 --- a/ares/md/ym2612/ym2612.cpp +++ b/ares/md/ym2612/ym2612.cpp @@ -58,28 +58,28 @@ auto YM2612::main() -> void { } auto YM2612::sample() -> void { - int left = 0; - int right = 0; + s32 left = 0; + s32 right = 0; for(auto& channel : channels) { auto& op = channel.operators; - const int modMask = -(1 << 1); - const int sumMask = -(1 << 5); - const int outMask = -(1 << 5); + const s32 modMask = -(1 << 1); + const s32 sumMask = -(1 << 5); + const s32 outMask = -(1 << 5); - auto old = [&](uint n) -> int { return op[n].prior & modMask; }; - auto mod = [&](uint n) -> int { return op[n].output & modMask; }; - auto out = [&](uint n) -> int { return op[n].output & sumMask; }; + auto old = [&](u32 n) -> s32 { return op[n].prior & modMask; }; + auto mod = [&](u32 n) -> s32 { return op[n].output & modMask; }; + auto out = [&](u32 n) -> s32 { return op[n].output & sumMask; }; - auto wave = [&](uint n, uint modulation) -> int { - int x = (modulation >> 1) + (op[n].phase.value >> 10); - int y = sine[x & 0x3ff] + op[n].outputLevel; + auto wave = [&](u32 n, u32 modulation) -> s32 { + s32 x = (modulation >> 1) + (op[n].phase.value >> 10); + s32 y = sine[x & 0x3ff] + op[n].outputLevel; return y < 0x2000 ? pow2[y & 0x1ff] << 2 >> (y >> 9) : 0; }; - int feedback = modMask & op[0].output + op[0].prior >> 9 - channel.feedback; - int accumulator = 0; + s32 feedback = modMask & op[0].output + op[0].prior >> 9 - channel.feedback; + s32 accumulator = 0; for(auto n : range(4)) op[n].prior = op[n].output; @@ -149,8 +149,8 @@ auto YM2612::sample() -> void { accumulator += out(0) + out(1) + out(2) + out(3); } - int voiceData = sclamp<14>(accumulator) & outMask; - if(dac.enable && (&channel == &channels[5])) voiceData = (int)dac.sample - 0x80 << 6; + s32 voiceData = sclamp<14>(accumulator) & outMask; + if(dac.enable && (&channel == &channels[5])) voiceData = (s32)dac.sample - 0x80 << 6; if(channel.leftEnable ) left += voiceData; if(channel.rightEnable) right += voiceData; @@ -159,7 +159,7 @@ auto YM2612::sample() -> void { stream->frame(sclamp<16>(left) / 32768.0, sclamp<16>(right) / 32768.0); } -auto YM2612::step(uint clocks) -> void { +auto YM2612::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu, apu); } @@ -175,19 +175,19 @@ auto YM2612::power(bool reset) -> void { timerB = {}; for(auto& channel : channels) channel.power(); - const uint positive = 0; - const uint negative = 1; + const u32 positive = 0; + const u32 negative = 1; - for(int x = 0; x <= 0xff; x++) { - int y = -256 * log(sin((2 * x + 1) * Math::Pi / 1024)) / log(2) + 0.5; + for(s32 x = 0; x <= 0xff; x++) { + s32 y = -256 * log(sin((2 * x + 1) * Math::Pi / 1024)) / log(2) + 0.5; sine[0x000 + x] = positive + (y << 1); sine[0x1ff - x] = positive + (y << 1); sine[0x200 + x] = negative + (y << 1); sine[0x3ff - x] = negative + (y << 1); } - for(int y = 0; y <= 0xff; y++) { - int z = 1024 * pow(2, (0xff - y) / 256.0) + 0.5; + for(s32 y = 0; y <= 0xff; y++) { + s32 z = 1024 * pow(2, (0xff - y) / 256.0) + 0.5; pow2[positive + (y << 1)] = +z; pow2[negative + (y << 1)] = ~z; //not -z } diff --git a/ares/md/ym2612/ym2612.hpp b/ares/md/ym2612/ym2612.hpp index 3554bbb0af..569218212c 100644 --- a/ares/md/ym2612/ym2612.hpp +++ b/ares/md/ym2612/ym2612.hpp @@ -11,64 +11,64 @@ struct YM2612 : Thread { auto main() -> void; auto sample() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp - auto readStatus() -> uint8; - auto writeAddress(uint9 data) -> void; - auto writeData(uint8 data) -> void; + auto readStatus() -> n8; + auto writeAddress(n9 data) -> void; + auto writeData(n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; private: struct IO { - uint9 address = 0; + n9 address = 0; } io; struct LFO { - uint1 enable = 0; - uint3 rate = 0; - uint32 clock = 0; - uint32 divider = 0; + n1 enable = 0; + n3 rate = 0; + n32 clock = 0; + n32 divider = 0; } lfo; struct DAC { - uint1 enable = 0; - uint8 sample = 0x80; + n1 enable = 0; + n8 sample = 0x80; } dac; struct Envelope { - uint32 clock = 0; - uint32 divider = 0; + n32 clock = 0; + n32 divider = 0; } envelope; struct TimerA { //timer.cpp auto run() -> void; - uint1 enable = 0; - uint1 irq = 0; - uint1 line = 0; - uint10 period = 0; - uint10 counter = 0; + n1 enable = 0; + n1 irq = 0; + n1 line = 0; + n10 period = 0; + n10 counter = 0; } timerA; struct TimerB { //timer.cpp auto run() -> void; - uint1 enable = 0; - uint1 irq = 0; - uint1 line = 0; - uint8 period = 0; - uint8 counter = 0; - uint4 divider = 0; + n1 enable = 0; + n1 irq = 0; + n1 line = 0; + n8 period = 0; + n8 counter = 0; + n4 divider = 0; } timerB; - enum : uint { Attack, Decay, Sustain, Release }; + enum : u32 { Attack, Decay, Sustain, Release }; struct Channel { //channel.cpp @@ -77,15 +77,15 @@ struct YM2612 : Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint1 leftEnable = 1; - uint1 rightEnable = 1; + n1 leftEnable = 1; + n1 rightEnable = 1; - uint3 algorithm = 0; - uint3 feedback = 0; - uint3 vibrato = 0; - uint2 tremolo = 0; + n3 algorithm = 0; + n3 feedback = 0; + n3 vibrato = 0; + n2 tremolo = 0; - uint2 mode = 0; + n2 mode = 0; struct Operator { Channel& channel; @@ -105,73 +105,73 @@ struct YM2612 : Thread { //serialization.cpp auto serialize(serializer&) -> void; - uint1 keyOn = 0; - uint1 lfoEnable = 0; - uint3 detune = 0; - uint4 multiple = 0; - uint7 totalLevel = 0; + n1 keyOn = 0; + n1 lfoEnable = 0; + n3 detune = 0; + n4 multiple = 0; + n7 totalLevel = 0; - uint16 outputLevel = 0x1fff; - int16 output = 0; - int16 prior = 0; + n16 outputLevel = 0x1fff; + i16 output = 0; + i16 prior = 0; struct Pitch { - uint11 value = 0; - uint11 reload = 0; - uint11 latch = 0; + n11 value = 0; + n11 reload = 0; + n11 latch = 0; } pitch; struct Octave { - uint3 value = 0; - uint3 reload = 0; - uint3 latch = 0; + n3 value = 0; + n3 reload = 0; + n3 latch = 0; } octave; struct Phase { - uint20 value = 0; - uint20 delta = 0; + n20 value = 0; + n20 delta = 0; } phase; struct Envelope { - uint state = Release; - int rate = 0; - int divider = 11; - uint32 steps = 0; - uint10 value = 0x3ff; - - uint2 keyScale = 0; - uint5 attackRate = 0; - uint5 decayRate = 0; - uint5 sustainRate = 0; - uint4 sustainLevel = 0; - uint5 releaseRate = 1; + u32 state = Release; + s32 rate = 0; + s32 divider = 11; + n32 steps = 0; + n10 value = 0x3ff; + + n2 keyScale = 0; + n5 attackRate = 0; + n5 decayRate = 0; + n5 sustainRate = 0; + n4 sustainLevel = 0; + n5 releaseRate = 1; } envelope; struct SSG { - uint1 enable = 0; - uint1 attack = 0; - uint1 alternate = 0; - uint1 hold = 0; - uint1 invert = 0; + n1 enable = 0; + n1 attack = 0; + n1 alternate = 0; + n1 hold = 0; + n1 invert = 0; } ssg; } operators[4]{*this, *this, *this, *this}; - auto operator[](uint2 index) -> Operator& { return operators[index]; } + auto operator[](n2 index) -> Operator& { return operators[index]; } } channels[6]; - uint16 sine[0x400]; - int16 pow2[0x200]; + n16 sine[0x400]; + i16 pow2[0x200]; //constants.cpp struct EnvelopeRate { - uint32_t divider; - uint32_t steps[4]; + u32 divider; + u32 steps[4]; }; - static const uint8_t lfoDividers[8]; - static const uint8_t vibratos[8][16]; - static const uint8_t tremolos[4]; - static const uint8_t detunes[3][8]; + static const u8 lfoDividers[8]; + static const u8 vibratos[8][16]; + static const u8 tremolos[4]; + static const u8 detunes[3][8]; static const EnvelopeRate envelopeRates[16]; }; diff --git a/ares/ms/cpu/cpu.hpp b/ares/ms/cpu/cpu.hpp index 960579f070..c6e3d1da6f 100644 --- a/ares/ms/cpu/cpu.hpp +++ b/ares/ms/cpu/cpu.hpp @@ -40,7 +40,7 @@ struct CPU : Z80, Z80::Bus, Thread { auto out(n16 address, n8 data) -> void override; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; private: n8 mdr; diff --git a/ares/ms/ms.hpp b/ares/ms/ms.hpp index a73c2dd124..c6523ff1e9 100644 --- a/ares/ms/ms.hpp +++ b/ares/ms/ms.hpp @@ -9,6 +9,7 @@ namespace ares::MasterSystem { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { diff --git a/ares/ms/system/system.cpp b/ares/ms/system/system.cpp index bf6cbe03e5..5e229ecd9d 100644 --- a/ares/ms/system/system.cpp +++ b/ares/ms/system/system.cpp @@ -2,7 +2,20 @@ namespace ares::MasterSystem { +auto enumerate() -> vector { + return { + "[Sega] Mark III (NTSC-J)", + "[Sega] Master System (NTSC-J)", + "[Sega] Master System (NTSC-U)", + "[Sega] Master System (PAL)", + "[Sega] Master System II (NTSC-U)", + "[Sega] Master System II (PAL)", + "[Sega] Game Gear", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -28,12 +41,36 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "Mark III" ) information.model = Model::MarkIII; - if(name == "Master System I" ) information.model = Model::MasterSystemI; - if(name == "Master System II") information.model = Model::MasterSystemII; - if(name == "Game Gear" ) information.model = Model::GameGear; + if(name.find("Mark III")) { + information.name = "Master System"; + information.model = Model::MarkIII; + } + if(name.find("Master System")) { + information.name = "Master System"; + information.model = Model::MasterSystemI; + } + if(name.find("Master System II")) { + information.name = "Master System"; + information.model = Model::MasterSystemII; + } + if(name.find("Game Gear")) { + information.name = "Game Gear"; + information.model = Model::GameGear; + } + if(name.find("NTSC-J")) { + information.region = Region::NTSCJ; + information.colorburst = Constants::Colorburst::NTSC; + } + if(name.find("NTSC-U")) { + information.region = Region::NTSCU; + information.colorburst = Constants::Colorburst::NTSC; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -43,17 +80,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC-J → NTSC-U → PAL"); - regionNode->setAllowedValues({ - "NTSC-J → NTSC-U → PAL", - "NTSC-U → NTSC-J → PAL", - "PAL → NTSC-J → NTSC-U", - "PAL → NTSC-U → NTSC-J", - "NTSC-J", - "NTSC-U", - "PAL" - }); - scheduler.reset(); controls.load(node); cpu.load(node); @@ -111,26 +137,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC-J") { - information.region = Region::NTSCJ; - information.colorburst = Constants::Colorburst::NTSC; - } - if(region == "NTSC-U") { - information.region = Region::NTSCU; - information.colorburst = Constants::Colorburst::NTSC; - } - if(region == "PAL") { - information.region = Region::PAL; - information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - cartridge.power(); cpu.power(); vdp.power(); @@ -148,13 +154,6 @@ auto System::power(bool reset) -> void { } } scheduler.power(cpu); - - //todo: this is a hack because load() attaches the OPLL before the region is configured. - //this incorrect fix can crash the emulator if the region is changed without restarting! - //the correct fix will require games to set the system region before calling load() - if(opll.node && !MasterSystem::Region::NTSCJ()) { - opll.unload(); - } } } diff --git a/ares/ms/system/system.hpp b/ares/ms/system/system.hpp index 0125fd91ab..fbeea05f15 100644 --- a/ares/ms/system/system.hpp +++ b/ares/ms/system/system.hpp @@ -1,6 +1,5 @@ struct System { Node::System node; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -32,7 +31,7 @@ struct System { enum class Model : u32 { MarkIII, MasterSystemI, MasterSystemII, GameGear }; enum class Region : u32 { NTSCJ, NTSCU, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto region() const -> Region { return information.region; } auto colorburst() const -> double { return information.colorburst; } @@ -52,7 +51,8 @@ struct System { private: struct Information { - Model model = Model::MasterSystemII; + string name = "Master System"; + Model model = Model::MasterSystemI; Region region = Region::NTSCJ; f64 colorburst = Constants::Colorburst::NTSC; } information; diff --git a/ares/msx/cartridge/board/asc16.cpp b/ares/msx/cartridge/board/asc16.cpp index f15f68eb14..1802b28a0d 100644 --- a/ares/msx/cartridge/board/asc16.cpp +++ b/ares/msx/cartridge/board/asc16.cpp @@ -2,7 +2,7 @@ struct ASC16 : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -15,17 +15,17 @@ struct ASC16 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >= 0x4000 && address <= 0x7fff) data = rom.read(bank[0] << 14 | (uint14)address); - if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank[1] << 14 | (uint14)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >= 0x4000 && address <= 0x7fff) data = rom.read(bank[0] << 14 | (n14)address); + if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank[1] << 14 | (n14)address); - if(address >= 0xc000 && address <= 0xffff) data = rom.read(bank[0] << 14 | (uint14)address); - if(address >= 0x0000 && address <= 0x3fff) data = rom.read(bank[1] << 14 | (uint14)address); + if(address >= 0xc000 && address <= 0xffff) data = rom.read(bank[0] << 14 | (n14)address); + if(address >= 0x0000 && address <= 0x3fff) data = rom.read(bank[1] << 14 | (n14)address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x6000 && address <= 0x6fff) bank[0] = data; if(address >= 0x7000 && address <= 0xbfff) bank[1] = data; } @@ -39,5 +39,5 @@ struct ASC16 : Interface { s(bank); } - uint8 bank[2]; + n8 bank[2]; }; diff --git a/ares/msx/cartridge/board/asc8.cpp b/ares/msx/cartridge/board/asc8.cpp index ee977d4234..6cf1857dc7 100644 --- a/ares/msx/cartridge/board/asc8.cpp +++ b/ares/msx/cartridge/board/asc8.cpp @@ -2,7 +2,7 @@ struct ASC8 : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -15,21 +15,21 @@ struct ASC8 : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >= 0x4000 && address <= 0x5fff) data = rom.read(bank[0] << 13 | (uint13)address); - if(address >= 0x6000 && address <= 0x7fff) data = rom.read(bank[1] << 13 | (uint13)address); - if(address >= 0x8000 && address <= 0x9fff) data = rom.read(bank[2] << 13 | (uint13)address); - if(address >= 0xa000 && address <= 0xbfff) data = rom.read(bank[3] << 13 | (uint13)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >= 0x4000 && address <= 0x5fff) data = rom.read(bank[0] << 13 | (n13)address); + if(address >= 0x6000 && address <= 0x7fff) data = rom.read(bank[1] << 13 | (n13)address); + if(address >= 0x8000 && address <= 0x9fff) data = rom.read(bank[2] << 13 | (n13)address); + if(address >= 0xa000 && address <= 0xbfff) data = rom.read(bank[3] << 13 | (n13)address); - if(address >= 0xc000 && address <= 0xdfff) data = rom.read(bank[0] << 13 | (uint13)address); - if(address >= 0xe000 && address <= 0xffff) data = rom.read(bank[1] << 13 | (uint13)address); - if(address >= 0x0000 && address <= 0x1fff) data = rom.read(bank[2] << 13 | (uint13)address); - if(address >= 0x2000 && address <= 0x3fff) data = rom.read(bank[3] << 13 | (uint13)address); + if(address >= 0xc000 && address <= 0xdfff) data = rom.read(bank[0] << 13 | (n13)address); + if(address >= 0xe000 && address <= 0xffff) data = rom.read(bank[1] << 13 | (n13)address); + if(address >= 0x0000 && address <= 0x1fff) data = rom.read(bank[2] << 13 | (n13)address); + if(address >= 0x2000 && address <= 0x3fff) data = rom.read(bank[3] << 13 | (n13)address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x6000 && address <= 0x67ff) bank[0] = data; if(address >= 0x6800 && address <= 0x6fff) bank[1] = data; if(address >= 0x7000 && address <= 0x77ff) bank[2] = data; @@ -47,5 +47,5 @@ struct ASC8 : Interface { s(bank); } - uint8 bank[4]; + n8 bank[4]; }; diff --git a/ares/msx/cartridge/board/board.cpp b/ares/msx/cartridge/board/board.cpp index 4bb6496ca5..3846768e13 100644 --- a/ares/msx/cartridge/board/board.cpp +++ b/ares/msx/cartridge/board/board.cpp @@ -9,7 +9,7 @@ namespace Board { #include "super-lode-runner.cpp" #include "super-pierrot.cpp" -auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); @@ -20,7 +20,7 @@ auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool return false; } -auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); if(node["volatile"]) return true; @@ -32,7 +32,7 @@ auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool return false; } -auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); diff --git a/ares/msx/cartridge/board/board.hpp b/ares/msx/cartridge/board/board.hpp index 878fc04b36..2c7bcf8f1a 100644 --- a/ares/msx/cartridge/board/board.hpp +++ b/ares/msx/cartridge/board/board.hpp @@ -7,14 +7,14 @@ struct Interface { virtual auto save(Markup::Node) -> void {} virtual auto unload() -> void {} virtual auto main() -> void; - virtual auto read(uint16 address, uint8 data) -> uint8 { return data; } - virtual auto write(uint16 address, uint8 data) -> void {} + virtual auto read(n16 address, n8 data) -> n8 { return data; } + virtual auto write(n16 address, n8 data) -> void {} virtual auto power() -> void {} virtual auto serialize(serializer&) -> void {} - auto load(Memory::Readable&, Markup::Node) -> bool; - auto load(Memory::Writable&, Markup::Node) -> bool; - auto save(Memory::Writable&, Markup::Node) -> bool; + auto load(Memory::Readable&, Markup::Node) -> bool; + auto load(Memory::Writable&, Markup::Node) -> bool; + auto save(Memory::Writable&, Markup::Node) -> bool; Cartridge& cartridge; }; diff --git a/ares/msx/cartridge/board/cross-blaim.cpp b/ares/msx/cartridge/board/cross-blaim.cpp index 8096c708c7..cf34aa6514 100644 --- a/ares/msx/cartridge/board/cross-blaim.cpp +++ b/ares/msx/cartridge/board/cross-blaim.cpp @@ -2,7 +2,7 @@ struct CrossBlaim : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -15,32 +15,32 @@ struct CrossBlaim : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { if(mode == 0 || mode == 1) { - if(address >> 14 == 0) data = rom.read((uint14)address + 16_KiB); - if(address >> 14 == 1) data = rom.read((uint14)address); - if(address >> 14 == 2) data = rom.read((uint14)address + 16_KiB); - if(address >> 14 == 3) data = rom.read((uint14)address + 16_KiB); + if(address >> 14 == 0) data = rom.read((n14)address + 16_KiB); + if(address >> 14 == 1) data = rom.read((n14)address); + if(address >> 14 == 2) data = rom.read((n14)address + 16_KiB); + if(address >> 14 == 3) data = rom.read((n14)address + 16_KiB); } if(mode == 2) { if(address >> 14 == 0) data = 0xff; - if(address >> 14 == 1) data = rom.read((uint14)address); - if(address >> 14 == 2) data = rom.read((uint14)address + 32_KiB); + if(address >> 14 == 1) data = rom.read((n14)address); + if(address >> 14 == 2) data = rom.read((n14)address + 32_KiB); if(address >> 14 == 3) data = 0xff; } if(mode == 3) { if(address >> 14 == 0) data = 0xff; - if(address >> 14 == 1) data = rom.read((uint14)address); - if(address >> 14 == 2) data = rom.read((uint14)address + 48_KiB); + if(address >> 14 == 1) data = rom.read((n14)address); + if(address >> 14 == 2) data = rom.read((n14)address + 48_KiB); if(address >> 14 == 3) data = 0xff; } return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { mode = data; } @@ -52,5 +52,5 @@ struct CrossBlaim : Interface { s(mode); } - uint2 mode; + n2 mode; }; diff --git a/ares/msx/cartridge/board/konami-scc.cpp b/ares/msx/cartridge/board/konami-scc.cpp index c0347e282a..79e834d911 100644 --- a/ares/msx/cartridge/board/konami-scc.cpp +++ b/ares/msx/cartridge/board/konami-scc.cpp @@ -2,7 +2,7 @@ struct KonamiSCC : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; Node::Audio::Stream stream; auto load(Markup::Node document) -> void override { @@ -22,7 +22,7 @@ struct KonamiSCC : Interface { } auto main() -> void override { - int sample = 256 * 5; + s32 sample = 256 * 5; for(auto& voice : voices) { if(voice.frequency <= 8) continue; //voice is halted when frequency < 9 @@ -39,16 +39,16 @@ struct KonamiSCC : Interface { cartridge.step(16); } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >= 0x4000 && address <= 0x5fff) data = rom.read(bank[0] << 13 | (uint13)address); - if(address >= 0x6000 && address <= 0x7fff) data = rom.read(bank[1] << 13 | (uint13)address); - if(address >= 0x8000 && address <= 0x9fff) data = rom.read(bank[2] << 13 | (uint13)address); - if(address >= 0xa000 && address <= 0xbfff) data = rom.read(bank[3] << 13 | (uint13)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >= 0x4000 && address <= 0x5fff) data = rom.read(bank[0] << 13 | (n13)address); + if(address >= 0x6000 && address <= 0x7fff) data = rom.read(bank[1] << 13 | (n13)address); + if(address >= 0x8000 && address <= 0x9fff) data = rom.read(bank[2] << 13 | (n13)address); + if(address >= 0xa000 && address <= 0xbfff) data = rom.read(bank[3] << 13 | (n13)address); - if(address >= 0xc000 && address <= 0xdfff) data = rom.read(bank[0] << 13 | (uint13)address); - if(address >= 0xe000 && address <= 0xffff) data = rom.read(bank[1] << 13 | (uint13)address); - if(address >= 0x0000 && address <= 0x1fff) data = rom.read(bank[2] << 13 | (uint13)address); - if(address >= 0x2000 && address <= 0x3fff) data = rom.read(bank[3] << 13 | (uint13)address); + if(address >= 0xc000 && address <= 0xdfff) data = rom.read(bank[0] << 13 | (n13)address); + if(address >= 0xe000 && address <= 0xffff) data = rom.read(bank[1] << 13 | (n13)address); + if(address >= 0x0000 && address <= 0x1fff) data = rom.read(bank[2] << 13 | (n13)address); + if(address >= 0x2000 && address <= 0x3fff) data = rom.read(bank[3] << 13 | (n13)address); address.bit(8) = 0; //SCC ignores A8 @@ -84,7 +84,7 @@ struct KonamiSCC : Interface { return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x5000 && address <= 0x57ff) bank[0] = data; if(address >= 0x7000 && address <= 0x77ff) bank[1] = data; if(address >= 0x9000 && address <= 0x97ff) bank[2] = data; @@ -214,8 +214,8 @@ struct KonamiSCC : Interface { mixer.resize(512 * 5); auto table = mixer.data() + 256 * 5; - for(int n : range(256 * 5)) { - int16 volume = n * 8 * 16 / 5; + for(s32 n : range(256 * 5)) { + s16 volume = n * 8 * 16 / 5; table[+n] = +volume; table[-n] = -volume; } @@ -234,19 +234,19 @@ struct KonamiSCC : Interface { s(test); } - uint8 bank[4]; + n8 bank[4]; struct Voice { - uint16 clock; - uint12 frequency; - uint5 counter; - uint4 volume; - uint1 key; - int8 wave[32]; + n16 clock; + n12 frequency; + n5 counter; + n4 volume; + n1 key; + i8 wave[32]; } voices[5]; - uint8 test; + n8 test; //unserialized: - vector mixer; + vector mixer; }; diff --git a/ares/msx/cartridge/board/konami.cpp b/ares/msx/cartridge/board/konami.cpp index 2b0a141b05..191e317093 100644 --- a/ares/msx/cartridge/board/konami.cpp +++ b/ares/msx/cartridge/board/konami.cpp @@ -2,7 +2,7 @@ struct Konami : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -15,15 +15,15 @@ struct Konami : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >> 13 == 2) data = rom.read(bank[0] << 13 | (uint13)address); - if(address >> 13 == 3) data = rom.read(bank[1] << 13 | (uint13)address); - if(address >> 13 == 4) data = rom.read(bank[2] << 13 | (uint13)address); - if(address >> 13 == 5) data = rom.read(bank[3] << 13 | (uint13)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >> 13 == 2) data = rom.read(bank[0] << 13 | (n13)address); + if(address >> 13 == 3) data = rom.read(bank[1] << 13 | (n13)address); + if(address >> 13 == 4) data = rom.read(bank[2] << 13 | (n13)address); + if(address >> 13 == 5) data = rom.read(bank[3] << 13 | (n13)address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >> 13 == 2) bank[0] = 0; if(address >> 13 == 3) bank[1] = data; if(address >> 13 == 4) bank[2] = data; @@ -41,5 +41,5 @@ struct Konami : Interface { s(bank); } - uint8 bank[4]; + n8 bank[4]; }; diff --git a/ares/msx/cartridge/board/linear.cpp b/ares/msx/cartridge/board/linear.cpp index b7a2832a21..bd7b0106ec 100644 --- a/ares/msx/cartridge/board/linear.cpp +++ b/ares/msx/cartridge/board/linear.cpp @@ -1,6 +1,6 @@ struct Linear : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -13,12 +13,12 @@ struct Linear : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { + auto read(n16 address, n8 data) -> n8 override { data = rom.read(address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { } auto power() -> void override { diff --git a/ares/msx/cartridge/board/super-lode-runner.cpp b/ares/msx/cartridge/board/super-lode-runner.cpp index 752e85fce7..dfffee6cc8 100644 --- a/ares/msx/cartridge/board/super-lode-runner.cpp +++ b/ares/msx/cartridge/board/super-lode-runner.cpp @@ -3,7 +3,7 @@ struct SuperLodeRunner : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -16,12 +16,12 @@ struct SuperLodeRunner : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank << 14 | (uint14)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank << 14 | (n14)address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x0000 && address <= 0x3fff) bank = data; } @@ -33,5 +33,5 @@ struct SuperLodeRunner : Interface { s(bank); } - uint8 bank; + n8 bank; }; diff --git a/ares/msx/cartridge/board/super-pierrot.cpp b/ares/msx/cartridge/board/super-pierrot.cpp index 5f0c37c62a..4987571b9f 100644 --- a/ares/msx/cartridge/board/super-pierrot.cpp +++ b/ares/msx/cartridge/board/super-pierrot.cpp @@ -3,7 +3,7 @@ struct SuperPierrot : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -16,13 +16,13 @@ struct SuperPierrot : Interface { auto unload() -> void override { } - auto read(uint16 address, uint8 data) -> uint8 override { - if(address >= 0x4000 && address <= 0x7fff) data = rom.read(bank[0] << 14 | (uint14)address); - if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank[1] << 14 | (uint14)address); + auto read(n16 address, n8 data) -> n8 override { + if(address >= 0x4000 && address <= 0x7fff) data = rom.read(bank[0] << 14 | (n14)address); + if(address >= 0x8000 && address <= 0xbfff) data = rom.read(bank[1] << 14 | (n14)address); return data; } - auto write(uint16 address, uint8 data) -> void override { + auto write(n16 address, n8 data) -> void override { if(address >= 0x4000 && address <= 0x4fff) bank[0] = data; if(address >= 0x6000 && address <= 0x6fff) bank[0] = data; if(address >= 0x8000 && address <= 0x8fff) bank[0] = data; @@ -43,5 +43,5 @@ struct SuperPierrot : Interface { s(bank); } - uint8 bank[2]; + n8 bank[2]; }; diff --git a/ares/msx/cartridge/cartridge.cpp b/ares/msx/cartridge/cartridge.cpp index 73c5a0dcdd..9cfffff5e8 100644 --- a/ares/msx/cartridge/cartridge.cpp +++ b/ares/msx/cartridge/cartridge.cpp @@ -57,7 +57,7 @@ auto Cartridge::main() -> void { step(system.colorburst()); } -auto Cartridge::step(uint clocks) -> void { +auto Cartridge::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -67,12 +67,12 @@ auto Cartridge::power() -> void { if(board) board->power(); } -auto Cartridge::read(uint16 address) -> uint8 { +auto Cartridge::read(n16 address) -> n8 { if(board) return board->read(address, 0xff); return 0xff; } -auto Cartridge::write(uint16 address, uint8 data) -> void { +auto Cartridge::write(n16 address, n8 data) -> void { if(board) return board->write(address, data); } diff --git a/ares/msx/cartridge/cartridge.hpp b/ares/msx/cartridge/cartridge.hpp index 3d05f9bd47..8539b4f2b1 100644 --- a/ares/msx/cartridge/cartridge.hpp +++ b/ares/msx/cartridge/cartridge.hpp @@ -3,8 +3,8 @@ struct Cartridge; struct Cartridge : Thread { Node::Peripheral node; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto manifest() const -> string { return information.manifest; } auto name() const -> string { return information.name; } @@ -17,11 +17,11 @@ struct Cartridge : Thread { auto save() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; - auto read(uint16 address) -> uint8; - auto write(uint16 address, uint8 data) -> void; + auto read(n16 address) -> n8; + auto write(n16 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/msx/controller/controller.hpp b/ares/msx/controller/controller.hpp index 92aadb5832..9f5dd770c2 100644 --- a/ares/msx/controller/controller.hpp +++ b/ares/msx/controller/controller.hpp @@ -3,8 +3,8 @@ struct Controller { virtual ~Controller() = default; - virtual auto read() -> uint6 { return 0x3f; } - virtual auto write(uint8 data) -> void {} + virtual auto read() -> n6 { return 0x3f; } + virtual auto write(n8 data) -> void {} }; #include "port.hpp" diff --git a/ares/msx/controller/gamepad/gamepad.cpp b/ares/msx/controller/gamepad/gamepad.cpp index 56a8ac377c..b688fe41ff 100644 --- a/ares/msx/controller/gamepad/gamepad.cpp +++ b/ares/msx/controller/gamepad/gamepad.cpp @@ -9,7 +9,7 @@ Gamepad::Gamepad(Node::Port parent) { b = node->append("B"); } -auto Gamepad::read() -> uint6 { +auto Gamepad::read() -> n6 { platform->input(up); platform->input(down); platform->input(left); @@ -29,7 +29,7 @@ auto Gamepad::read() -> uint6 { xHold = 1, swap(leftLatch, rightLatch); } - uint6 data; + n6 data; data.bit(0) = !upLatch; data.bit(1) = !downLatch; data.bit(2) = !leftLatch; diff --git a/ares/msx/controller/gamepad/gamepad.hpp b/ares/msx/controller/gamepad/gamepad.hpp index ac4c8e0faf..2effe6350b 100644 --- a/ares/msx/controller/gamepad/gamepad.hpp +++ b/ares/msx/controller/gamepad/gamepad.hpp @@ -8,13 +8,13 @@ struct Gamepad : Controller { Gamepad(Node::Port); - auto read() -> uint6 override; + auto read() -> n6 override; private: - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/msx/controller/port.hpp b/ares/msx/controller/port.hpp index 042dd75969..7f407549c1 100644 --- a/ares/msx/controller/port.hpp +++ b/ares/msx/controller/port.hpp @@ -8,8 +8,8 @@ struct ControllerPort { auto unload() -> void; auto allocate(string name) -> Node::Peripheral; - auto read() -> uint6 { if(device) return device->read(); return 0x3f; } - auto write(uint8 data) { if(device) return device->write(data); } + auto read() -> n6 { if(device) return device->read(); return 0x3f; } + auto write(n8 data) { if(device) return device->write(data); } auto serialize(serializer&) -> void; diff --git a/ares/msx/cpu/cpu.cpp b/ares/msx/cpu/cpu.cpp index 4c908d7476..7a8799b12f 100644 --- a/ares/msx/cpu/cpu.cpp +++ b/ares/msx/cpu/cpu.cpp @@ -32,7 +32,7 @@ auto CPU::main() -> void { instruction(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(); } diff --git a/ares/msx/cpu/cpu.hpp b/ares/msx/cpu/cpu.hpp index 0c179ba843..b4c05f4d95 100644 --- a/ares/msx/cpu/cpu.hpp +++ b/ares/msx/cpu/cpu.hpp @@ -1,6 +1,6 @@ struct CPU : Z80, Z80::Bus, Thread { Node::Object node; - Memory::Writable ram; //MSX = 64KB, MSX2 = 256KB + Memory::Writable ram; //MSX = 64KB, MSX2 = 256KB struct Debugger { //debugger.cpp @@ -25,36 +25,36 @@ struct CPU : Z80, Z80::Bus, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto power() -> void; auto setIRQ(bool) -> void; //memory.cpp - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto in(uint16 address) -> uint8 override; - auto out(uint16 address, uint8 data) -> void override; + auto in(n16 address) -> n8 override; + auto out(n16 address, n8 data) -> void override; - auto readPrimarySlot() -> uint8; - auto writePrimarySlot(uint8 data) -> void; + auto readPrimarySlot() -> n8; + auto writePrimarySlot(n8 data) -> void; - auto readSecondarySlot() -> uint8; - auto writeSecondarySlot(uint8 data) -> void; + auto readSecondarySlot() -> n8; + auto writeSecondarySlot(n8 data) -> void; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; private: struct Slot { - uint8 memory; - uint2 primary; - uint2 secondary[4]; + n8 memory; + n2 primary; + n2 secondary[4]; } slot[4]; struct IO { - uint1 irqLine; + n1 irqLine; } io; }; diff --git a/ares/msx/cpu/memory.cpp b/ares/msx/cpu/memory.cpp index ddab34d3a7..824fff6f98 100644 --- a/ares/msx/cpu/memory.cpp +++ b/ares/msx/cpu/memory.cpp @@ -1,9 +1,9 @@ -auto CPU::read(uint16 address) -> uint8 { +auto CPU::read(n16 address) -> n8 { if(address == 0xffff) return readSecondarySlot(); - uint2 page = address.bit(14,15); - uint2 primary = slot[page].primary; - uint2 secondary = slot[primary].secondary[page]; + n2 page = address.bit(14,15); + n2 primary = slot[page].primary; + n2 secondary = slot[primary].secondary[page]; if(primary == 0) { return rom.bios.read(address); @@ -20,7 +20,7 @@ auto CPU::read(uint16 address) -> uint8 { if(primary == 3) { if(secondary == 0) { if(Model::MSX()) return ram.read(address); - uint22 logical = slot[page].memory << 14 | (uint14)address; + n22 logical = slot[page].memory << 14 | (n14)address; return ram.read(logical); } if(secondary == 1 && rom.sub) { @@ -31,12 +31,12 @@ auto CPU::read(uint16 address) -> uint8 { return 0xff; } -auto CPU::write(uint16 address, uint8 data) -> void { +auto CPU::write(n16 address, n8 data) -> void { if(address == 0xffff) return writeSecondarySlot(data); - uint2 page = address.bit(14,15); - uint2 primary = slot[page].primary; - uint2 secondary = slot[primary].secondary[page]; + n2 page = address.bit(14,15); + n2 primary = slot[page].primary; + n2 secondary = slot[primary].secondary[page]; if(primary == 0) { return; @@ -52,15 +52,15 @@ auto CPU::write(uint16 address, uint8 data) -> void { if(primary == 3) { if(Model::MSX()) return ram.write(address, data); - uint22 logical = slot[page].memory << 14 | (uint14)address; + n22 logical = slot[page].memory << 14 | (n14)address; return ram.write(logical, data); } } // -auto CPU::in(uint16 address) -> uint8 { - switch((uint8)address) { +auto CPU::in(n16 address) -> n8 { + switch((n8)address) { case 0x98: return vdp.read(0); case 0x99: return vdp.read(1); case 0x9a: return vdp.read(2); @@ -72,13 +72,13 @@ auto CPU::in(uint16 address) -> uint8 { if(Model::MSX()) return 0xff; //note: reading these ports is said to be unreliable; //but since it's not specified how so, that is not emulated here - return slot[(uint2)address].memory; + return slot[(n2)address].memory; } return 0xff; } -auto CPU::out(uint16 address, uint8 data) -> void { - switch((uint8)address) { +auto CPU::out(n16 address, n8 data) -> void { + switch((n8)address) { case 0x98: return vdp.write(0, data); case 0x99: return vdp.write(1, data); case 0x9a: return vdp.write(2, data); @@ -88,15 +88,15 @@ auto CPU::out(uint16 address, uint8 data) -> void { case 0xa8: return writePrimarySlot(data); case 0xaa: return keyboard.write(data.bit(0,3)); case 0xfc: case 0xfd: case 0xfe: case 0xff: - slot[(uint2)address].memory = data; + slot[(n2)address].memory = data; return; } } // -auto CPU::readPrimarySlot() -> uint8 { - uint8 data; +auto CPU::readPrimarySlot() -> n8 { + n8 data; data.bit(0,1) = slot[0].primary; data.bit(2,3) = slot[1].primary; data.bit(4,5) = slot[2].primary; @@ -104,7 +104,7 @@ auto CPU::readPrimarySlot() -> uint8 { return data; } -auto CPU::writePrimarySlot(uint8 data) -> void { +auto CPU::writePrimarySlot(n8 data) -> void { slot[0].primary = data.bit(0,1); slot[1].primary = data.bit(2,3); slot[2].primary = data.bit(4,5); @@ -113,9 +113,9 @@ auto CPU::writePrimarySlot(uint8 data) -> void { // -auto CPU::readSecondarySlot() -> uint8 { +auto CPU::readSecondarySlot() -> n8 { auto primary = slot[3].primary; - uint8 data; + n8 data; data.bit(0,1) = slot[primary].secondary[0]; data.bit(2,3) = slot[primary].secondary[1]; data.bit(4,5) = slot[primary].secondary[2]; @@ -123,7 +123,7 @@ auto CPU::readSecondarySlot() -> uint8 { return ~data; } -auto CPU::writeSecondarySlot(uint8 data) -> void { +auto CPU::writeSecondarySlot(n8 data) -> void { auto primary = slot[3].primary; slot[primary].secondary[0] = data.bit(0,1); slot[primary].secondary[1] = data.bit(2,3); diff --git a/ares/msx/keyboard/keyboard.cpp b/ares/msx/keyboard/keyboard.cpp index 48d37427ed..009846d257 100644 --- a/ares/msx/keyboard/keyboard.cpp +++ b/ares/msx/keyboard/keyboard.cpp @@ -30,8 +30,8 @@ auto Keyboard::connect() -> void { if(auto fp = platform->open(layout, "layout.bml", File::Read)) { document = BML::unserialize(fp->reads()); } - for(uint column : range(12)) { - for(uint row : range(8)) { + for(u32 column : range(12)) { + for(u32 row : range(8)) { string label{column, ",", row}; if(auto key = document[{"layout/key[", column * 8 + row, "]"}]) { label = key.text(); @@ -43,8 +43,8 @@ auto Keyboard::connect() -> void { auto Keyboard::disconnect() -> void { layout = {}; - for(uint column : range(12)) { - for(uint row : range(8)) { + for(u32 column : range(12)) { + for(u32 row : range(8)) { matrix[column][row] = {}; } } @@ -54,11 +54,11 @@ auto Keyboard::power() -> void { io = {}; } -auto Keyboard::read() -> uint8 { - uint8 column = io.select; - uint8 data = 0xff; +auto Keyboard::read() -> n8 { + n8 column = io.select; + n8 data = 0xff; if(column >= 0 && column <= 11) { - for(uint row : range(8)) { + for(u32 row : range(8)) { if(auto node = matrix[column][row]) { platform->input(node); data.bit(row) = !node->value(); @@ -68,7 +68,7 @@ auto Keyboard::read() -> uint8 { return data; } -auto Keyboard::write(uint4 data) -> void { +auto Keyboard::write(n4 data) -> void { io.select = data; } diff --git a/ares/msx/keyboard/keyboard.hpp b/ares/msx/keyboard/keyboard.hpp index 3f0f15564c..e1ddf6ef34 100644 --- a/ares/msx/keyboard/keyboard.hpp +++ b/ares/msx/keyboard/keyboard.hpp @@ -11,8 +11,8 @@ struct Keyboard { auto disconnect() -> void; auto power() -> void; - auto read() -> uint8; - auto write(uint4 data) -> void; + auto read() -> n8; + auto write(n4 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -21,7 +21,7 @@ struct Keyboard { Node::Input::Button matrix[12][8]; struct IO { - uint4 select; + n4 select; } io; }; diff --git a/ares/msx/msx.hpp b/ares/msx/msx.hpp index 59c6c78e76..fa602f34e2 100644 --- a/ares/msx/msx.hpp +++ b/ares/msx/msx.hpp @@ -11,6 +11,7 @@ namespace ares::MSX { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { diff --git a/ares/msx/psg/psg.cpp b/ares/msx/psg/psg.cpp index 83aef6085a..5059ff2ca8 100644 --- a/ares/msx/psg/psg.cpp +++ b/ares/msx/psg/psg.cpp @@ -29,7 +29,7 @@ auto PSG::main() -> void { step(1); } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -38,18 +38,18 @@ auto PSG::power() -> void { AY38910::power(); Thread::create(system.colorburst() / 16.0, {&PSG::main, this}); - for(uint level : range(16)) { + for(u32 level : range(16)) { volume[level] = 1.0 / pow(2, 1.0 / 2 * (15 - level)); } } -auto PSG::readIO(uint1 port) -> uint8 { +auto PSG::readIO(n1 port) -> n8 { if(port == 0) return controllerPort1.read() | 0x40; if(port == 1) return controllerPort2.read() | 0xc0; unreachable; } -auto PSG::writeIO(uint1 port, uint8 data) -> void { +auto PSG::writeIO(n1 port, n8 data) -> void { if(port == 0) return controllerPort1.write(data); if(port == 1) return controllerPort2.write(data); } diff --git a/ares/msx/psg/psg.hpp b/ares/msx/psg/psg.hpp index 83f216c678..ac6ba59f9b 100644 --- a/ares/msx/psg/psg.hpp +++ b/ares/msx/psg/psg.hpp @@ -7,17 +7,17 @@ struct PSG : AY38910, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; - auto readIO(uint1 port) -> uint8 override; - auto writeIO(uint1 port, uint8 data) -> void override; + auto readIO(n1 port) -> n8 override; + auto writeIO(n1 port, n8 data) -> void override; //serialization.cpp auto serialize(serializer&) -> void; private: - double volume[16]; + f64 volume[16]; }; extern PSG psg; diff --git a/ares/msx/system/serialization.cpp b/ares/msx/system/serialization.cpp index bab6465ea9..37d9dc0bec 100644 --- a/ares/msx/system/serialization.cpp +++ b/ares/msx/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/msx/system/system.cpp b/ares/msx/system/system.cpp index c7ea4498b2..548d42a6f3 100644 --- a/ares/msx/system/system.cpp +++ b/ares/msx/system/system.cpp @@ -2,7 +2,17 @@ namespace ares::MSX { +auto enumerate() -> vector { + return { + "[Microsoft] MSX (NTSC)", + "[Microsoft] MSX (PAL)", + "[Microsoft] MSX2 (NTSC)", + "[Microsoft] MSX2 (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -35,10 +45,24 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "MSX" ) information.model = Model::MSX; - if(name == "MSX2") information.model = Model::MSX2; + if(name.find("MSX")) { + information.name = "MSX"; + information.model = Model::MSX; + } + if(name.find("MSX2")) { + information.name = "MSX2"; + information.model = Model::MSX2; + } + if(name.find("NTSC")) { + information.region = Region::NTSC; + information.colorburst = Constants::Colorburst::NTSC; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.colorburst = Constants::Colorburst::PAL; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -48,14 +72,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC → PAL"); - regionNode->setAllowedValues({ - "NTSC → PAL", - "PAL → NTSC", - "NTSC", - "PAL" - }); - scheduler.reset(); keyboard.load(node); cpu.load(node); @@ -92,22 +108,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC") { - information.region = Region::NTSC; - information.colorburst = Constants::Colorburst::NTSC; - } - if(region == "PAL") { - information.region = Region::PAL; - information.colorburst = Constants::Colorburst::PAL; - } - }; - auto regions = regionNode->latch().split("→").strip(); - setRegion(regions.first()); - for(auto& requested : reverse(regions)) { - if(requested == cartridge.region()) setRegion(requested); - } - rom.bios.allocate(32_KiB); if(auto fp = platform->open(node, "bios.rom", File::Read, File::Required)) { rom.bios.load(fp); diff --git a/ares/msx/system/system.hpp b/ares/msx/system/system.hpp index c64fcfaaa4..a7e1760416 100644 --- a/ares/msx/system/system.hpp +++ b/ares/msx/system/system.hpp @@ -1,19 +1,18 @@ struct ROM { - Memory::Readable bios; - Memory::Readable sub; + Memory::Readable bios; + Memory::Readable sub; }; struct System { Node::System node; - Node::Setting::String regionNode; - enum class Model : uint { MSX, MSX2 }; - enum class Region : uint { NTSC, PAL }; + enum class Model : u32 { MSX, MSX2 }; + enum class Region : u32 { NTSC, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto region() const -> Region { return information.region; } - auto colorburst() const -> double { return information.colorburst; } + auto colorburst() const -> f64 { return information.colorburst; } //system.cpp auto game() -> string; @@ -31,9 +30,10 @@ struct System { private: struct Information { + string name = "MSX"; Model model = Model::MSX; Region region = Region::NTSC; - double colorburst = Constants::Colorburst::NTSC; + f64 colorburst = Constants::Colorburst::NTSC; } information; //serialization.cpp diff --git a/ares/msx/vdp/color.cpp b/ares/msx/vdp/color.cpp index bd8e276842..5c1ab28098 100644 --- a/ares/msx/vdp/color.cpp +++ b/ares/msx/vdp/color.cpp @@ -1,4 +1,4 @@ -auto VDP::colorMSX(uint32 color) -> uint64 { +auto VDP::colorMSX(n32 color) -> n64 { switch(color.bit(0,3)) { case 0: return 0x0000'0000'0000ull; //transparent case 1: return 0x0000'0000'0000ull; //black @@ -20,14 +20,14 @@ auto VDP::colorMSX(uint32 color) -> uint64 { unreachable; } -auto VDP::colorMSX2(uint32 color) -> uint64 { - uint3 B = color.bit(0,2); - uint3 R = color.bit(3,5); - uint3 G = color.bit(6,8); +auto VDP::colorMSX2(n32 color) -> n64 { + n3 B = color.bit(0,2); + n3 R = color.bit(3,5); + n3 G = color.bit(6,8); - uint64 r = image::normalize(R, 3, 16); - uint64 g = image::normalize(G, 3, 16); - uint64 b = image::normalize(B, 3, 16); + n64 r = image::normalize(R, 3, 16); + n64 g = image::normalize(G, 3, 16); + n64 b = image::normalize(B, 3, 16); return r << 32 | g << 16 | b << 0; } diff --git a/ares/msx/vdp/vdp.cpp b/ares/msx/vdp/vdp.cpp index 3c36602d6c..4ee2582b43 100644 --- a/ares/msx/vdp/vdp.cpp +++ b/ares/msx/vdp/vdp.cpp @@ -36,7 +36,7 @@ auto VDP::unload() -> void { node.reset(); } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -74,7 +74,7 @@ auto VDP::power() -> void { /* Z80 I/O ports 0x98 - 0x9b */ -auto VDP::read(uint2 port) -> uint8 { +auto VDP::read(n2 port) -> n8 { if(Model::MSX()) switch(port) { case 0: return TMS9918::data(); @@ -90,7 +90,7 @@ auto VDP::read(uint2 port) -> uint8 { return 0xff; } -auto VDP::write(uint2 port, uint8 data) -> void { +auto VDP::write(n2 port, n8 data) -> void { if(Model::MSX()) switch(port) { case 0: return TMS9918::data(data); diff --git a/ares/msx/vdp/vdp.hpp b/ares/msx/vdp/vdp.hpp index 34fd62e9aa..6bea45754b 100644 --- a/ares/msx/vdp/vdp.hpp +++ b/ares/msx/vdp/vdp.hpp @@ -6,17 +6,17 @@ struct VDP : TMS9918, V9938, Thread { auto load(Node::Object) -> void; auto unload() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto irq(bool line) -> void override; auto frame() -> void override; auto power() -> void; - auto read(uint2 port) -> uint8; - auto write(uint2 port, uint8 data) -> void; + auto read(n2 port) -> n8; + auto write(n2 port, n8 data) -> void; //color.cpp - auto colorMSX(uint32) -> uint64; - auto colorMSX2(uint32) -> uint64; + auto colorMSX(n32) -> n64; + auto colorMSX2(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/n64/ai/ai.cpp b/ares/n64/ai/ai.cpp index 0fa870a04e..0c6d4976ac 100644 --- a/ares/n64/ai/ai.cpp +++ b/ares/n64/ai/ai.cpp @@ -47,7 +47,7 @@ auto AI::sample() -> void { } } -auto AI::step(uint clocks) -> void { +auto AI::step(u32 clocks) -> void { clock += clocks; } diff --git a/ares/n64/ai/ai.hpp b/ares/n64/ai/ai.hpp index 33a622c02b..2120c89167 100644 --- a/ares/n64/ai/ai.hpp +++ b/ares/n64/ai/ai.hpp @@ -19,7 +19,7 @@ struct AI : Thread, Memory::IO { auto unload() -> void; auto main() -> void; auto sample() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp @@ -30,16 +30,16 @@ struct AI : Thread, Memory::IO { auto serialize(serializer&) -> void; struct FIFO { - uint24 address; + n24 address; } fifo[2]; struct IO { - uint1 dmaEnable; - uint24 dmaAddress[2]; - uint18 dmaLength[2]; - uint2 dmaCount; - uint14 dacRate; - uint4 bitRate; + n1 dmaEnable; + n24 dmaAddress[2]; + n18 dmaLength[2]; + n2 dmaCount; + n14 dacRate; + n4 bitRate; } io; struct DAC { diff --git a/ares/n64/ai/io.cpp b/ares/n64/ai/io.cpp index 57ec0b3c65..36020c63d7 100644 --- a/ares/n64/ai/io.cpp +++ b/ares/n64/ai/io.cpp @@ -9,7 +9,7 @@ static const vector registerNames = { auto AI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address != 3) { //AI_LENGTH (mirrored) @@ -33,7 +33,7 @@ auto AI::readWord(u32 address) -> u32 { auto AI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //AI_DRAM_ADDRESS @@ -44,7 +44,7 @@ auto AI::writeWord(u32 address, u32 data_) -> void { if(address == 1) { //AI_LENGTH - uint18 length = data.bit(0,17) & ~7; + n18 length = data.bit(0,17) & ~7; if(io.dmaCount < 2 && length) { io.dmaLength[io.dmaCount] = length; io.dmaCount++; diff --git a/ares/n64/controller/controller.hpp b/ares/n64/controller/controller.hpp index d9816445ea..3e7afa370b 100644 --- a/ares/n64/controller/controller.hpp +++ b/ares/n64/controller/controller.hpp @@ -2,7 +2,7 @@ struct Controller { Node::Peripheral node; virtual ~Controller() = default; - virtual auto read() -> uint32 { return 0; } + virtual auto read() -> n32 { return 0; } }; #include "port.hpp" diff --git a/ares/n64/controller/gamepad/gamepad.cpp b/ares/n64/controller/gamepad/gamepad.cpp index 6617ed9b31..954f8175be 100644 --- a/ares/n64/controller/gamepad/gamepad.cpp +++ b/ares/n64/controller/gamepad/gamepad.cpp @@ -19,7 +19,7 @@ Gamepad::Gamepad(Node::Port parent) { start = node->append("Start"); } -auto Gamepad::read() -> uint32 { +auto Gamepad::read() -> n32 { platform->input(x); platform->input(y); platform->input(up); @@ -37,7 +37,7 @@ auto Gamepad::read() -> uint32 { platform->input(z); platform->input(start); - uint32 data; + n32 data; data.byte(0) = -y->value() >> 8; data.byte(1) = +x->value() >> 8; data.bit(16) = cameraRight->value(); diff --git a/ares/n64/controller/gamepad/gamepad.hpp b/ares/n64/controller/gamepad/gamepad.hpp index 41f106c01b..1fe5434e9f 100644 --- a/ares/n64/controller/gamepad/gamepad.hpp +++ b/ares/n64/controller/gamepad/gamepad.hpp @@ -17,5 +17,5 @@ struct Gamepad : Controller { Node::Input::Button start; Gamepad(Node::Port); - auto read() -> uint32 override; + auto read() -> n32 override; }; diff --git a/ares/n64/cpu/cpu.cpp b/ares/n64/cpu/cpu.cpp index 9c5b6118f9..6ab36dc8bc 100644 --- a/ares/n64/cpu/cpu.cpp +++ b/ares/n64/cpu/cpu.cpp @@ -31,7 +31,7 @@ auto CPU::main() -> void { synchronize(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { Thread::clock += clocks; } @@ -110,7 +110,7 @@ auto CPU::instructionDebug() -> void { if(mask[(ipu.pc & 0x1fff'ffff) >> 2]) return; mask[(ipu.pc & 0x1fff'ffff) >> 2] = 1; - static uint counter = 0; + static u32 counter = 0; //if(++counter > 100) return; print( disassembler.hint(hex(pipeline.address, 8L)), " ", diff --git a/ares/n64/cpu/cpu.hpp b/ares/n64/cpu/cpu.hpp index fd1c301fd8..d03f51bab4 100644 --- a/ares/n64/cpu/cpu.hpp +++ b/ares/n64/cpu/cpu.hpp @@ -23,7 +23,7 @@ struct CPU : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto synchronize() -> void; auto instruction() -> void; @@ -71,10 +71,10 @@ struct CPU : Thread { CPU& self; Context(CPU& self) : self(self) {} - enum Mode : uint { Kernel, Supervisor, User }; - enum Segment : uint { Invalid, Mapped, Cached, Uncached }; - uint mode; - uint segment[8]; //512_MiB chunks + enum Mode : u32 { Kernel, Supervisor, User }; + enum Segment : u32 { Invalid, Mapped, Cached, Uncached }; + u32 mode; + u32 segment[8]; //512_MiB chunks auto setMode() -> void; } context{*this}; @@ -83,7 +83,7 @@ struct CPU : Thread { struct TLB { CPU& self; TLB(CPU& self) : self(self) {} - static constexpr uint Entries = 32; + static constexpr u32 Entries = 32; //tlb.cpp auto load(u32 address) -> maybe; @@ -94,23 +94,23 @@ struct CPU : Thread { //scc-tlb.cpp auto synchronize() -> void; - uint1 global[2]; - uint1 valid[2]; - uint1 dirty[2]; - uint3 cacheAlgorithm[2]; - uint32 physicalAddress[2]; - uint32 pageMask; - uint32 virtualAddress; - uint8 addressSpaceID; + n1 global[2]; + n1 valid[2]; + n1 dirty[2]; + n3 cacheAlgorithm[2]; + n32 physicalAddress[2]; + n32 pageMask; + n32 virtualAddress; + n8 addressSpaceID; //unimplemented: - uint22 unused; - uint2 region; + n22 unused; + n2 region; //internal: - uint1 globals; - uint32 addressMaskHi; - uint32 addressMaskLo; - uint32 addressSelect; - uint32 addressCompare; + n1 globals; + n32 addressMaskHi; + n32 addressMaskLo; + n32 addressSelect; + n32 addressCompare; } entry[TLB::Entries]; u32 physicalAddress; @@ -120,15 +120,15 @@ struct CPU : Thread { auto readAddress (u32 address) -> maybe; auto writeAddress(u32 address) -> maybe; - auto readByte (u32 address) -> maybe; - auto readHalf (u32 address) -> maybe; - auto readWord (u32 address) -> maybe; - auto readDouble (u32 address) -> maybe; + auto readByte(u32 address) -> maybe; + auto readHalf(u32 address) -> maybe; + auto readWord(u32 address) -> maybe; + auto readDual(u32 address) -> maybe; - auto writeByte (u32 address, u8 data) -> bool; - auto writeHalf (u32 address, u16 data) -> bool; - auto writeWord (u32 address, u32 data) -> bool; - auto writeDouble (u32 address, u64 data) -> bool; + auto writeByte(u32 address, u8 data) -> bool; + auto writeHalf(u32 address, u16 data) -> bool; + auto writeWord(u32 address, u32 data) -> bool; + auto writeDual(u32 address, u64 data) -> bool; //serialization.cpp auto serialize(serializer&) -> void; @@ -136,7 +136,7 @@ struct CPU : Thread { //exception.cpp struct Exception { CPU& self; - auto trigger(uint code, uint coprocessor = 0) -> void; + auto trigger(u32 code, u32 coprocessor = 0) -> void; auto interrupt() -> void; auto tlbModification() -> void; auto tlbLoad() -> void; @@ -158,7 +158,7 @@ struct CPU : Thread { auto watchAddress() -> void; } exception{*this}; - enum Interrupt : uint { + enum Interrupt : u32 { Software0 = 0, Software1 = 1, RCP = 2, @@ -183,7 +183,7 @@ struct CPU : Thread { using cr64 = const r64; struct IPU { - enum Register : uint { + enum Register : u32 { R0, //zero (read-only) AT, //assembler temporary V0, V1, //arithmetic values @@ -318,14 +318,14 @@ struct CPU : Thread { struct SCC { //0 struct Index { - uint6 tlbEntry; - uint1 probeFailure; + n6 tlbEntry; + n1 probeFailure; } index; //1 struct Random { - uint5 index; - uint1 unused; + n5 index; + n1 unused; } random; //2: EntryLo0 @@ -336,14 +336,14 @@ struct CPU : Thread { //4 struct Context { - uint19 badVirtualAddress; - uint41 pageTableEntryBase; + n19 badVirtualAddress; + n41 pageTableEntryBase; } context; //6 struct Wired { - uint5 index; - uint1 unused; + n5 index; + n1 unused; } wired; //8 @@ -357,38 +357,38 @@ struct CPU : Thread { //12 struct Status { - uint1 interruptEnable; - uint1 exceptionLevel; - uint1 errorLevel; - uint2 privilegeMode; - uint1 userExtendedAddressing; - uint1 supervisorExtendedAddressing; - uint1 kernelExtendedAddressing; - uint8 interruptMask; - uint1 de; //unused - uint1 ce; //unused - uint1 condition; - uint1 softReset; - uint1 tlbShutdown; - uint1 vectorLocation; - uint1 instructionTracing; - uint1 reverseEndian; - uint1 floatingPointMode; - uint1 lowPowerMode; + n1 interruptEnable; + n1 exceptionLevel; + n1 errorLevel; + n2 privilegeMode; + n1 userExtendedAddressing; + n1 supervisorExtendedAddressing; + n1 kernelExtendedAddressing; + n8 interruptMask; + n1 de; //unused + n1 ce; //unused + n1 condition; + n1 softReset; + n1 tlbShutdown; + n1 vectorLocation; + n1 instructionTracing; + n1 reverseEndian; + n1 floatingPointMode; + n1 lowPowerMode; struct Enable { - uint1 coprocessor0; - uint1 coprocessor1; - uint1 coprocessor2; - uint1 coprocessor3; + n1 coprocessor0; + n1 coprocessor1; + n1 coprocessor2; + n1 coprocessor3; } enable; } status; //13 struct Cause { - uint5 exceptionCode; - uint8 interruptPending; - uint2 coprocessorError; - uint1 branchDelay; + n5 exceptionCode; + n8 interruptPending; + n2 coprocessorError; + n1 branchDelay; } cause; //14: Exception Program Counter @@ -402,53 +402,53 @@ struct CPU : Thread { //16 struct Configuration { - uint2 coherencyAlgorithmKSEG0; - uint2 cu; //reserved - uint1 bigEndian; - uint2 sysadWritebackPattern; - uint2 systemClockRatio; + n2 coherencyAlgorithmKSEG0; + n2 cu; //reserved + n1 bigEndian; + n2 sysadWritebackPattern; + n2 systemClockRatio; } configuration; //17: Load Linked Address u64 ll; - uint1 llbit; + n1 llbit; //18 struct WatchLo { - uint1 trapOnWrite; - uint1 trapOnRead; - uint32 physicalAddress; + n1 trapOnWrite; + n1 trapOnRead; + n32 physicalAddress; } watchLo; //19 struct WatchHi { - uint4 physicalAddressExtended; //unused; for R4000 compatibility only + n4 physicalAddressExtended; //unused; for R4000 compatibility only } watchHi; //20 struct XContext { - uint27 badVirtualAddress; - uint2 region; - uint31 pageTableEntryBase; + n27 badVirtualAddress; + n2 region; + n31 pageTableEntryBase; } xcontext; //26 struct ParityError { - uint8 diagnostic; //unused; for R4000 compatibility only + n8 diagnostic; //unused; for R4000 compatibility only } parityError; //28 struct TagLo { - uint2 primaryCacheState; - uint32 physicalAddress; + n2 primaryCacheState; + n32 physicalAddress; } tagLo; //31: Error Exception Program Counter u64 epcError; } scc; - auto getControlRegister(uint5) -> u64; - auto setControlRegister(uint5, uint64) -> void; + auto getControlRegister(n5) -> u64; + auto setControlRegister(n5, n64) -> void; auto instructionDMFC0(r64& rt, u8 rd) -> void; auto instructionDMTC0(cr64& rt, u8 rd) -> void; @@ -472,37 +472,37 @@ struct CPU : Thread { } coprocessor; struct ControlStatus { - uint2 roundMode = 0; + n2 roundMode = 0; struct Flag { - uint1 inexact = 0; - uint1 underflow = 0; - uint1 overflow = 0; - uint1 divisionByZero = 0; - uint1 invalidOperation = 0; + n1 inexact = 0; + n1 underflow = 0; + n1 overflow = 0; + n1 divisionByZero = 0; + n1 invalidOperation = 0; } flag; struct Enable { - uint1 inexact = 0; - uint1 underflow = 0; - uint1 overflow = 0; - uint1 divisionByZero = 0; - uint1 invalidOperation = 0; + n1 inexact = 0; + n1 underflow = 0; + n1 overflow = 0; + n1 divisionByZero = 0; + n1 invalidOperation = 0; } enable; struct Cause { - uint1 inexact = 0; - uint1 underflow = 0; - uint1 overflow = 0; - uint1 divisionByZero = 0; - uint1 invalidOperation = 0; - uint1 unimplementedOperation = 0; + n1 inexact = 0; + n1 underflow = 0; + n1 overflow = 0; + n1 divisionByZero = 0; + n1 invalidOperation = 0; + n1 unimplementedOperation = 0; } cause; - uint1 compare = 0; - uint1 flushed = 0; + n1 compare = 0; + n1 flushed = 0; } csr; } fpu; - template auto fgr(uint) -> T&; - auto getControlRegisterFPU(uint5) -> u32; - auto setControlRegisterFPU(uint5, uint32) -> void; + template auto fgr(u32) -> T&; + auto getControlRegisterFPU(n5) -> u32; + auto setControlRegisterFPU(n5, n32) -> void; auto instructionBC1(bool value, bool likely, s16 imm) -> void; auto instructionCFC1(r64& rt, u8 rd) -> void; @@ -658,24 +658,24 @@ struct CPU : Thread { auto REGIMM() -> vector; auto SCC() -> vector; auto FPU() -> vector; - auto immediate(s64 value, uint bits = 0) const -> string; - auto ipuRegisterName(uint index) const -> string; - auto ipuRegisterValue(uint index) const -> string; - auto ipuRegisterIndex(uint index, s16 offset) const -> string; - auto sccRegisterName(uint index) const -> string; - auto sccRegisterValue(uint index) const -> string; - auto fpuRegisterName(uint index) const -> string; - auto fpuRegisterValue(uint index) const -> string; - auto ccrRegisterName(uint index) const -> string; - auto ccrRegisterValue(uint index) const -> string; + auto immediate(s64 value, u32 bits = 0) const -> string; + auto ipuRegisterName(u32 index) const -> string; + auto ipuRegisterValue(u32 index) const -> string; + auto ipuRegisterIndex(u32 index, s16 offset) const -> string; + auto sccRegisterName(u32 index) const -> string; + auto sccRegisterValue(u32 index) const -> string; + auto fpuRegisterName(u32 index) const -> string; + auto fpuRegisterValue(u32 index) const -> string; + auto ccrRegisterName(u32 index) const -> string; + auto ccrRegisterValue(u32 index) const -> string; u32 address; u32 instruction; } disassembler{*this}; static constexpr bool Endian = 1; //0 = little, 1 = big - static constexpr uint FlipLE = (Endian == 0 ? 7 : 0); - static constexpr uint FlipBE = (Endian == 1 ? 7 : 0); + static constexpr u32 FlipLE = (Endian == 0 ? 7 : 0); + static constexpr u32 FlipBE = (Endian == 1 ? 7 : 0); }; extern CPU cpu; diff --git a/ares/n64/cpu/disassembler.cpp b/ares/n64/cpu/disassembler.cpp index 4caae79ae6..08763eabd5 100644 --- a/ares/n64/cpu/disassembler.cpp +++ b/ares/n64/cpu/disassembler.cpp @@ -402,12 +402,12 @@ auto CPU::Disassembler::FPU() -> vector { return {}; } -auto CPU::Disassembler::immediate(s64 value, uint bits) const -> string { +auto CPU::Disassembler::immediate(s64 value, u32 bits) const -> string { if(value < 0) return {"-$", hex(-value, bits >> 2)}; return {"$", hex(value, bits >> 2)}; }; -auto CPU::Disassembler::ipuRegisterName(uint index) const -> string { +auto CPU::Disassembler::ipuRegisterName(u32 index) const -> string { static const string registers[32] = { "0", "at", "v0", "v1", "a0", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", @@ -417,12 +417,12 @@ auto CPU::Disassembler::ipuRegisterName(uint index) const -> string { return registers[index]; } -auto CPU::Disassembler::ipuRegisterValue(uint index) const -> string { +auto CPU::Disassembler::ipuRegisterValue(u32 index) const -> string { if(index && showValues) return {ipuRegisterName(index), hint("{$", hex(self.ipu.r[index].u64, 8L), "}")}; return ipuRegisterName(index); } -auto CPU::Disassembler::ipuRegisterIndex(uint index, s16 offset) const -> string { +auto CPU::Disassembler::ipuRegisterIndex(u32 index, s16 offset) const -> string { string adjust; if(offset >= 0) adjust = {"+$", hex( offset)}; if(offset < 0) adjust = {"-$", hex(-offset)}; @@ -430,7 +430,7 @@ auto CPU::Disassembler::ipuRegisterIndex(uint index, s16 offset) const -> string return {ipuRegisterName(index), adjust}; } -auto CPU::Disassembler::sccRegisterName(uint index) const -> string { +auto CPU::Disassembler::sccRegisterName(u32 index) const -> string { static const string registers[32] = { "Index", "Random", "EntryLo0", "EntryLo1", "Context", "PageMask", "Wired", "Unused7", @@ -444,12 +444,12 @@ auto CPU::Disassembler::sccRegisterName(uint index) const -> string { return registers[index]; } -auto CPU::Disassembler::sccRegisterValue(uint index) const -> string { +auto CPU::Disassembler::sccRegisterValue(u32 index) const -> string { if(showValues) return {sccRegisterName(index), hint("{$", hex(self.getControlRegister(index), 8L), "}")}; return sccRegisterName(index); } -auto CPU::Disassembler::fpuRegisterName(uint index) const -> string { +auto CPU::Disassembler::fpuRegisterName(u32 index) const -> string { static const string registers[32] = { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", @@ -459,7 +459,7 @@ auto CPU::Disassembler::fpuRegisterName(uint index) const -> string { return registers[index]; } -auto CPU::Disassembler::fpuRegisterValue(uint index) const -> string { +auto CPU::Disassembler::fpuRegisterValue(u32 index) const -> string { bool f32 = (instruction & 1 << 21) == 0; bool f64 = (instruction & 1 << 21) != 0; if(f32 && showValues) return {fpuRegisterName(index), hint("{", self.fpu.r[index].f32, "}")}; @@ -467,11 +467,11 @@ auto CPU::Disassembler::fpuRegisterValue(uint index) const -> string { return fpuRegisterName(index); } -auto CPU::Disassembler::ccrRegisterName(uint index) const -> string { +auto CPU::Disassembler::ccrRegisterName(u32 index) const -> string { return {"ccr", index}; } -auto CPU::Disassembler::ccrRegisterValue(uint index) const -> string { +auto CPU::Disassembler::ccrRegisterValue(u32 index) const -> string { if(showValues) return {ccrRegisterName(index), hint("{$", hex(self.getControlRegisterFPU(index)), "}")}; return ccrRegisterName(index); } diff --git a/ares/n64/cpu/exceptions.cpp b/ares/n64/cpu/exceptions.cpp index 5f505b5126..8b6d1257d9 100644 --- a/ares/n64/cpu/exceptions.cpp +++ b/ares/n64/cpu/exceptions.cpp @@ -1,4 +1,4 @@ -auto CPU::Exception::trigger(uint code, uint coprocessor) -> void { +auto CPU::Exception::trigger(u32 code, u32 coprocessor) -> void { if(self.debugger.tracer.exception->enabled()) { if(code != 0) self.debugger.exception(hex(code, 2L)); } diff --git a/ares/n64/cpu/fpu.cpp b/ares/n64/cpu/fpu.cpp index 73ff5bd8c1..8cae3d3a24 100644 --- a/ares/n64/cpu/fpu.cpp +++ b/ares/n64/cpu/fpu.cpp @@ -6,7 +6,7 @@ auto CPU::FPU::setFloatingPointMode(bool mode) -> void { } } -template<> auto CPU::fgr(uint index) -> s32& { +template<> auto CPU::fgr(u32 index) -> s32& { if(scc.status.floatingPointMode) { return fpu.r[index].s32; } else if(index & 1) { @@ -16,11 +16,11 @@ template<> auto CPU::fgr(uint index) -> s32& { } } -template<> auto CPU::fgr(uint index) -> u32& { +template<> auto CPU::fgr(u32 index) -> u32& { return (u32&)fgr(index); } -template<> auto CPU::fgr(uint index) -> f32& { +template<> auto CPU::fgr(u32 index) -> f32& { if(scc.status.floatingPointMode) { return fpu.r[index].f32; } else if(index & 1) { @@ -30,7 +30,7 @@ template<> auto CPU::fgr(uint index) -> f32& { } } -template<> auto CPU::fgr(uint index) -> s64& { +template<> auto CPU::fgr(u32 index) -> s64& { if(scc.status.floatingPointMode) { return fpu.r[index].s64; } else { @@ -38,11 +38,11 @@ template<> auto CPU::fgr(uint index) -> s64& { } } -template<> auto CPU::fgr(uint index) -> u64& { +template<> auto CPU::fgr(u32 index) -> u64& { return (u64&)fgr(index); } -template<> auto CPU::fgr(uint index) -> f64& { +template<> auto CPU::fgr(u32 index) -> f64& { if(scc.status.floatingPointMode) { return fpu.r[index].f64; } else { @@ -50,8 +50,8 @@ template<> auto CPU::fgr(uint index) -> f64& { } } -auto CPU::getControlRegisterFPU(uint5 index) -> u32 { - uint32 data; +auto CPU::getControlRegisterFPU(n5 index) -> u32 { + n32 data; switch(index) { case 0: //coprocessor revision identifier data.bit(0, 7) = fpu.coprocessor.revision; @@ -83,7 +83,7 @@ auto CPU::getControlRegisterFPU(uint5 index) -> u32 { return data; } -auto CPU::setControlRegisterFPU(uint5 index, uint32 data) -> void { +auto CPU::setControlRegisterFPU(n5 index, n32 data) -> void { //read-only variables are defined but commented out for documentation purposes switch(index) { case 0: //coprocessor revision identifier @@ -91,7 +91,7 @@ auto CPU::setControlRegisterFPU(uint5 index, uint32 data) -> void { //fpu.coprocessor.implementation = data.bit(8,15); break; case 31: {//control / status register - uint roundModePrevious = fpu.csr.roundMode; + u32 roundModePrevious = fpu.csr.roundMode; fpu.csr.roundMode.bit(0) = data.bit( 0); fpu.csr.roundMode.bit(1) = data.bit( 1); fpu.csr.flag.inexact = data.bit( 2); @@ -286,7 +286,7 @@ auto CPU::instructionFTRUNC_W_D(u8 fd, u8 fs) -> void { FD(s32) = FS(f64) < 0 ? auto CPU::instructionLDC1(u8 ft, cr64& rs, s16 imm) -> void { if(!scc.status.enable.coprocessor1) return exception.coprocessor1(); - if(auto data = readDouble(rs.u32 + imm)) FT(u64) = *data; + if(auto data = readDual(rs.u32 + imm)) FT(u64) = *data; } auto CPU::instructionLWC1(u8 ft, cr64& rs, s16 imm) -> void { @@ -304,7 +304,7 @@ auto CPU::instructionMTC1(cr64& rt, u8 fs) -> void { auto CPU::instructionSDC1(u8 ft, cr64& rs, s16 imm) -> void { if(!scc.status.enable.coprocessor1) return exception.coprocessor1(); - writeDouble(rs.u32 + imm, FT(u64)); + writeDual(rs.u32 + imm, FT(u64)); } auto CPU::instructionSWC1(u8 ft, cr64& rs, s16 imm) -> void { diff --git a/ares/n64/cpu/ipu.cpp b/ares/n64/cpu/ipu.cpp index da8fefd237..8fc5c05052 100644 --- a/ares/n64/cpu/ipu.cpp +++ b/ares/n64/cpu/ipu.cpp @@ -290,14 +290,14 @@ auto CPU::instructionLBU(r64& rt, cr64& rs, s16 imm) -> void { } auto CPU::instructionLD(r64& rt, cr64& rs, s16 imm) -> void { - if(auto data = readDouble(rs.u32 + imm)) rt.u64 = *data; + if(auto data = readDual(rs.u32 + imm)) rt.u64 = *data; } auto CPU::instructionLDL(r64& rt, cr64& rs, s16 imm) -> void { auto address = rs.u32 + imm; auto shift = 8 * ((address ^ FlipLE) & 7); auto mask = u64(0) - 1 << shift; - if(auto data = readDouble(address & ~7)) { + if(auto data = readDual(address & ~7)) { rt.u64 = rt.u64 & ~mask | *data << shift; } } @@ -306,7 +306,7 @@ auto CPU::instructionLDR(r64& rt, cr64& rs, s16 imm) -> void { auto address = rs.u32 + imm; auto shift = 8 * ((address ^ FlipBE) & 7); auto mask = u64(0) - 1 >> shift; - if(auto data = readDouble(address & ~7)) { + if(auto data = readDual(address & ~7)) { rt.u64 = rt.u64 & ~mask | *data >> shift; } } @@ -328,7 +328,7 @@ auto CPU::instructionLL(r64& rt, cr64& rs, s16 imm) -> void { } auto CPU::instructionLLD(r64& rt, cr64& rs, s16 imm) -> void { - if(auto data = readDouble(rs.u32 + imm)) { + if(auto data = readDual(rs.u32 + imm)) { rt.u64 = *data; scc.ll = tlb.physicalAddress >> 4; scc.llbit = 1; @@ -421,22 +421,22 @@ auto CPU::instructionSC(r64& rt, cr64& rs, s16 imm) -> void { auto CPU::instructionSCD(r64& rt, cr64& rs, s16 imm) -> void { if(scc.llbit) { scc.llbit = 0; - rt.u64 = writeDouble(rs.u32 + imm, rt.u64); + rt.u64 = writeDual(rs.u32 + imm, rt.u64); } else { rt.u64 = 0; } } auto CPU::instructionSD(cr64& rt, cr64& rs, s16 imm) -> void { - writeDouble(rs.u32 + imm, rt.u64); + writeDual(rs.u32 + imm, rt.u64); } auto CPU::instructionSDL(cr64& rt, cr64& rs, s16 imm) -> void { auto address = rs.u32 + imm; auto shift = 8 * ((address ^ FlipLE) & 7); auto mask = u64(0) - 1 >> shift; - if(auto data = readDouble(address & ~7)) { - writeDouble(address & ~7, *data & ~mask | rt.u64 >> shift); + if(auto data = readDual(address & ~7)) { + writeDual(address & ~7, *data & ~mask | rt.u64 >> shift); } } @@ -444,8 +444,8 @@ auto CPU::instructionSDR(cr64& rt, cr64& rs, s16 imm) -> void { auto address = rs.u32 + imm; auto shift = 8 * ((address ^ FlipBE) & 7); auto mask = u64(0) - 1 << shift; - if(auto data = readDouble(address & ~7)) { - writeDouble(address & ~7, *data & ~mask | rt.u64 << shift); + if(auto data = readDual(address & ~7)) { + writeDual(address & ~7, *data & ~mask | rt.u64 << shift); } } diff --git a/ares/n64/cpu/memory.cpp b/ares/n64/cpu/memory.cpp index 5d2a50387e..1acd456921 100644 --- a/ares/n64/cpu/memory.cpp +++ b/ares/n64/cpu/memory.cpp @@ -51,11 +51,11 @@ auto CPU::readWord(u32 address) -> maybe { return nothing; } -auto CPU::readDouble(u32 address) -> maybe { +auto CPU::readDual(u32 address) -> maybe { if constexpr(Accuracy::CPU::AddressErrors) { if(unlikely(address & 7)) return exception.addressLoad(), nothing; } - if(auto physical = readAddress(address)) return bus.readDouble(physical()); + if(auto physical = readAddress(address)) return bus.readDual(physical()); return nothing; } @@ -80,10 +80,10 @@ auto CPU::writeWord(u32 address, u32 data) -> bool { return false; } -auto CPU::writeDouble(u32 address, u64 data) -> bool { +auto CPU::writeDual(u32 address, u64 data) -> bool { if constexpr(Accuracy::CPU::AddressErrors) { if(unlikely(address & 7)) return exception.addressStore(), false; } - if(auto physical = writeAddress(address)) return bus.writeDouble(physical(), data), true; + if(auto physical = writeAddress(address)) return bus.writeDual(physical(), data), true; return false; } diff --git a/ares/n64/cpu/scc.cpp b/ares/n64/cpu/scc.cpp index 299c9643f0..596afb2221 100644 --- a/ares/n64/cpu/scc.cpp +++ b/ares/n64/cpu/scc.cpp @@ -1,5 +1,5 @@ -auto CPU::getControlRegister(uint5 index) -> u64 { - uint64 data; +auto CPU::getControlRegister(n5 index) -> u64 { + n64 data; switch(index) { case 0: //index data.bit( 0, 5) = scc.index.tlbEntry; @@ -124,7 +124,7 @@ auto CPU::getControlRegister(uint5 index) -> u64 { return data; } -auto CPU::setControlRegister(uint5 index, uint64 data) -> void { +auto CPU::setControlRegister(n5 index, n64 data) -> void { //read-only variables are defined but commented out for documentation purposes switch(index) { case 0: //index @@ -288,7 +288,7 @@ auto CPU::instructionMTC0(cr64& rt, u8 rd) -> void { auto CPU::instructionTLBP() -> void { scc.index.tlbEntry = 0; //technically undefined scc.index.probeFailure = 1; - for(uint index : range(TLB::Entries)) { + for(u32 index : range(TLB::Entries)) { auto& entry = tlb.entry[index]; auto mask = ~entry.pageMask & ~0x1fff; if((entry.virtualAddress & mask) != (scc.tlb.virtualAddress & mask)) continue; diff --git a/ares/n64/dd/io.cpp b/ares/n64/dd/io.cpp index c84a943444..b2eef29889 100644 --- a/ares/n64/dd/io.cpp +++ b/ares/n64/dd/io.cpp @@ -1,5 +1,5 @@ auto DD::readWord(u32 address) -> u32 { - uint32 data; + n32 data; return data; } diff --git a/ares/n64/memory/bus.hpp b/ares/n64/memory/bus.hpp index 5b4d1a8f3d..3c04670d1e 100644 --- a/ares/n64/memory/bus.hpp +++ b/ares/n64/memory/bus.hpp @@ -48,9 +48,9 @@ inline auto Bus::readWord(u32 address) -> u32 { decode(0, readWord, address); } -inline auto Bus::readDouble(u32 address) -> u64 { +inline auto Bus::readDual(u32 address) -> u64 { address &= 0x1fff'fff8; - decode(0, readDouble, address); + decode(0, readDual, address); } #undef unmapped @@ -74,11 +74,11 @@ inline auto Bus::writeWord(u32 address, u32 data) -> void { decode(1, writeWord, address, data); } -inline auto Bus::writeDouble(u32 address, u64 data) -> void { +inline auto Bus::writeDual(u32 address, u64 data) -> void { address &= 0x1fff'fff8; cpu.recompiler.invalidate(address + 0); cpu.recompiler.invalidate(address + 4); - decode(2, writeDouble, address, data); + decode(2, writeDual, address, data); } #undef unmapped diff --git a/ares/n64/memory/io.hpp b/ares/n64/memory/io.hpp index 7e42438850..745c1efcf5 100644 --- a/ares/n64/memory/io.hpp +++ b/ares/n64/memory/io.hpp @@ -18,7 +18,7 @@ struct IO { } unreachable; } - auto readDouble(u32 address) -> u64 { + auto readDual(u32 address) -> u64 { u64 data = ((T*)this)->readWord(address); return data << 32 | ((T*)this)->readWord(address + 4); } @@ -39,7 +39,7 @@ struct IO { } unreachable; } - auto writeDouble(u32 address, u64 data) -> void { + auto writeDual(u32 address, u64 data) -> void { ((T*)this)->writeWord(address + 0, data >> 32); ((T*)this)->writeWord(address + 4, data >> 0); } diff --git a/ares/n64/memory/lsb-readable.hpp b/ares/n64/memory/lsb-readable.hpp new file mode 100644 index 0000000000..ae849b53f3 --- /dev/null +++ b/ares/n64/memory/lsb-readable.hpp @@ -0,0 +1,104 @@ +struct Readable { + auto reset() -> void { + delete[] data; + data = nullptr; + size = 0; + maskByte = 0; + maskHalf = 0; + maskWord = 0; + maskDual = 0; + maskQuad = 0; + } + + auto allocate(u32 capacity, u32 fillWith = ~0) -> void { + reset(); + size = capacity & ~15; + u32 mask = bit::round(size) - 1; + maskByte = mask & ~0; + maskHalf = mask & ~1; + maskWord = mask & ~3; + maskDual = mask & ~7; + maskQuad = mask & ~15; + data = new u8[mask + 1]; + fill(fillWith); + } + + auto fill(u32 value = 0) -> void { + for(u32 address = 0; address < size; address += 4) { + *(u32*)&data[address & maskWord] = value; + } + } + + auto load(Shared::File fp) -> void { + for(u32 address = 0; address < min(size, fp->size()); address += 4) { + *(u32*)&data[address & maskWord] = fp->readm(4L); + } + } + + auto save(Shared::File fp) -> void { + for(u32 address = 0; address < size; address += 4) { + fp->writem(*(u32*)&data[address & maskWord], 4L); + } + } + + //N64 CPU requires aligned memory accesses + auto readByte(u32 address) -> u8 { return *(u8* )&data[address & maskByte ^ 3]; } + auto readHalf(u32 address) -> u16 { return *(u16*)&data[address & maskHalf ^ 2]; } + auto readWord(u32 address) -> u32 { return *(u32*)&data[address & maskWord ^ 0]; } + auto readDual(u32 address) -> u64 { + u64 upper = readWord(address + 0); + u64 lower = readWord(address + 4); + return upper << 32 | lower << 0; + } + auto readQuad(u32 address) -> u128 { + u128 upper = readDual(address + 0); + u128 lower = readDual(address + 8); + return upper << 64 | lower << 0; + } + + auto writeByte(u32 address, u8 value) -> void {} + auto writeHalf(u32 address, u16 value) -> void {} + auto writeWord(u32 address, u32 value) -> void {} + auto writeDual(u32 address, u64 value) -> void {} + auto writeQuad(u32 address, u128 value) -> void {} + + //N64 RSP allows unaligned memory accesses in certain cases + auto readHalfUnaligned(u32 address) -> u16 { + u16 upper = readByte(address + 0); + u16 lower = readByte(address + 1); + return upper << 8 | lower << 0; + } + auto readWordUnaligned(u32 address) -> u32 { + u32 upper = readHalfUnaligned(address + 0); + u32 lower = readHalfUnaligned(address + 2); + return upper << 16 | lower << 0; + } + auto readDualUnaligned(u32 address) -> u64 { + u64 upper = readWordUnaligned(address + 0); + u64 lower = readWordUnaligned(address + 4); + return upper << 32 | lower << 0; + } + auto readQuadUnaligned(u32 address) -> u128 { + u128 upper = readDualUnaligned(address + 0); + u128 lower = readDualUnaligned(address + 8); + return upper << 64 | lower << 0; + } + + auto writeHalfUnaligned(u32 address, u16 value) -> void {} + auto writeWordUnaligned(u32 address, u32 value) -> void {} + auto writeDualUnaligned(u32 address, u64 value) -> void {} + auto writeQuadUnaligned(u32 address, u128 value) -> void {} + + auto serialize(serializer& s) -> void { + s(array_span{data, size}); + } + +//private: + u8* data = nullptr; + u32 size = 0; + u32 maskByte = 0; + u32 maskHalf = 0; + u32 maskWord = 0; + u32 maskDual = 0; + u32 maskQuad = 0; +}; diff --git a/ares/n64/memory/lsb-writable.hpp b/ares/n64/memory/lsb-writable.hpp new file mode 100644 index 0000000000..452c895728 --- /dev/null +++ b/ares/n64/memory/lsb-writable.hpp @@ -0,0 +1,122 @@ +struct Writable { + auto reset() -> void { + delete[] data; + data = nullptr; + size = 0; + maskByte = 0; + maskHalf = 0; + maskWord = 0; + maskDual = 0; + maskQuad = 0; + } + + auto allocate(u32 capacity, u32 fillWith = ~0) -> void { + reset(); + size = capacity & ~15; + u32 mask = bit::round(size) - 1; + maskByte = mask & ~0; + maskHalf = mask & ~1; + maskWord = mask & ~3; + maskDual = mask & ~7; + maskQuad = mask & ~15; + data = new u8[mask + 1]; + fill(fillWith); + } + + auto fill(u32 value = 0) -> void { + for(u32 address = 0; address < size; address += 4) { + *(u32*)&data[address & maskWord] = value; + } + } + + auto load(Shared::File fp) -> void { + for(u32 address = 0; address < min(size, fp->size()); address += 4) { + *(u32*)&data[address & maskWord] = fp->readm(4L); + } + } + + auto save(Shared::File fp) -> void { + for(u32 address = 0; address < size; address += 4) { + fp->writem(*(u32*)&data[address & maskWord], 4L); + } + } + + //N64 CPU requires aligned memory accesses + auto readByte(u32 address) -> u8 { return *(u8* )&data[address & maskByte ^ 3]; } + auto readHalf(u32 address) -> u16 { return *(u16*)&data[address & maskHalf ^ 2]; } + auto readWord(u32 address) -> u32 { return *(u32*)&data[address & maskWord ^ 0]; } + auto readDual(u32 address) -> u64 { + u64 upper = readWord(address + 0); + u64 lower = readWord(address + 4); + return upper << 32 | lower << 0; + } + auto readQuad(u32 address) -> u128 { + u128 upper = readDual(address + 0); + u128 lower = readDual(address + 8); + return upper << 64 | lower << 0; + } + + auto writeByte(u32 address, u8 value) -> void { *(u8* )&data[address & maskByte ^ 3] = value; } + auto writeHalf(u32 address, u16 value) -> void { *(u16*)&data[address & maskHalf ^ 2] = value; } + auto writeWord(u32 address, u32 value) -> void { *(u32*)&data[address & maskWord ^ 0] = value; } + auto writeDual(u32 address, u64 value) -> void { + writeWord(address + 0, value >> 32); + writeWord(address + 4, value >> 0); + } + auto writeQuad(u32 address, u128 value) -> void { + writeDual(address + 0, value >> 64); + writeDual(address + 8, value >> 0); + } + + //N64 RSP allows unaligned memory accesses in certain cases + auto readHalfUnaligned(u32 address) -> u16 { + u16 upper = readByte(address + 0); + u16 lower = readByte(address + 1); + return upper << 8 | lower << 0; + } + auto readWordUnaligned(u32 address) -> u32 { + u32 upper = readHalfUnaligned(address + 0); + u32 lower = readHalfUnaligned(address + 2); + return upper << 16 | lower << 0; + } + auto readDualUnaligned(u32 address) -> u64 { + u64 upper = readWordUnaligned(address + 0); + u64 lower = readWordUnaligned(address + 4); + return upper << 32 | lower << 0; + } + auto readQuadUnaligned(u32 address) -> u128 { + u128 upper = readDualUnaligned(address + 0); + u128 lower = readDualUnaligned(address + 8); + return upper << 64 | lower << 0; + } + + auto writeHalfUnaligned(u32 address, u16 value) -> void { + writeByte(address + 0, value >> 8); + writeByte(address + 1, value >> 0); + } + auto writeWordUnaligned(u32 address, u32 value) -> void { + writeHalfUnaligned(address + 0, value >> 16); + writeHalfUnaligned(address + 2, value >> 0); + } + auto writeDualUnaligned(u32 address, u64 value) -> void { + writeWordUnaligned(address + 0, value >> 32); + writeWordUnaligned(address + 4, value >> 0); + } + auto writeQuadUnaligned(u32 address, u128 value) -> void { + writeDualUnaligned(address + 0, value >> 64); + writeDualUnaligned(address + 8, value >> 0); + } + + auto serialize(serializer& s) -> void { + s(array_span{data, size}); + } + +//private: + u8* data = nullptr; + u32 size = 0; + u32 maskByte = 0; + u32 maskHalf = 0; + u32 maskWord = 0; + u32 maskDual = 0; + u32 maskQuad = 0; +}; diff --git a/ares/n64/memory/memory.hpp b/ares/n64/memory/memory.hpp index f90008162a..33a9b0cb2c 100644 --- a/ares/n64/memory/memory.hpp +++ b/ares/n64/memory/memory.hpp @@ -1,6 +1,6 @@ namespace Memory { - #include "readable.hpp" - #include "writable.hpp" + #include "lsb-readable.hpp" + #include "lsb-writable.hpp" #include "io.hpp" } @@ -9,11 +9,11 @@ struct Bus { auto readByte(u32 address) -> u8; auto readHalf(u32 address) -> u16; auto readWord(u32 address) -> u32; - auto readDouble(u32 address) -> u64; - auto writeByte(u32 address, u8 data) -> void; + auto readDual(u32 address) -> u64; + auto writeByte(u32 address, u8 data) -> void; auto writeHalf(u32 address, u16 data) -> void; auto writeWord(u32 address, u32 data) -> void; - auto writeDouble(u32 address, u64 data) -> void; + auto writeDual(u32 address, u64 data) -> void; }; extern Bus bus; diff --git a/ares/n64/memory/readable.hpp b/ares/n64/memory/msb-readable.hpp similarity index 52% rename from ares/n64/memory/readable.hpp rename to ares/n64/memory/msb-readable.hpp index 8476c52c95..1150292f0a 100644 --- a/ares/n64/memory/readable.hpp +++ b/ares/n64/memory/msb-readable.hpp @@ -6,19 +6,19 @@ struct Readable { maskByte = 0; maskHalf = 0; maskWord = 0; - maskDouble = 0; + maskDual = 0; maskQuad = 0; } auto allocate(u32 capacity, u32 fillWith = ~0) -> void { reset(); - size = capacity & ~7; - u32 mask = bit::round(size) - 1; - maskByte = mask & ~0; - maskHalf = mask & ~1; - maskWord = mask & ~3; - maskDouble = mask & ~7; - maskQuad = mask & ~15; + size = capacity & ~15; + u32 mask = bit::round(size) - 1; + maskByte = mask & ~0; + maskHalf = mask & ~1; + maskWord = mask & ~3; + maskDual = mask & ~7; + maskQuad = mask & ~15; data = new u8[mask + 1]; fill(fillWith); } @@ -42,27 +42,27 @@ struct Readable { } //N64 CPU requires aligned memory accesses - auto readByte(u32 address) -> u8 { return *(u8*)&data[address & maskByte]; } - auto readHalf(u32 address) -> u16 { return bswap16(*(u16*)&data[address & maskHalf]); } - auto readWord(u32 address) -> u32 { return bswap32(*(u32*)&data[address & maskWord]); } - auto readDouble(u32 address) -> u64 { return bswap64(*(u64*)&data[address & maskDouble]); } + auto readByte(u32 address) -> u8 { return (*(u8* )&data[address & maskByte]); } + auto readHalf(u32 address) -> u16 { return bswap16 (*(u16* )&data[address & maskHalf]); } + auto readWord(u32 address) -> u32 { return bswap32 (*(u32* )&data[address & maskWord]); } + auto readDual(u32 address) -> u64 { return bswap64 (*(u64* )&data[address & maskDual]); } auto readQuad(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskQuad]); } - auto writeByte(u32 address, u8 value) -> void {} - auto writeHalf(u32 address, u16 value) -> void {} - auto writeWord(u32 address, u32 value) -> void {} - auto writeDouble(u32 address, u64 value) -> void {} + auto writeByte(u32 address, u8 value) -> void {} + auto writeHalf(u32 address, u16 value) -> void {} + auto writeWord(u32 address, u32 value) -> void {} + auto writeDual(u32 address, u64 value) -> void {} auto writeQuad(u32 address, u128 value) -> void {} //N64 RSP allows unaligned memory accesses in certain cases - auto readHalfUnaligned(u32 address) -> u16 { return bswap16(*(u16*)&data[address & maskByte]); } - auto readWordUnaligned(u32 address) -> u32 { return bswap32(*(u32*)&data[address & maskByte]); } - auto readDoubleUnaligned(u32 address) -> u64 { return bswap64(*(u64*)&data[address & maskByte]); } + auto readHalfUnaligned(u32 address) -> u16 { return bswap16 (*(u16* )&data[address & maskByte]); } + auto readWordUnaligned(u32 address) -> u32 { return bswap32 (*(u32* )&data[address & maskByte]); } + auto readDualUnaligned(u32 address) -> u64 { return bswap64 (*(u64* )&data[address & maskByte]); } auto readQuadUnaligned(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskByte]); } - auto writeHalfUnaligned(u32 address, u16 value) -> void {} - auto writeWordUnaligned(u32 address, u32 value) -> void {} - auto writeDoubleUnaligned(u32 address, u64 value) -> void {} + auto writeHalfUnaligned(u32 address, u16 value) -> void {} + auto writeWordUnaligned(u32 address, u32 value) -> void {} + auto writeDualUnaligned(u32 address, u64 value) -> void {} auto writeQuadUnaligned(u32 address, u128 value) -> void {} auto serialize(serializer& s) -> void { @@ -75,6 +75,6 @@ struct Readable { u32 maskByte = 0; u32 maskHalf = 0; u32 maskWord = 0; - u32 maskDouble = 0; + u32 maskDual = 0; u32 maskQuad = 0; }; diff --git a/ares/n64/memory/msb-writable.hpp b/ares/n64/memory/msb-writable.hpp new file mode 100644 index 0000000000..4327e77422 --- /dev/null +++ b/ares/n64/memory/msb-writable.hpp @@ -0,0 +1,80 @@ +struct Writable { + auto reset() -> void { + delete[] data; + data = nullptr; + size = 0; + maskByte = 0; + maskHalf = 0; + maskWord = 0; + maskDual = 0; + maskQuad = 0; + } + + auto allocate(u32 capacity, u32 fillWith = ~0) -> void { + reset(); + size = capacity & ~15; + u32 mask = bit::round(size) - 1; + maskByte = mask & ~0; + maskHalf = mask & ~1; + maskWord = mask & ~3; + maskDual = mask & ~7; + maskQuad = mask & ~15; + data = new u8[mask + 1]; + fill(fillWith); + } + + auto fill(u32 value = 0) -> void { + for(u32 address = 0; address < size; address += 4) { + *(u32*)&data[address & maskWord] = bswap32(value); + } + } + + auto load(Shared::File fp) -> void { + for(u32 address = 0; address < min(size, fp->size()); address += 4) { + *(u32*)&data[address & maskWord] = bswap32(fp->readm(4L)); + } + } + + auto save(Shared::File fp) -> void { + for(u32 address = 0; address < size; address += 4) { + fp->writem(bswap32(*(u32*)&data[address & maskWord]), 4L); + } + } + + //N64 CPU requires aligned memory accesses + auto readByte(u32 address) -> u8 { return (*(u8* )&data[address & maskByte]); } + auto readHalf(u32 address) -> u16 { return bswap16 (*(u16* )&data[address & maskHalf]); } + auto readWord(u32 address) -> u32 { return bswap32 (*(u32* )&data[address & maskWord]); } + auto readDual(u32 address) -> u64 { return bswap64 (*(u64* )&data[address & maskDual]); } + auto readQuad(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskQuad]); } + + auto writeByte(u32 address, u8 value) -> void { *(u8* )&data[address & maskByte] = (value); } + auto writeHalf(u32 address, u16 value) -> void { *(u16* )&data[address & maskHalf] = bswap16 (value); } + auto writeWord(u32 address, u32 value) -> void { *(u32* )&data[address & maskWord] = bswap32 (value); } + auto writeDual(u32 address, u64 value) -> void { *(u64* )&data[address & maskDual] = bswap64 (value); } + auto writeQuad(u32 address, u128 value) -> void { *(u128*)&data[address & maskQuad] = bswap128(value); } + + //N64 RSP allows unaligned memory accesses in certain cases + auto readHalfUnaligned(u32 address) -> u16 { return bswap16 (*(u16* )&data[address & maskByte]); } + auto readWordUnaligned(u32 address) -> u32 { return bswap32 (*(u32* )&data[address & maskByte]); } + auto readDualUnaligned(u32 address) -> u64 { return bswap64 (*(u64* )&data[address & maskByte]); } + auto readQuadUnaligned(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskByte]); } + + auto writeHalfUnaligned(u32 address, u16 value) -> void { *(u16* )&data[address & maskByte] = bswap16 (value); } + auto writeWordUnaligned(u32 address, u32 value) -> void { *(u32* )&data[address & maskByte] = bswap32 (value); } + auto writeDualUnaligned(u32 address, u64 value) -> void { *(u64* )&data[address & maskByte] = bswap64 (value); } + auto writeQuadUnaligned(u32 address, u128 value) -> void { *(u128*)&data[address & maskByte] = bswap128(value); } + + auto serialize(serializer& s) -> void { + s(array_span{data, size}); + } + +//private: + u8* data = nullptr; + u32 size = 0; + u32 maskByte = 0; + u32 maskHalf = 0; + u32 maskWord = 0; + u32 maskDual = 0; + u32 maskQuad = 0; +}; diff --git a/ares/n64/memory/writable.hpp b/ares/n64/memory/writable.hpp deleted file mode 100644 index faff915b05..0000000000 --- a/ares/n64/memory/writable.hpp +++ /dev/null @@ -1,80 +0,0 @@ -struct Writable { - auto reset() -> void { - delete[] data; - data = nullptr; - size = 0; - maskByte = 0; - maskHalf = 0; - maskWord = 0; - maskDouble = 0; - maskQuad = 0; - } - - auto allocate(u32 capacity, u32 fillWith = ~0) -> void { - reset(); - size = capacity & ~7; - u32 mask = bit::round(size) - 1; - maskByte = mask & ~0; - maskHalf = mask & ~1; - maskWord = mask & ~3; - maskDouble = mask & ~7; - maskQuad = mask & ~15; - data = new u8[mask + 1]; - fill(fillWith); - } - - auto fill(u32 value = 0) -> void { - for(u32 address = 0; address < size; address += 4) { - *(u32*)&data[address & maskWord] = bswap32(value); - } - } - - auto load(Shared::File fp) -> void { - for(u32 address = 0; address < min(size, fp->size()); address += 4) { - *(u32*)&data[address & maskWord] = bswap32(fp->readm(4L)); - } - } - - auto save(Shared::File fp) -> void { - for(u32 address = 0; address < size; address += 4) { - fp->writem(bswap32(*(u32*)&data[address & maskWord]), 4L); - } - } - - //N64 CPU requires aligned memory accesses - auto readByte(u32 address) -> u8 { return *(u8*)&data[address & maskByte]; } - auto readHalf(u32 address) -> u16 { return bswap16(*(u16*)&data[address & maskHalf]); } - auto readWord(u32 address) -> u32 { return bswap32(*(u32*)&data[address & maskWord]); } - auto readDouble(u32 address) -> u64 { return bswap64(*(u64*)&data[address & maskDouble]); } - auto readQuad(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskQuad]); } - - auto writeByte(u32 address, u8 value) -> void { *(u8*)&data[address & maskByte] = value; } - auto writeHalf(u32 address, u16 value) -> void { *(u16*)&data[address & maskHalf] = bswap16(value); } - auto writeWord(u32 address, u32 value) -> void { *(u32*)&data[address & maskWord] = bswap32(value); } - auto writeDouble(u32 address, u64 value) -> void { *(u64*)&data[address & maskDouble] = bswap64(value); } - auto writeQuad(u32 address, u128 value) -> void { *(u128*)&data[address & maskQuad] = bswap128(value); } - - //N64 RSP allows unaligned memory accesses in certain cases - auto readHalfUnaligned(u32 address) -> u16 { return bswap16(*(u16*)&data[address & maskByte]); } - auto readWordUnaligned(u32 address) -> u32 { return bswap32(*(u32*)&data[address & maskByte]); } - auto readDoubleUnaligned(u32 address) -> u64 { return bswap64(*(u64*)&data[address & maskByte]); } - auto readQuadUnaligned(u32 address) -> u128 { return bswap128(*(u128*)&data[address & maskByte]); } - - auto writeHalfUnaligned(u32 address, u16 value) -> void { *(u16*)&data[address & maskByte] = bswap16(value); } - auto writeWordUnaligned(u32 address, u32 value) -> void { *(u32*)&data[address & maskByte] = bswap32(value); } - auto writeDoubleUnaligned(u32 address, u64 value) -> void { *(u64*)&data[address & maskByte] = bswap64(value); } - auto writeQuadUnaligned(u32 address, u128 value) -> void { *(u128*)&data[address & maskByte] = bswap128(value); } - - auto serialize(serializer& s) -> void { - s(array_span{data, size}); - } - -//private: - u8* data = nullptr; - u32 size = 0; - u32 maskByte = 0; - u32 maskHalf = 0; - u32 maskWord = 0; - u32 maskDouble = 0; - u32 maskQuad = 0; -}; diff --git a/ares/n64/mi/io.cpp b/ares/n64/mi/io.cpp index 2622da37c4..d447c19fc8 100644 --- a/ares/n64/mi/io.cpp +++ b/ares/n64/mi/io.cpp @@ -7,7 +7,7 @@ static const vector registerNames = { auto MI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //MI_INIT_MODE @@ -49,7 +49,7 @@ auto MI::readWord(u32 address) -> u32 { auto MI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //MI_INIT_MODE diff --git a/ares/n64/mi/mi.hpp b/ares/n64/mi/mi.hpp index 80edbf67ae..e9e2b9a020 100644 --- a/ares/n64/mi/mi.hpp +++ b/ares/n64/mi/mi.hpp @@ -19,7 +19,7 @@ struct MI : Memory::IO { auto load(Node::Object) -> void; auto unload() -> void; - enum class IRQ : uint { SP, SI, AI, VI, PI, DP }; + enum class IRQ : u32 { SP, SI, AI, VI, PI, DP }; auto raise(IRQ) -> void; auto lower(IRQ) -> void; auto poll() -> void; diff --git a/ares/n64/n64.hpp b/ares/n64/n64.hpp index 3cba237a7f..c93635c392 100644 --- a/ares/n64/n64.hpp +++ b/ares/n64/n64.hpp @@ -8,6 +8,7 @@ using v128 = __m128i; namespace ares::Nintendo64 { + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Region { diff --git a/ares/n64/pi/io.cpp b/ares/n64/pi/io.cpp index db20fff615..f426b40dc7 100644 --- a/ares/n64/pi/io.cpp +++ b/ares/n64/pi/io.cpp @@ -16,7 +16,7 @@ static const vector registerNames = { auto PI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //PI_DRAM_ADDRESS @@ -94,7 +94,7 @@ auto PI::readWord(u32 address) -> u32 { auto PI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; //only PI_STATUS can be written while PI is busy if(address != 4 && (io.dmaBusy || io.ioBusy)) { @@ -104,17 +104,17 @@ auto PI::writeWord(u32 address, u32 data_) -> void { if(address == 0) { //PI_DRAM_ADDRESS - io.dramAddress = uint24(data) & ~7; + io.dramAddress = n24(data) & ~7; } if(address == 1) { //PI_PBUS_ADDRESS - io.pbusAddress = uint29(data) & ~1; + io.pbusAddress = n29(data) & ~1; } if(address == 2) { //PI_READ_LENGTH - io.readLength = (uint24(data) | 7) + 1; + io.readLength = (n24(data) | 7) + 1; for(u32 address = 0; address < io.readLength; address += 2) { u16 data = bus.readHalf(io.dramAddress + address); bus.writeHalf(io.pbusAddress + address, data); @@ -125,7 +125,7 @@ auto PI::writeWord(u32 address, u32 data_) -> void { if(address == 3) { //PI_WRITE_LENGTH - io.writeLength = (uint24(data) | 7) + 1; + io.writeLength = (n24(data) | 7) + 1; for(u32 address = 0; address < io.writeLength; address += 2) { u16 data = bus.readHalf(io.pbusAddress + address); bus.writeHalf(io.dramAddress + address, data); diff --git a/ares/n64/pi/pi.hpp b/ares/n64/pi/pi.hpp index deddd30b30..a440b48d2a 100644 --- a/ares/n64/pi/pi.hpp +++ b/ares/n64/pi/pi.hpp @@ -32,21 +32,21 @@ struct PI : Memory::IO { auto serialize(serializer&) -> void; struct IO { - uint1 dmaBusy; - uint1 ioBusy; - uint1 error; - uint1 interrupt; - uint32 dramAddress; - uint32 pbusAddress; - uint32 readLength; - uint32 writeLength; + n1 dmaBusy; + n1 ioBusy; + n1 error; + n1 interrupt; + n32 dramAddress; + n32 pbusAddress; + n32 readLength; + n32 writeLength; } io; struct BSD { - uint8 latency; - uint8 pulseWidth; - uint8 pageSize; - uint8 releaseDuration; + n8 latency; + n8 pulseWidth; + n8 pageSize; + n8 releaseDuration; } bsd1, bsd2; }; diff --git a/ares/n64/rdp/io.cpp b/ares/n64/rdp/io.cpp index bbfabe2d2d..0abaef8110 100644 --- a/ares/n64/rdp/io.cpp +++ b/ares/n64/rdp/io.cpp @@ -11,7 +11,7 @@ static const vector registerNamesSCC = { auto RDP::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //DPC_START @@ -71,7 +71,7 @@ auto RDP::readWord(u32 address) -> u32 { auto RDP::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //DPC_START @@ -138,7 +138,7 @@ static const vector registerNamesIO = { auto RDP::IO::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //DPS_TBIST @@ -171,7 +171,7 @@ auto RDP::IO::readWord(u32 address) -> u32 { auto RDP::IO::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //DPS_TBIST diff --git a/ares/n64/rdp/rdp.cpp b/ares/n64/rdp/rdp.cpp index b215f7a62e..65cc269cd7 100644 --- a/ares/n64/rdp/rdp.cpp +++ b/ares/n64/rdp/rdp.cpp @@ -22,7 +22,7 @@ auto RDP::main() -> void { step(93'750'000); } -auto RDP::step(uint clocks) -> void { +auto RDP::step(u32 clocks) -> void { clock += clocks; } diff --git a/ares/n64/rdp/rdp.hpp b/ares/n64/rdp/rdp.hpp index 751bd8224e..805cc788bd 100644 --- a/ares/n64/rdp/rdp.hpp +++ b/ares/n64/rdp/rdp.hpp @@ -20,7 +20,7 @@ struct RDP : Thread, Memory::IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //render.cpp @@ -71,32 +71,32 @@ struct RDP : Thread, Memory::IO { auto serialize(serializer&) -> void; struct Command { - uint24 start; - uint24 end; - uint24 current; - uint24 clock; - uint24 bufferBusy; - uint24 pipeBusy; - uint24 tmemBusy; - uint1 source; //0 = RDRAM, 1 = DMEM - uint1 freeze; - uint1 flush; - uint1 ready; + n24 start; + n24 end; + n24 current; + n24 clock; + n24 bufferBusy; + n24 pipeBusy; + n24 tmemBusy; + n1 source; //0 = RDRAM, 1 = DMEM + n1 freeze; + n1 flush; + n1 ready; } command; struct Point { - uint16 i; //integer - uint16 f; //fraction + n16 i; //integer + n16 f; //fraction }; struct Edge { - uint1 lmajor; - uint3 level; - uint3 tile; + n1 lmajor; + n3 level; + n3 tile; struct Y { - uint14 hi; - uint14 md; - uint14 lo; + n14 hi; + n14 md; + n14 lo; } y; struct X { struct { @@ -132,197 +132,197 @@ struct RDP : Thread, Memory::IO { } zbuffer; struct TextureRectangle { - uint3 tile; + n3 tile; struct { - uint12 hi; - uint12 lo; + n12 hi; + n12 lo; } x, y; Point s; Point t; } rectangle; struct OtherModes { - uint1 atomicPrimitive; - uint1 reserved1; - uint2 cycleType; - uint1 perspective; - uint1 detailTexture; - uint1 sharpenTexture; - uint1 lodTexture; - uint1 tlut; - uint1 tlutType; - uint1 sampleType; - uint1 midTexel; - uint1 bilerp[2]; - uint1 convertOne; - uint1 colorKey; - uint2 colorDitherMode; - uint2 alphaDitherMode; - uint4 reserved2; - uint2 blend1a[2]; - uint2 blend1b[2]; - uint2 blend2a[2]; - uint2 blend2b[2]; - uint1 reserved3; - uint1 forceBlend; - uint1 alphaCoverage; - uint1 coverageXalpha; - uint2 zMode; - uint2 coverageMode; - uint1 colorOnCoverage; - uint1 imageRead; - uint1 zUpdate; - uint1 zCompare; - uint1 antialias; - uint1 zSource; - uint1 ditherAlpha; - uint1 alphaCompare; + n1 atomicPrimitive; + n1 reserved1; + n2 cycleType; + n1 perspective; + n1 detailTexture; + n1 sharpenTexture; + n1 lodTexture; + n1 tlut; + n1 tlutType; + n1 sampleType; + n1 midTexel; + n1 bilerp[2]; + n1 convertOne; + n1 colorKey; + n2 colorDitherMode; + n2 alphaDitherMode; + n4 reserved2; + n2 blend1a[2]; + n2 blend1b[2]; + n2 blend2a[2]; + n2 blend2b[2]; + n1 reserved3; + n1 forceBlend; + n1 alphaCoverage; + n1 coverageXalpha; + n2 zMode; + n2 coverageMode; + n1 colorOnCoverage; + n1 imageRead; + n1 zUpdate; + n1 zCompare; + n1 antialias; + n1 zSource; + n1 ditherAlpha; + n1 alphaCompare; } other; struct FogColor { - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; + n8 red; + n8 green; + n8 blue; + n8 alpha; } fog; struct Blend { - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; + n8 red; + n8 green; + n8 blue; + n8 alpha; } blend; struct PrimitiveColor { - uint5 minimum; - uint8 fraction; - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; + n5 minimum; + n8 fraction; + n8 red; + n8 green; + n8 blue; + n8 alpha; } primitive; struct EnvironmentColor { - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; + n8 red; + n8 green; + n8 blue; + n8 alpha; } environment; struct CombineMode { struct MUL { - uint5 color[2]; - uint3 alpha[2]; + n5 color[2]; + n3 alpha[2]; } mul; struct ADD { - uint3 color[2]; - uint3 alpha[2]; + n3 color[2]; + n3 alpha[2]; } add; struct SUB { - uint4 color[2]; - uint3 alpha[2]; + n4 color[2]; + n3 alpha[2]; } sba, sbb; } combine; struct TLUT { - uint3 index; + n3 index; struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } s, t; } tlut; struct Load { struct Block { - uint3 index; + n3 index; struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } s, t; } block; struct Tile { - uint3 index; + n3 index; struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } s, t; } tile; } load_; struct TileSize { - uint3 index; + n3 index; struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } s, t; } tileSize; struct Tile { - uint3 format; - uint2 size; - uint9 line; - uint9 address; - uint3 index; - uint4 palette; + n3 format; + n2 size; + n9 line; + n9 address; + n3 index; + n4 palette; struct { - uint1 clamp; - uint1 mirror; - uint4 mask; - uint4 shift; + n1 clamp; + n1 mirror; + n4 mask; + n4 shift; } s, t; } tile; struct Set { struct Fill { - uint32 color = 0; + n32 color = 0; } fill; struct Texture { - uint3 format = 0; - uint2 size = 0; - uint10 width = 0; - uint26 dramAddress = 0; + n3 format = 0; + n2 size = 0; + n10 width = 0; + n26 dramAddress = 0; } texture; struct Mask { - uint26 dramAddress = 0; + n26 dramAddress = 0; } mask; struct Color { - uint3 format = 0; - uint2 size = 0; - uint10 width = 0; - uint26 dramAddress = 0; + n3 format = 0; + n2 size = 0; + n10 width = 0; + n26 dramAddress = 0; } color; } set; struct PrimitiveDepth { - uint16 z; - uint16 deltaZ; + n16 z; + n16 deltaZ; } primitiveDepth; struct Scissor { - uint1 field; - uint1 odd; + n1 field; + n1 odd; struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } x, y; } scissor; struct Convert { - uint9 k[6]; + n9 k[6]; } convert; struct Key { struct { - uint12 width; - uint8 center; - uint8 scale; + n12 width; + n8 center; + n8 scale; } r, g, b; } key; struct FillRectangle { struct { - uint12 lo; - uint12 hi; + n12 lo; + n12 hi; } x, y; } fillRectangle_; @@ -335,15 +335,15 @@ struct RDP : Thread, Memory::IO { auto writeWord(u32 address, u32 data) -> void; struct BIST { - uint1 check; - uint1 go; - uint1 done; - uint8 fail; + n1 check; + n1 go; + n1 done; + n8 fail; } bist; struct Test { - uint1 enable; - uint7 address; - uint32 data; + n1 enable; + n7 address; + n32 data; } test; } io{*this}; }; diff --git a/ares/n64/rdp/render.cpp b/ares/n64/rdp/render.cpp index 05c4af5b8b..b8d3c288e5 100644 --- a/ares/n64/rdp/render.cpp +++ b/ares/n64/rdp/render.cpp @@ -48,137 +48,137 @@ auto RDP::render() -> void { auto& memory = !command.source ? rdram.ram : rsp.dmem; auto fetch = [&]() -> u64 { - u64 op = memory.readDoubleUnaligned(command.current); + u64 op = memory.readDualUnaligned(command.current); command.current += 8; return op; }; auto fetchEdge = [&](u64 op) { - edge.lmajor = uint1(op >> 55); - edge.level = uint3(op >> 51); - edge.tile = uint3(op >> 48); - edge.y.lo = uint14(op >> 32); - edge.y.md = uint14(op >> 16); - edge.y.hi = uint14(op >> 0); + edge.lmajor = n1 (op >> 55); + edge.level = n3 (op >> 51); + edge.tile = n3 (op >> 48); + edge.y.lo = n14(op >> 32); + edge.y.md = n14(op >> 16); + edge.y.hi = n14(op >> 0); op = fetch(); - edge.x.lo.c.i = uint16(op >> 48); - edge.x.lo.c.f = uint16(op >> 32); - edge.x.lo.s.i = uint16(op >> 16); - edge.x.lo.s.f = uint16(op >> 0); + edge.x.lo.c.i = n16(op >> 48); + edge.x.lo.c.f = n16(op >> 32); + edge.x.lo.s.i = n16(op >> 16); + edge.x.lo.s.f = n16(op >> 0); op = fetch(); - edge.x.hi.c.i = uint16(op >> 48); - edge.x.hi.c.f = uint16(op >> 32); - edge.x.hi.s.i = uint16(op >> 16); - edge.x.hi.s.f = uint16(op >> 0); + edge.x.hi.c.i = n16(op >> 48); + edge.x.hi.c.f = n16(op >> 32); + edge.x.hi.s.i = n16(op >> 16); + edge.x.hi.s.f = n16(op >> 0); op = fetch(); - edge.x.md.c.i = uint16(op >> 48); - edge.x.md.c.f = uint16(op >> 32); - edge.x.md.s.i = uint16(op >> 16); - edge.x.md.s.f = uint16(op >> 0); + edge.x.md.c.i = n16(op >> 48); + edge.x.md.c.f = n16(op >> 32); + edge.x.md.s.i = n16(op >> 16); + edge.x.md.s.f = n16(op >> 0); }; auto fetchShade = [&](u64 op) { op = fetch(); - shade.r.c.i = uint16(op >> 48); - shade.g.c.i = uint16(op >> 32); - shade.b.c.i = uint16(op >> 16); - shade.a.c.i = uint16(op >> 0); + shade.r.c.i = n16(op >> 48); + shade.g.c.i = n16(op >> 32); + shade.b.c.i = n16(op >> 16); + shade.a.c.i = n16(op >> 0); op = fetch(); - shade.r.x.i = uint16(op >> 48); - shade.g.x.i = uint16(op >> 32); - shade.b.x.i = uint16(op >> 16); - shade.a.x.i = uint16(op >> 0); + shade.r.x.i = n16(op >> 48); + shade.g.x.i = n16(op >> 32); + shade.b.x.i = n16(op >> 16); + shade.a.x.i = n16(op >> 0); op = fetch(); - shade.r.c.f = uint16(op >> 48); - shade.g.c.f = uint16(op >> 32); - shade.b.c.f = uint16(op >> 16); - shade.a.c.f = uint16(op >> 0); + shade.r.c.f = n16(op >> 48); + shade.g.c.f = n16(op >> 32); + shade.b.c.f = n16(op >> 16); + shade.a.c.f = n16(op >> 0); op = fetch(); - shade.r.x.f = uint16(op >> 48); - shade.g.x.f = uint16(op >> 32); - shade.b.x.f = uint16(op >> 16); - shade.a.x.f = uint16(op >> 0); + shade.r.x.f = n16(op >> 48); + shade.g.x.f = n16(op >> 32); + shade.b.x.f = n16(op >> 16); + shade.a.x.f = n16(op >> 0); op = fetch(); - shade.r.e.i = uint16(op >> 48); - shade.g.e.i = uint16(op >> 32); - shade.b.e.i = uint16(op >> 16); - shade.a.e.i = uint16(op >> 0); + shade.r.e.i = n16(op >> 48); + shade.g.e.i = n16(op >> 32); + shade.b.e.i = n16(op >> 16); + shade.a.e.i = n16(op >> 0); op = fetch(); - shade.r.y.i = uint16(op >> 48); - shade.g.y.i = uint16(op >> 32); - shade.b.y.i = uint16(op >> 16); - shade.a.y.i = uint16(op >> 0); + shade.r.y.i = n16(op >> 48); + shade.g.y.i = n16(op >> 32); + shade.b.y.i = n16(op >> 16); + shade.a.y.i = n16(op >> 0); op = fetch(); - shade.r.e.f = uint16(op >> 48); - shade.g.e.f = uint16(op >> 32); - shade.b.e.f = uint16(op >> 16); - shade.a.e.f = uint16(op >> 0); + shade.r.e.f = n16(op >> 48); + shade.g.e.f = n16(op >> 32); + shade.b.e.f = n16(op >> 16); + shade.a.e.f = n16(op >> 0); op = fetch(); - shade.r.y.f = uint16(op >> 48); - shade.g.y.f = uint16(op >> 32); - shade.b.y.f = uint16(op >> 16); - shade.a.y.f = uint16(op >> 0); + shade.r.y.f = n16(op >> 48); + shade.g.y.f = n16(op >> 32); + shade.b.y.f = n16(op >> 16); + shade.a.y.f = n16(op >> 0); }; auto fetchTexture = [&](u64 op) { op = fetch(); - texture.s.c.i = uint16(op >> 48); - texture.t.c.i = uint16(op >> 32); - texture.w.c.i = uint16(op >> 16); + texture.s.c.i = n16(op >> 48); + texture.t.c.i = n16(op >> 32); + texture.w.c.i = n16(op >> 16); op = fetch(); - texture.s.x.i = uint16(op >> 48); - texture.t.x.i = uint16(op >> 32); - texture.w.x.i = uint16(op >> 16); + texture.s.x.i = n16(op >> 48); + texture.t.x.i = n16(op >> 32); + texture.w.x.i = n16(op >> 16); op = fetch(); - texture.s.c.f = uint16(op >> 48); - texture.t.c.f = uint16(op >> 32); - texture.w.c.f = uint16(op >> 16); + texture.s.c.f = n16(op >> 48); + texture.t.c.f = n16(op >> 32); + texture.w.c.f = n16(op >> 16); op = fetch(); - texture.s.x.f = uint16(op >> 48); - texture.t.x.f = uint16(op >> 32); - texture.w.x.f = uint16(op >> 16); + texture.s.x.f = n16(op >> 48); + texture.t.x.f = n16(op >> 32); + texture.w.x.f = n16(op >> 16); op = fetch(); - texture.s.e.i = uint16(op >> 48); - texture.t.e.i = uint16(op >> 32); - texture.w.e.i = uint16(op >> 16); + texture.s.e.i = n16(op >> 48); + texture.t.e.i = n16(op >> 32); + texture.w.e.i = n16(op >> 16); op = fetch(); - texture.s.y.i = uint16(op >> 48); - texture.t.y.i = uint16(op >> 32); - texture.w.y.i = uint16(op >> 16); + texture.s.y.i = n16(op >> 48); + texture.t.y.i = n16(op >> 32); + texture.w.y.i = n16(op >> 16); op = fetch(); - texture.s.e.f = uint16(op >> 48); - texture.t.e.f = uint16(op >> 32); - texture.w.e.f = uint16(op >> 16); + texture.s.e.f = n16(op >> 48); + texture.t.e.f = n16(op >> 32); + texture.w.e.f = n16(op >> 16); op = fetch(); - texture.s.y.f = uint16(op >> 48); - texture.t.y.f = uint16(op >> 32); - texture.w.y.f = uint16(op >> 16); + texture.s.y.f = n16(op >> 48); + texture.t.y.f = n16(op >> 32); + texture.w.y.f = n16(op >> 16); }; auto fetchZBuffer = [&](u64 op) { op = fetch(); - zbuffer.d.i = uint16(op >> 48); - zbuffer.d.f = uint16(op >> 32); - zbuffer.x.i = uint16(op >> 16); - zbuffer.x.f = uint16(op >> 0); + zbuffer.d.i = n16(op >> 48); + zbuffer.d.f = n16(op >> 32); + zbuffer.x.i = n16(op >> 16); + zbuffer.x.f = n16(op >> 0); op = fetch(); - zbuffer.e.i = uint16(op >> 48); - zbuffer.e.f = uint16(op >> 32); - zbuffer.y.i = uint16(op >> 16); - zbuffer.y.f = uint16(op >> 0); + zbuffer.e.i = n16(op >> 48); + zbuffer.e.f = n16(op >> 32); + zbuffer.y.i = n16(op >> 16); + zbuffer.y.f = n16(op >> 0); }; auto fetchRectangle = [&](u64 op) { - rectangle.x.lo = uint12(op >> 44); - rectangle.y.lo = uint12(op >> 32); - rectangle.tile = uint3(op >> 24); - rectangle.x.hi = uint12(op >> 12); - rectangle.y.hi = uint12(op >> 0); + rectangle.x.lo = n12(op >> 44); + rectangle.y.lo = n12(op >> 32); + rectangle.tile = n3 (op >> 24); + rectangle.x.hi = n12(op >> 12); + rectangle.y.hi = n12(op >> 0); op = fetch(); - rectangle.s.i = uint16(op >> 48); - rectangle.t.i = uint16(op >> 32); - rectangle.s.f = uint16(op >> 16); - rectangle.t.f = uint16(op >> 0); + rectangle.s.i = n16(op >> 48); + rectangle.t.i = n16(op >> 32); + rectangle.s.f = n16(op >> 16); + rectangle.t.f = n16(op >> 0); }; while(command.current < command.end) { @@ -306,98 +306,98 @@ auto RDP::render() -> void { } break; case 0x2a: { - key.g.width = uint12(op >> 44); - key.b.width = uint12(op >> 32); - key.g.center = uint8(op >> 24); - key.g.scale = uint8(op >> 16); - key.b.center = uint8(op >> 8); - key.b.scale = uint8(op >> 0); + key.g.width = n12(op >> 44); + key.b.width = n12(op >> 32); + key.g.center = n8 (op >> 24); + key.g.scale = n8 (op >> 16); + key.b.center = n8 (op >> 8); + key.b.scale = n8 (op >> 0); setKeyGB(); } break; case 0x2b: { - key.r.width = uint12(op >> 16); - key.r.center = uint8(op >> 8); - key.r.scale = uint8(op >> 0); + key.r.width = n12(op >> 16); + key.r.center = n8 (op >> 8); + key.r.scale = n8 (op >> 0); setKeyR(); } break; case 0x2c: { - convert.k[0] = uint9(op >> 45); - convert.k[1] = uint9(op >> 36); - convert.k[2] = uint9(op >> 27); - convert.k[3] = uint9(op >> 18); - convert.k[4] = uint9(op >> 9); - convert.k[5] = uint8(op >> 0); + convert.k[0] = n9(op >> 45); + convert.k[1] = n9(op >> 36); + convert.k[2] = n9(op >> 27); + convert.k[3] = n9(op >> 18); + convert.k[4] = n9(op >> 9); + convert.k[5] = n8(op >> 0); setConvert(); } break; case 0x2d: { - scissor.x.hi = uint12(op >> 44); - scissor.y.hi = uint12(op >> 32); - scissor.field = uint1(op >> 25); - scissor.odd = uint1(op >> 24); - scissor.x.lo = uint12(op >> 12); - scissor.y.lo = uint12(op >> 0); + scissor.x.hi = n12(op >> 44); + scissor.y.hi = n12(op >> 32); + scissor.field = n1 (op >> 25); + scissor.odd = n1 (op >> 24); + scissor.x.lo = n12(op >> 12); + scissor.y.lo = n12(op >> 0); setScissor(); } break; case 0x2e: { - primitiveDepth.z = uint16(op >> 16); - primitiveDepth.deltaZ = uint16(op >> 0); + primitiveDepth.z = n16(op >> 16); + primitiveDepth.deltaZ = n16(op >> 0); setPrimitiveDepth(); } break; case 0x2f: { - other.atomicPrimitive = uint1(op >> 55); - other.reserved1 = uint1(op >> 54); - other.cycleType = uint2(op >> 52); - other.perspective = uint1(op >> 51); - other.detailTexture = uint1(op >> 50); - other.sharpenTexture = uint1(op >> 49); - other.lodTexture = uint1(op >> 48); - other.tlut = uint1(op >> 47); - other.tlutType = uint1(op >> 46); - other.sampleType = uint1(op >> 45); - other.midTexel = uint1(op >> 44); - other.bilerp[0] = uint1(op >> 43); - other.bilerp[1] = uint1(op >> 42); - other.convertOne = uint1(op >> 41); - other.colorKey = uint1(op >> 40); - other.colorDitherMode = uint2(op >> 38); - other.alphaDitherMode = uint2(op >> 36); - other.reserved2 = uint4(op >> 32); - other.blend1a[0] = uint2(op >> 30); - other.blend1a[1] = uint2(op >> 28); - other.blend1b[0] = uint2(op >> 26); - other.blend1b[1] = uint2(op >> 24); - other.blend2a[0] = uint2(op >> 22); - other.blend2a[1] = uint2(op >> 20); - other.blend2b[0] = uint2(op >> 18); - other.blend2b[1] = uint2(op >> 16); - other.reserved3 = uint1(op >> 15); - other.forceBlend = uint1(op >> 14); - other.alphaCoverage = uint1(op >> 13); - other.coverageXalpha = uint1(op >> 12); - other.zMode = uint2(op >> 10); - other.coverageMode = uint2(op >> 8); - other.colorOnCoverage = uint1(op >> 7); - other.imageRead = uint1(op >> 6); - other.zUpdate = uint1(op >> 5); - other.zCompare = uint1(op >> 4); - other.antialias = uint1(op >> 3); - other.zSource = uint1(op >> 2); - other.ditherAlpha = uint1(op >> 1); - other.alphaCompare = uint1(op >> 0); + other.atomicPrimitive = n1(op >> 55); + other.reserved1 = n1(op >> 54); + other.cycleType = n2(op >> 52); + other.perspective = n1(op >> 51); + other.detailTexture = n1(op >> 50); + other.sharpenTexture = n1(op >> 49); + other.lodTexture = n1(op >> 48); + other.tlut = n1(op >> 47); + other.tlutType = n1(op >> 46); + other.sampleType = n1(op >> 45); + other.midTexel = n1(op >> 44); + other.bilerp[0] = n1(op >> 43); + other.bilerp[1] = n1(op >> 42); + other.convertOne = n1(op >> 41); + other.colorKey = n1(op >> 40); + other.colorDitherMode = n2(op >> 38); + other.alphaDitherMode = n2(op >> 36); + other.reserved2 = n4(op >> 32); + other.blend1a[0] = n2(op >> 30); + other.blend1a[1] = n2(op >> 28); + other.blend1b[0] = n2(op >> 26); + other.blend1b[1] = n2(op >> 24); + other.blend2a[0] = n2(op >> 22); + other.blend2a[1] = n2(op >> 20); + other.blend2b[0] = n2(op >> 18); + other.blend2b[1] = n2(op >> 16); + other.reserved3 = n1(op >> 15); + other.forceBlend = n1(op >> 14); + other.alphaCoverage = n1(op >> 13); + other.coverageXalpha = n1(op >> 12); + other.zMode = n2(op >> 10); + other.coverageMode = n2(op >> 8); + other.colorOnCoverage = n1(op >> 7); + other.imageRead = n1(op >> 6); + other.zUpdate = n1(op >> 5); + other.zCompare = n1(op >> 4); + other.antialias = n1(op >> 3); + other.zSource = n1(op >> 2); + other.ditherAlpha = n1(op >> 1); + other.alphaCompare = n1(op >> 0); setOtherModes(); } break; case 0x30: { - tlut.s.lo = uint12(op >> 44); - tlut.t.lo = uint12(op >> 32); - tlut.index = uint3(op >> 24); - tlut.s.hi = uint12(op >> 12); - tlut.t.hi = uint12(op >> 0); + tlut.s.lo = n12(op >> 44); + tlut.t.lo = n12(op >> 32); + tlut.index = n3 (op >> 24); + tlut.s.hi = n12(op >> 12); + tlut.t.hi = n12(op >> 0); loadTLUT(); } break; @@ -406,135 +406,135 @@ auto RDP::render() -> void { } break; case 0x32: { - tileSize.s.lo = uint12(op >> 44); - tileSize.t.lo = uint12(op >> 32); - tileSize.index = uint3(op >> 24); - tileSize.s.hi = uint12(op >> 12); - tileSize.t.hi = uint12(op >> 0); + tileSize.s.lo = n12(op >> 44); + tileSize.t.lo = n12(op >> 32); + tileSize.index = n3 (op >> 24); + tileSize.s.hi = n12(op >> 12); + tileSize.t.hi = n12(op >> 0); setTileSize(); } break; case 0x33: { - load_.block.s.lo = uint12(op >> 44); - load_.block.t.lo = uint12(op >> 32); - load_.block.index = uint3(op >> 24); - load_.block.s.hi = uint12(op >> 12); - load_.block.t.hi = uint12(op >> 0); + load_.block.s.lo = n12(op >> 44); + load_.block.t.lo = n12(op >> 32); + load_.block.index = n3 (op >> 24); + load_.block.s.hi = n12(op >> 12); + load_.block.t.hi = n12(op >> 0); loadBlock(); } break; case 0x34: { - load_.tile.s.lo = uint12(op >> 44); - load_.tile.t.lo = uint12(op >> 32); - load_.tile.index = uint3(op >> 24); - load_.tile.s.hi = uint12(op >> 12); - load_.tile.t.hi = uint12(op >> 0); + load_.tile.s.lo = n12(op >> 44); + load_.tile.t.lo = n12(op >> 32); + load_.tile.index = n3 (op >> 24); + load_.tile.s.hi = n12(op >> 12); + load_.tile.t.hi = n12(op >> 0); loadTile(); } break; case 0x35: { - tile.format = uint3(op >> 53); - tile.size = uint2(op >> 51); - tile.line = uint9(op >> 41); - tile.address = uint9(op >> 32); - tile.index = uint3(op >> 24); - tile.palette = uint4(op >> 20); - tile.t.clamp = uint1(op >> 19); - tile.t.mirror = uint1(op >> 18); - tile.t.mask = uint4(op >> 14); - tile.t.shift = uint4(op >> 10); - tile.s.clamp = uint1(op >> 9); - tile.s.mirror = uint1(op >> 8); - tile.s.mask = uint4(op >> 4); - tile.s.shift = uint4(op >> 0); + tile.format = n3(op >> 53); + tile.size = n2(op >> 51); + tile.line = n9(op >> 41); + tile.address = n9(op >> 32); + tile.index = n3(op >> 24); + tile.palette = n4(op >> 20); + tile.t.clamp = n1(op >> 19); + tile.t.mirror = n1(op >> 18); + tile.t.mask = n4(op >> 14); + tile.t.shift = n4(op >> 10); + tile.s.clamp = n1(op >> 9); + tile.s.mirror = n1(op >> 8); + tile.s.mask = n4(op >> 4); + tile.s.shift = n4(op >> 0); setTile(); } break; case 0x36: { - fillRectangle_.x.lo = uint12(op >> 44); - fillRectangle_.y.lo = uint12(op >> 32); - fillRectangle_.x.hi = uint12(op >> 12); - fillRectangle_.y.hi = uint12(op >> 0); + fillRectangle_.x.lo = n12(op >> 44); + fillRectangle_.y.lo = n12(op >> 32); + fillRectangle_.x.hi = n12(op >> 12); + fillRectangle_.y.hi = n12(op >> 0); fillRectangle(); } break; case 0x37: { - set.fill.color = uint32(op >> 0); + set.fill.color = n32(op >> 0); setFillColor(); } break; case 0x38: { - fog.red = uint8(op >> 24); - fog.green = uint8(op >> 16); - fog.blue = uint8(op >> 8); - fog.alpha = uint8(op >> 0); + fog.red = n8(op >> 24); + fog.green = n8(op >> 16); + fog.blue = n8(op >> 8); + fog.alpha = n8(op >> 0); setFogColor(); } break; case 0x39: { - blend.red = uint8(op >> 24); - blend.green = uint8(op >> 16); - blend.blue = uint8(op >> 8); - blend.alpha = uint8(op >> 0); + blend.red = n8(op >> 24); + blend.green = n8(op >> 16); + blend.blue = n8(op >> 8); + blend.alpha = n8(op >> 0); setBlendColor(); } break; case 0x3a: { - primitive.minimum = uint4(op >> 40); - primitive.fraction = uint8(op >> 32); - primitive.red = uint8(op >> 24); - primitive.green = uint8(op >> 16); - primitive.blue = uint8(op >> 8); - primitive.alpha = uint8(op >> 0); + primitive.minimum = n4(op >> 40); + primitive.fraction = n8(op >> 32); + primitive.red = n8(op >> 24); + primitive.green = n8(op >> 16); + primitive.blue = n8(op >> 8); + primitive.alpha = n8(op >> 0); setPrimitiveColor(); } break; case 0x3b: { - environment.red = uint8(op >> 24); - environment.green = uint8(op >> 16); - environment.blue = uint8(op >> 8); - environment.alpha = uint8(op >> 0); + environment.red = n8(op >> 24); + environment.green = n8(op >> 16); + environment.blue = n8(op >> 8); + environment.alpha = n8(op >> 0); setEnvironmentColor(); } break; case 0x3c: { - combine.sba.color[0] = uint4(op >> 52); - combine.mul.color[0] = uint5(op >> 47); - combine.sba.alpha[0] = uint3(op >> 44); - combine.mul.alpha[0] = uint3(op >> 41); - combine.sba.color[1] = uint4(op >> 37); - combine.mul.color[1] = uint5(op >> 32); - combine.sbb.color[0] = uint4(op >> 28); - combine.sbb.color[1] = uint4(op >> 24); - combine.sba.alpha[1] = uint3(op >> 21); - combine.mul.alpha[1] = uint3(op >> 18); - combine.add.color[0] = uint3(op >> 15); - combine.sbb.alpha[0] = uint3(op >> 12); - combine.add.alpha[0] = uint3(op >> 9); - combine.add.color[1] = uint3(op >> 6); - combine.sbb.alpha[1] = uint3(op >> 3); - combine.add.alpha[1] = uint3(op >> 0); + combine.sba.color[0] = n4(op >> 52); + combine.mul.color[0] = n5(op >> 47); + combine.sba.alpha[0] = n3(op >> 44); + combine.mul.alpha[0] = n3(op >> 41); + combine.sba.color[1] = n4(op >> 37); + combine.mul.color[1] = n5(op >> 32); + combine.sbb.color[0] = n4(op >> 28); + combine.sbb.color[1] = n4(op >> 24); + combine.sba.alpha[1] = n3(op >> 21); + combine.mul.alpha[1] = n3(op >> 18); + combine.add.color[0] = n3(op >> 15); + combine.sbb.alpha[0] = n3(op >> 12); + combine.add.alpha[0] = n3(op >> 9); + combine.add.color[1] = n3(op >> 6); + combine.sbb.alpha[1] = n3(op >> 3); + combine.add.alpha[1] = n3(op >> 0); setCombineMode(); } break; case 0x3d: { - set.texture.format = uint3(op >> 53); - set.texture.size = uint2(op >> 51); - set.texture.width = uint10(op >> 32); - set.texture.dramAddress = uint26(op >> 0); + set.texture.format = n3 (op >> 53); + set.texture.size = n2 (op >> 51); + set.texture.width = n10(op >> 32); + set.texture.dramAddress = n26(op >> 0); setTextureImage(); } break; case 0x3e: { - set.mask.dramAddress = uint26(op >> 0); + set.mask.dramAddress = n26(op >> 0); setMaskImage(); } break; case 0x3f: { - set.color.format = uint3(op >> 53); - set.color.size = uint2(op >> 51); - set.color.width = uint10(op >> 32); - set.color.dramAddress = uint26(op >> 0); + set.color.format = n3 (op >> 53); + set.color.size = n2 (op >> 51); + set.color.width = n10(op >> 32); + set.color.dramAddress = n26(op >> 0); setColorImage(); } break; diff --git a/ares/n64/ri/io.cpp b/ares/n64/ri/io.cpp index 5951ebfaa2..84f019e9bd 100644 --- a/ares/n64/ri/io.cpp +++ b/ares/n64/ri/io.cpp @@ -11,7 +11,7 @@ static const vector registerNames = { auto RI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data = 0; + n32 data = 0; if(address == 0) { //RI_MODE @@ -53,7 +53,7 @@ auto RI::readWord(u32 address) -> u32 { auto RI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //RI_MODE diff --git a/ares/n64/rsp/decoder.hpp b/ares/n64/rsp/decoder.hpp index da31a232cd..9c46fca8bf 100644 --- a/ares/n64/rsp/decoder.hpp +++ b/ares/n64/rsp/decoder.hpp @@ -319,7 +319,7 @@ #ifdef DECODER_LWC2 { #define E (OP >> 7 & 15) - #define IMMi7 int7(OP) + #define IMMi7 i7(OP) switch(OP >> 11 & 0x1f) { op(0x00, LBV, VT, E, RS, IMMi7); op(0x01, LSV, VT, E, RS, IMMi7); @@ -343,7 +343,7 @@ #ifdef DECODER_SWC2 { #define E (OP >> 7 & 15) - #define IMMi7 int7(OP) + #define IMMi7 i7(OP) switch(OP >> 11 & 0x1f) { op(0x00, SBV, VT, E, RS, IMMi7); op(0x01, SSV, VT, E, RS, IMMi7); diff --git a/ares/n64/rsp/disassembler.cpp b/ares/n64/rsp/disassembler.cpp index 30acfc432b..577d22a921 100644 --- a/ares/n64/rsp/disassembler.cpp +++ b/ares/n64/rsp/disassembler.cpp @@ -15,8 +15,8 @@ auto RSP::Disassembler::EXECUTE() -> vector { auto rsValue = [&] { return ipuRegisterValue(instruction >> 21 & 31); }; auto imm16i = [&] { return immediate(s16(instruction)); }; auto imm16u = [&] { return immediate(u16(instruction), 16L); }; - auto jump = [&] { return immediate(uint12(address + 4 & 0xf000'0000 | (instruction & 0x03ff'ffff) << 2)); }; - auto branch = [&] { return immediate(uint12(address + 4 + (s16(instruction) << 2))); }; + auto jump = [&] { return immediate(n12(address + 4 & 0xf000'0000 | (instruction & 0x03ff'ffff) << 2)); }; + auto branch = [&] { return immediate(n12(address + 4 + (s16(instruction) << 2))); }; auto offset = [&] { return ipuRegisterIndex(instruction >> 21 & 31, s16(instruction)); }; auto ADDI = [&](string_view add, string_view sub, string_view mov) -> vector { @@ -234,7 +234,7 @@ auto RSP::Disassembler::SPECIAL() -> vector { auto RSP::Disassembler::REGIMM() -> vector { auto rsValue = [&] { return ipuRegisterValue(instruction >> 21 & 31); }; - auto branch = [&] { return immediate(uint12(address + 4 + (s16(instruction) << 2))); }; + auto branch = [&] { return immediate(n12(address + 4 + (s16(instruction) << 2))); }; auto BRANCH = [&](string_view name) -> vector { return {name, rsValue(), branch()}; @@ -295,7 +295,7 @@ auto RSP::Disassembler::SCC() -> vector { auto RSP::Disassembler::LWC2() -> vector { auto vtName = [&] { return vpuRegisterName (instruction >> 16 & 31, instruction >> 7 & 15); }; auto vtValue = [&] { return vpuRegisterValue (instruction >> 16 & 31, instruction >> 7 & 15); }; - auto offset = [&](uint multiplier) { return ipuRegisterIndex(instruction >> 21 & 31, int7(instruction) * multiplier); }; + auto offset = [&](u32 multiplier) { return ipuRegisterIndex(instruction >> 21 & 31, i7(instruction) * multiplier); }; switch(instruction >> 11 & 31) { case 0x00: return {"lbv", vtName(), offset( 1)}; @@ -317,7 +317,7 @@ auto RSP::Disassembler::LWC2() -> vector { auto RSP::Disassembler::SWC2() -> vector { auto vtName = [&] { return vpuRegisterName (instruction >> 16 & 31); }; auto vtValue = [&] { return vpuRegisterValue (instruction >> 16 & 31); }; - auto offset = [&](uint multiplier) { return ipuRegisterIndex(instruction >> 21 & 31, int7(instruction) * multiplier); }; + auto offset = [&](u32 multiplier) { return ipuRegisterIndex(instruction >> 21 & 31, i7(instruction) * multiplier); }; switch(instruction >> 11 & 31) { case 0x00: return {"sbv", vtValue(), offset( 1)}; @@ -451,12 +451,12 @@ auto RSP::Disassembler::VU() -> vector { return {}; } -auto RSP::Disassembler::immediate(s64 value, uint bits) const -> string { +auto RSP::Disassembler::immediate(s64 value, u32 bits) const -> string { if(value < 0) return {"-$", hex(-value, bits >> 2)}; return {"$", hex(value, bits >> 2)}; }; -auto RSP::Disassembler::ipuRegisterName(uint index) const -> string { +auto RSP::Disassembler::ipuRegisterName(u32 index) const -> string { static const string registers[32] = { "0", "at", "v0", "v1", "a0", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", @@ -466,12 +466,12 @@ auto RSP::Disassembler::ipuRegisterName(uint index) const -> string { return registers[index]; } -auto RSP::Disassembler::ipuRegisterValue(uint index) const -> string { +auto RSP::Disassembler::ipuRegisterValue(u32 index) const -> string { if(index && showValues) return {ipuRegisterName(index), hint("{$", hex(self.ipu.r[index].u32, 8L), "}")}; return ipuRegisterName(index); } -auto RSP::Disassembler::ipuRegisterIndex(uint index, s16 offset) const -> string { +auto RSP::Disassembler::ipuRegisterIndex(u32 index, s16 offset) const -> string { string adjust; if(offset >= 0) adjust = {"+$", hex( offset)}; if(offset < 0) adjust = {"-$", hex(-offset)}; @@ -479,7 +479,7 @@ auto RSP::Disassembler::ipuRegisterIndex(uint index, s16 offset) const -> string return {ipuRegisterName(index), adjust}; } -auto RSP::Disassembler::sccRegisterName(uint index) const -> string { +auto RSP::Disassembler::sccRegisterName(u32 index) const -> string { static const string registers[32] = { "SP_PBUS_ADDRESS", "SP_DRAM_ADDRESS", "SP_READ_LENGTH", "SP_WRITE_LENGTH", "SP_STATUS", "SP_DMA_FULL", "SP_DMA_BUSY", "SP_SEMAPHORE", @@ -489,7 +489,7 @@ auto RSP::Disassembler::sccRegisterName(uint index) const -> string { return registers[index & 15]; } -auto RSP::Disassembler::sccRegisterValue(uint index) const -> string { +auto RSP::Disassembler::sccRegisterValue(u32 index) const -> string { u32 value = 0; if(index <= 6) value = rsp.readWord((index & 7) << 2); if(index == 7) value = self.status.semaphore; //rsp.readSCC(7) has side-effects @@ -498,27 +498,27 @@ auto RSP::Disassembler::sccRegisterValue(uint index) const -> string { return sccRegisterName(index); } -auto RSP::Disassembler::vpuRegisterName(uint index, uint element) const -> string { +auto RSP::Disassembler::vpuRegisterName(u32 index, u32 element) const -> string { if(element) return {"v", index, "[", element, "]"}; return {"v", index}; } -auto RSP::Disassembler::vpuRegisterValue(uint index, uint element) const -> string { +auto RSP::Disassembler::vpuRegisterValue(u32 index, u32 element) const -> string { if(showValues) { vector elements; - for(uint index : range(8)) elements.append(hex(self.vpu.r[index].element(index), 4L)); + for(u32 index : range(8)) elements.append(hex(self.vpu.r[index].element(index), 4L)); return {vpuRegisterName(index, element), hint("{$", elements.merge("|"), "}")}; } return vpuRegisterName(index, element); } -auto RSP::Disassembler::ccrRegisterName(uint index) const -> string { +auto RSP::Disassembler::ccrRegisterName(u32 index) const -> string { static const string registers[32] = {"vco", "vcc", "vce"}; if(index < 3) return registers[index]; return {"vc", index}; } -auto RSP::Disassembler::ccrRegisterValue(uint index) const -> string { +auto RSP::Disassembler::ccrRegisterValue(u32 index) const -> string { if(showValues) return {ccrRegisterName(index)}; //todo return ccrRegisterName(index); } diff --git a/ares/n64/rsp/io.cpp b/ares/n64/rsp/io.cpp index bb07ef3533..254d2ce8b4 100644 --- a/ares/n64/rsp/io.cpp +++ b/ares/n64/rsp/io.cpp @@ -11,7 +11,7 @@ static const vector registerNamesSCC = { auto RSP::readWord(u32 address) -> u32 { address = (address & 0x3ffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //SP_PBUS_ADDRESS @@ -81,7 +81,7 @@ auto RSP::readWord(u32 address) -> u32 { auto RSP::writeWord(u32 address, u32 data_) -> void { address = (address & 0x3ffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //SP_PBUS_ADDRESS @@ -184,7 +184,7 @@ static const vector registerNamesIO = { auto RSP::Status::readWord(u32 address) -> u32 { address = (address & 0x7ffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //SP_PC_REG @@ -203,7 +203,7 @@ auto RSP::Status::readWord(u32 address) -> u32 { auto RSP::Status::writeWord(u32 address, u32 data_) -> void { address = (address & 0x7ffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //SP_PC_REG diff --git a/ares/n64/rsp/recompiler.cpp b/ares/n64/rsp/recompiler.cpp index e74b309f99..37b6207122 100644 --- a/ares/n64/rsp/recompiler.cpp +++ b/ares/n64/rsp/recompiler.cpp @@ -39,7 +39,7 @@ auto RSP::Recompiler::emit(u32 address) -> Block* { bind({block->code, allocator.available()}); bool hasBranched = 0; - uint instructions = 0; + u32 instructions = 0; do { u32 instruction = self.imem.readWord(address); bool branched = emitEXECUTE(instruction); diff --git a/ares/n64/rsp/rsp.cpp b/ares/n64/rsp/rsp.cpp index c6688224f2..bbe3a47444 100644 --- a/ares/n64/rsp/rsp.cpp +++ b/ares/n64/rsp/rsp.cpp @@ -32,7 +32,7 @@ auto RSP::main() -> void { instruction(); } -auto RSP::step(uint clocks) -> void { +auto RSP::step(u32 clocks) -> void { clock += clocks; } @@ -70,7 +70,7 @@ auto RSP::instructionDebug() -> void { pipeline.address = ipu.pc; pipeline.instruction = imem.readWord(pipeline.address); - static uint counter = 0; + static u32 counter = 0; //if(++counter > 100) return; print( disassembler.hint(hex(pipeline.address, 3L)), " ", diff --git a/ares/n64/rsp/rsp.hpp b/ares/n64/rsp/rsp.hpp index 104342990c..2d9d690e1b 100644 --- a/ares/n64/rsp/rsp.hpp +++ b/ares/n64/rsp/rsp.hpp @@ -29,7 +29,7 @@ struct RSP : Thread, Memory::IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto instruction() -> void; auto instructionEpilogue() -> bool; @@ -50,16 +50,16 @@ struct RSP : Thread, Memory::IO { auto serialize(serializer&) -> void; struct DMA { - uint1 memSource; - uint12 memAddress; - uint24 dramAddress; - uint1 busy; - uint1 full; + n1 memSource; + n12 memAddress; + n24 dramAddress; + n1 busy; + n1 full; struct Transfer { - uint12 length; - uint12 skip; - uint8 count; + n12 length; + n12 skip; + n8 count; } read, write; } dma; @@ -71,13 +71,13 @@ struct RSP : Thread, Memory::IO { auto readWord(u32 address) -> u32; auto writeWord(u32 address, u32 data) -> void; - uint1 semaphore; - uint1 halted; - uint1 broken; - uint1 full; - uint1 singleStep; - uint1 interruptOnBreak; - uint1 signal[8]; + n1 semaphore; + n1 halted; + n1 broken; + n1 full; + n1 singleStep; + n1 interruptOnBreak; + n1 signal[8]; } status{*this}; //ipu.cpp @@ -88,7 +88,7 @@ struct RSP : Thread, Memory::IO { using cr32 = const r32; struct IPU { - enum Register : uint { + enum Register : u32 { R0, AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, S0, S1, S2, S3, S4, S5, S6, S7, @@ -169,27 +169,27 @@ struct RSP : Thread, Memory::IO { operator __m128i() const { return v128; } auto operator=(__m128i value) { v128 = value; } - auto byte(uint index) -> uint8_t& { return ((uint8_t*)&u128)[15 - index]; } - auto byte(uint index) const -> uint8_t { return ((uint8_t*)&u128)[15 - index]; } + auto byte(u32 index) -> uint8_t& { return ((uint8_t*)&u128)[15 - index]; } + auto byte(u32 index) const -> uint8_t { return ((uint8_t*)&u128)[15 - index]; } - auto element(uint index) -> uint16_t& { return ((uint16_t*)&u128)[7 - index]; } - auto element(uint index) const -> uint16_t { return ((uint16_t*)&u128)[7 - index]; } + auto element(u32 index) -> uint16_t& { return ((uint16_t*)&u128)[7 - index]; } + auto element(u32 index) const -> uint16_t { return ((uint16_t*)&u128)[7 - index]; } - auto u8(uint index) -> uint8_t& { return ((uint8_t*)&u128)[15 - index]; } - auto u8(uint index) const -> uint8_t { return ((uint8_t*)&u128)[15 - index]; } + auto u8(u32 index) -> uint8_t& { return ((uint8_t*)&u128)[15 - index]; } + auto u8(u32 index) const -> uint8_t { return ((uint8_t*)&u128)[15 - index]; } - auto s16(uint index) -> int16_t& { return ((int16_t*)&u128)[7 - index]; } - auto s16(uint index) const -> int16_t { return ((int16_t*)&u128)[7 - index]; } + auto s16(u32 index) -> int16_t& { return ((int16_t*)&u128)[7 - index]; } + auto s16(u32 index) const -> int16_t { return ((int16_t*)&u128)[7 - index]; } - auto u16(uint index) -> uint16_t& { return ((uint16_t*)&u128)[7 - index]; } - auto u16(uint index) const -> uint16_t { return ((uint16_t*)&u128)[7 - index]; } + auto u16(u32 index) -> uint16_t& { return ((uint16_t*)&u128)[7 - index]; } + auto u16(u32 index) const -> uint16_t { return ((uint16_t*)&u128)[7 - index]; } //VCx registers - auto get(uint index) const -> bool { return u16(index) != 0; } - auto set(uint index, bool value) -> bool { return u16(index) = 0 - value, value; } + auto get(u32 index) const -> bool { return u16(index) != 0; } + auto set(u32 index, bool value) -> bool { return u16(index) = 0 - value, value; } //vu-registers.cpp - auto operator()(uint index) const -> r128; + auto operator()(u32 index) const -> r128; }; using cr128 = const r128; @@ -207,9 +207,9 @@ struct RSP : Thread, Memory::IO { static constexpr r128 zero{0}; static constexpr r128 invert{u128(0) - 1}; - auto accumulatorGet(uint index) const -> u64; - auto accumulatorSet(uint index, u64 value) -> void; - auto accumulatorSaturate(uint index, bool slice, u16 negative, u16 positive) const -> u16; + auto accumulatorGet(u32 index) const -> u64; + auto accumulatorSet(u32 index, u64 value) -> void; + auto accumulatorSaturate(u32 index, bool slice, u16 negative, u16 positive) const -> u16; auto instructionCFC2(r32& rt, u8 rd) -> void; auto instructionCTC2(cr32& rt, u8 rd) -> void; @@ -367,16 +367,16 @@ struct RSP : Thread, Memory::IO { auto LWC2() -> vector; auto SWC2() -> vector; auto VU() -> vector; - auto immediate(s64 value, uint bits = 0) const -> string; - auto ipuRegisterName(uint index) const -> string; - auto ipuRegisterValue(uint index) const -> string; - auto ipuRegisterIndex(uint index, s16 offset) const -> string; - auto sccRegisterName(uint index) const -> string; - auto sccRegisterValue(uint index) const -> string; - auto vpuRegisterName(uint index, uint element = 0) const -> string; - auto vpuRegisterValue(uint index, uint element = 0) const -> string; - auto ccrRegisterName(uint index) const -> string; - auto ccrRegisterValue(uint index) const -> string; + auto immediate(s64 value, u32 bits = 0) const -> string; + auto ipuRegisterName(u32 index) const -> string; + auto ipuRegisterValue(u32 index) const -> string; + auto ipuRegisterIndex(u32 index, s16 offset) const -> string; + auto sccRegisterName(u32 index) const -> string; + auto sccRegisterValue(u32 index) const -> string; + auto vpuRegisterName(u32 index, u32 element = 0) const -> string; + auto vpuRegisterValue(u32 index, u32 element = 0) const -> string; + auto ccrRegisterName(u32 index) const -> string; + auto ccrRegisterValue(u32 index) const -> string; u32 address; u32 instruction; diff --git a/ares/n64/rsp/vpu.cpp b/ares/n64/rsp/vpu.cpp index 79c048dac7..388f825ed7 100644 --- a/ares/n64/rsp/vpu.cpp +++ b/ares/n64/rsp/vpu.cpp @@ -11,7 +11,7 @@ #define DIVOUT vpu.divout #define DIVDP vpu.divdp -auto RSP::r128::operator()(uint index) const -> r128 { +auto RSP::r128::operator()(u32 index) const -> r128 { if constexpr(Accuracy::RSP::SISD) { r128 v{*this}; switch(index) { @@ -23,14 +23,14 @@ auto RSP::r128::operator()(uint index) const -> r128 { case 5: v.u16(0) = v.u16(2) = v.u16(3) = v.u16(1); v.u16(4) = v.u16(6) = v.u16(7) = v.u16(5); break; case 6: v.u16(0) = v.u16(1) = v.u16(3) = v.u16(2); v.u16(4) = v.u16(5) = v.u16(7) = v.u16(6); break; case 7: v.u16(0) = v.u16(1) = v.u16(2) = v.u16(3); v.u16(4) = v.u16(5) = v.u16(6) = v.u16(7); break; - case 8: for(uint n : range(8)) v.u16(n) = v.u16(0); break; - case 9: for(uint n : range(8)) v.u16(n) = v.u16(1); break; - case 10: for(uint n : range(8)) v.u16(n) = v.u16(2); break; - case 11: for(uint n : range(8)) v.u16(n) = v.u16(3); break; - case 12: for(uint n : range(8)) v.u16(n) = v.u16(4); break; - case 13: for(uint n : range(8)) v.u16(n) = v.u16(5); break; - case 14: for(uint n : range(8)) v.u16(n) = v.u16(6); break; - case 15: for(uint n : range(8)) v.u16(n) = v.u16(7); break; + case 8: for(u32 n : range(8)) v.u16(n) = v.u16(0); break; + case 9: for(u32 n : range(8)) v.u16(n) = v.u16(1); break; + case 10: for(u32 n : range(8)) v.u16(n) = v.u16(2); break; + case 11: for(u32 n : range(8)) v.u16(n) = v.u16(3); break; + case 12: for(u32 n : range(8)) v.u16(n) = v.u16(4); break; + case 13: for(u32 n : range(8)) v.u16(n) = v.u16(5); break; + case 14: for(u32 n : range(8)) v.u16(n) = v.u16(6); break; + case 15: for(u32 n : range(8)) v.u16(n) = v.u16(7); break; } return v; } @@ -63,17 +63,17 @@ auto RSP::r128::operator()(uint index) const -> r128 { } } -auto RSP::accumulatorGet(uint index) const -> u64 { +auto RSP::accumulatorGet(u32 index) const -> u64 { return (u64)ACCH.u16(index) << 32 | (u64)ACCM.u16(index) << 16 | (u64)ACCL.u16(index) << 0; } -auto RSP::accumulatorSet(uint index, u64 value) -> void { +auto RSP::accumulatorSet(u32 index, u64 value) -> void { ACCH.u16(index) = value >> 32; ACCM.u16(index) = value >> 16; ACCL.u16(index) = value >> 0; } -auto RSP::accumulatorSaturate(uint index, bool slice, u16 negative, u16 positive) const -> u16 { +auto RSP::accumulatorSaturate(u32 index, bool slice, u16 negative, u16 positive) const -> u16 { if(ACCH.s16(index) < 0) { if(ACCH.u16(index) != 0xffff) return negative; if(ACCM.s16(index) >= 0) return negative; @@ -95,7 +95,7 @@ auto RSP::instructionCFC2(r32& rt, u8 rd) -> void { if constexpr(Accuracy::RSP::SISD) { rt.u32 = 0; - for(uint n : range(8)) { + for(u32 n : range(8)) { rt.u32 |= lo.get(n) << 0 + n; rt.u32 |= hi.get(n) << 8 + n; } @@ -119,7 +119,7 @@ auto RSP::instructionCTC2(cr32& rt, u8 rd) -> void { } if constexpr(Accuracy::RSP::SISD) { - for(uint n : range(8)) { + for(u32 n : range(8)) { lo->set(n, rt.u32 & 1 << 0 + n); hi->set(n, rt.u32 & 1 << 8 + n); } @@ -141,7 +141,7 @@ auto RSP::instructionLDV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; auto start = e; auto end = start + 8; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.byte(offset & 15) = dmem.readByte(address++); } } @@ -150,7 +150,7 @@ auto RSP::instructionLFV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; auto start = e >> 1; auto end = start + 4; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.element(offset & 7) = dmem.readByte(address) << 7; address += 4; } @@ -158,7 +158,7 @@ auto RSP::instructionLFV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto RSP::instructionLHV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; - for(uint offset = 0; offset < 8; offset++) { + for(u32 offset = 0; offset < 8; offset++) { vt.element(offset) = dmem.readByte(address + (16 - e + offset * 2 & 15)) << 7; } } @@ -167,14 +167,14 @@ auto RSP::instructionLLV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 4; auto start = e; auto end = start + 4; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.byte(offset & 15) = dmem.readByte(address++); } } auto RSP::instructionLPV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; - for(uint offset = 0; offset < 8; offset++) { + for(u32 offset = 0; offset < 8; offset++) { vt.element(offset) = dmem.readByte(address + (16 - e + offset & 15)) << 8; } } @@ -183,7 +183,7 @@ auto RSP::instructionLQV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; auto start = e; auto end = 16 - (address & 15); - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.byte(offset & 15) = dmem.readByte(address++); } } @@ -193,7 +193,7 @@ auto RSP::instructionLRV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto index = e; auto start = 16 - ((address & 15) - index); address &= ~15; - for(uint offset = start; offset < 16; offset++) { + for(u32 offset = start; offset < 16; offset++) { vt.byte(offset & 15) = dmem.readByte(address++); } } @@ -202,7 +202,7 @@ auto RSP::instructionLSV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 2; auto start = e; auto end = start + 2; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.byte(offset & 15) = dmem.readByte(address++); } } @@ -212,7 +212,7 @@ auto RSP::instructionLTV(u8 vt, u8 e, cr32& rs, s8 imm) -> void { auto start = vt; auto end = min(32, start + 8); address = (address + 8 & ~15) + (e & 1); - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { auto byte = (8 - (e >> 1) + (offset - start)) << 1; vpu.r[offset].byte(byte + 0 & 15) = dmem.readByte(address++); vpu.r[offset].byte(byte + 1 & 15) = dmem.readByte(address++); @@ -221,7 +221,7 @@ auto RSP::instructionLTV(u8 vt, u8 e, cr32& rs, s8 imm) -> void { auto RSP::instructionLUV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; - for(uint offset = 0; offset < 8; offset++) { + for(u32 offset = 0; offset < 8; offset++) { vt.element(offset) = dmem.readByte(address + (16 - e + offset & 15)) << 7; } } @@ -230,7 +230,7 @@ auto RSP::instructionLWV(r128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; auto start = 16 - e; auto end = e + 16; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { vt.byte(offset & 15) = dmem.readByte(address); address += 4; } @@ -256,7 +256,7 @@ auto RSP::instructionSDV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; auto start = e; auto end = start + 8; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address++, vt.byte(offset & 15)); } } @@ -267,7 +267,7 @@ auto RSP::instructionSFV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto end = start + 4; auto base = address & 15; address &= ~15; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address + (base & 15), vt.element(offset & 7) >> 7); base += 4; } @@ -275,7 +275,7 @@ auto RSP::instructionSFV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto RSP::instructionSHV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; - for(uint offset = 0; offset < 8; offset++) { + for(u32 offset = 0; offset < 8; offset++) { auto byte = e + offset * 2; auto value = vt.byte(byte + 0 & 15) << 1 | vt.byte(byte + 1 & 15) >> 7; dmem.writeByte(address, value); @@ -287,7 +287,7 @@ auto RSP::instructionSLV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 4; auto start = e; auto end = start + 4; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address++, vt.byte(offset & 15)); } } @@ -296,7 +296,7 @@ auto RSP::instructionSPV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; auto start = e; auto end = start + 8; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { if((offset & 15) < 8) { dmem.writeByte(address++, vt.byte((offset & 7) << 1)); } else { @@ -309,7 +309,7 @@ auto RSP::instructionSQV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 16; auto start = e; auto end = start + (16 - (address & 15)); - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address++, vt.byte(offset & 15)); } } @@ -320,7 +320,7 @@ auto RSP::instructionSRV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto end = start + (address & 15); auto base = 16 - (address & 15); address &= ~15; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address++, vt.byte(offset + base & 15)); } } @@ -329,7 +329,7 @@ auto RSP::instructionSSV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 2; auto start = e; auto end = start + 2; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address++, vt.byte(offset & 15)); } } @@ -341,7 +341,7 @@ auto RSP::instructionSTV(u8 vt, u8 e, cr32& rs, s8 imm) -> void { auto element = 8 - (e >> 1); auto base = (address & 15) + (element << 1); address &= ~15; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeHalfUnaligned(address + (base & 15), vpu.r[offset].element(element++ & 7)); base += 2; } @@ -351,7 +351,7 @@ auto RSP::instructionSUV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto address = rs.u32 + imm * 8; auto start = e; auto end = start + 8; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { if((offset & 15) < 8) { dmem.writeByte(address++, vt.element(offset & 7) >> 7); } else { @@ -366,7 +366,7 @@ auto RSP::instructionSWV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto end = start + 16; auto base = address & 15; address &= ~15; - for(uint offset = start; offset < end; offset++) { + for(u32 offset = start; offset < end; offset++) { dmem.writeByte(address + (base++ & 15), vt.byte(offset & 15)); } } @@ -374,7 +374,7 @@ auto RSP::instructionSWV(cr128& vt, u8 e, cr32& rs, s8 imm) -> void { auto RSP::instructionVABS(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { r128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { if(vs.s16(n) < 0) { if(vte.s16(n) == -32768) vte.s16(n) = -32767; ACCL.s16(n) = -vte.s16(n); @@ -401,7 +401,7 @@ auto RSP::instructionVABS(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVADD(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 result = vs.s16(n) + vte.s16(n) + VCOL.get(n); ACCL.s16(n) = result; vd.s16(n) = sclamp<16>(result); @@ -426,7 +426,7 @@ auto RSP::instructionVADD(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVADDC(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { u32 result = vs.u16(n) + vte.u16(n); ACCL.u16(n) = result; VCOL.set(n, result >> 16); @@ -449,7 +449,7 @@ auto RSP::instructionVADDC(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVAND(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { r128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = vs.u16(n) & vte.u16(n); } vd = ACCL; @@ -464,7 +464,7 @@ auto RSP::instructionVAND(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVCH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { if((vs.s16(n) ^ vte.s16(n)) < 0) { s16 result = vs.s16(n) + vte.s16(n); ACCL.s16(n) = (result <= 0 ? -vte.s16(n) : vs.s16(n)); @@ -513,7 +513,7 @@ auto RSP::instructionVCH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVCL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { if(VCOL.get(n)) { if(VCOH.get(n)) { ACCL.u16(n) = VCCL.get(n) ? -vte.u16(n) : vs.u16(n); @@ -570,7 +570,7 @@ auto RSP::instructionVCL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVCR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { if((vs.s16(n) ^ vte.s16(n)) < 0) { VCCH.set(n, vte.s16(n) < 0); ACCL.u16(n) = VCCL.set(n, vs.s16(n) + vte.s16(n) + 1 <= 0) ? ~vte.u16(n) : vs.u16(n); @@ -608,7 +608,7 @@ auto RSP::instructionVCR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVEQ(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = VCCL.set(n, !VCE.get(n) && vs.u16(n) == vte.u16(n)) ? vs.u16(n) : vte.u16(n); } VCCH = zero; //unverified @@ -633,7 +633,7 @@ auto RSP::instructionVEQ(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVGE(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = VCCL.set(n, vs.s16(n) > vte.s16(n) || (vs.s16(n) == vte.s16(n) && (!VCOL.get(n) || VCE.get(n)))) ? vs.u16(n) : vte.u16(n); } VCCH = zero; //unverified @@ -661,7 +661,7 @@ auto RSP::instructionVGE(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVLT(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = VCCL.set(n, vs.s16(n) < vte.s16(n) || (vs.s16(n) == vte.s16(n) && VCOL.get(n) && !VCE.get(n))) ? vs.u16(n) : vte.u16(n); } VCCH = zero; //unverified @@ -690,7 +690,7 @@ template auto RSP::instructionVMACF(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, accumulatorGet(n) + vs.s16(n) * vte.s16(n) * 2); if constexpr(U == 0) { vd.u16(n) = accumulatorSaturate(n, 1, 0x8000, 0x7fff); @@ -741,7 +741,7 @@ auto RSP::instructionVMACF(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { } auto RSP::instructionVMACQ(r128& vd) -> void { - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 product = ACCH.element(n) << 16 | ACCM.element(n) << 0; if(product < 0 && !(product & 1 << 5)) product += 32; else if(product >= 0 && !(product & 1 << 5)) product -= 32; @@ -755,7 +755,7 @@ auto RSP::instructionVMACQ(r128& vd) -> void { auto RSP::instructionVMADH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 result = (accumulatorGet(n) >> 16) + vs.s16(n) * vte.s16(n); ACCH.u16(n) = result >> 16; ACCM.u16(n) = result >> 0; @@ -782,7 +782,7 @@ auto RSP::instructionVMADH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMADL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { u32 r1 = vs.u16(n) * vte.u16(n); u32 r2 = ACCL.u16(n) + (r1 >> 16); u32 r3 = ACCM.u16(n) + (r2 >> 16); @@ -819,7 +819,7 @@ auto RSP::instructionVMADL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMADM(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { u32 r1 = vs.s16(n) * vte.u16(n); u32 r2 = ACCL.u16(n) + u16(r1); u32 r3 = ACCM.u16(n) + (r1 >> 16) + (r2 >> 16); @@ -858,7 +858,7 @@ auto RSP::instructionVMADM(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMADN(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, accumulatorGet(n) + s64(vs.u16(n) * vte.s16(n))); vd.u16(n) = accumulatorSaturate(n, 0, 0x0000, 0xffff); } @@ -909,7 +909,7 @@ auto RSP::instructionVMOV(r128& vd, u8 de, cr128& vt, u8 e) -> void { auto RSP::instructionVMRG(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = VCCL.get(n) ? vs.u16(n) : vte.u16(n); } vd = ACCL; @@ -926,7 +926,7 @@ auto RSP::instructionVMRG(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMUDH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, s64(vs.s16(n) * vte.s16(n)) << 16); vd.u16(n) = accumulatorSaturate(n, 1, 0x8000, 0x7fff); } @@ -946,7 +946,7 @@ auto RSP::instructionVMUDH(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMUDL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, u16(vs.u16(n) * vte.u16(n) >> 16)); } vd = ACCL; @@ -963,7 +963,7 @@ auto RSP::instructionVMUDL(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMUDM(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, s32(vs.s16(n) * vte.u16(n))); } vd = ACCM; @@ -984,7 +984,7 @@ auto RSP::instructionVMUDM(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMUDN(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, s32(vs.u16(n) * vte.s16(n))); } vd = ACCL; @@ -1006,7 +1006,7 @@ template auto RSP::instructionVMULF(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { accumulatorSet(n, vs.s16(n) * vte.s16(n) * 2 + 0x8000); if constexpr(U == 0) { vd.u16(n) = ACCM.u16(n); @@ -1046,7 +1046,7 @@ auto RSP::instructionVMULF(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVMULQ(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 product = (s16)vs.element(n) * (s16)vte.element(n); if(product < 0) product += 31; //round ACCH.element(n) = product >> 16; @@ -1059,7 +1059,7 @@ auto RSP::instructionVMULQ(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVNAND(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = ~(vs.u16(n) & vte.u16(n)); } vd = ACCL; @@ -1075,7 +1075,7 @@ auto RSP::instructionVNAND(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVNE(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = VCCL.set(n, vs.u16(n) != vte.u16(n) || VCE.get(n)) ? vs.u16(n) : vte.u16(n); } VCCH = zero; //unverified @@ -1105,7 +1105,7 @@ auto RSP::instructionVNOP() -> void { auto RSP::instructionVNOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = ~(vs.u16(n) | vte.u16(n)); } vd = ACCL; @@ -1121,7 +1121,7 @@ auto RSP::instructionVNOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVNXOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = ~(vs.u16(n) ^ vte.u16(n)); } vd = ACCL; @@ -1137,7 +1137,7 @@ auto RSP::instructionVNXOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = vs.u16(n) | vte.u16(n); } vd = ACCL; @@ -1183,7 +1183,7 @@ auto RSP::instructionVRCPH(r128& vd, u8 de, cr128& vt, u8 e) -> void { template auto RSP::instructionVRND(r128& vd, u8 vs, cr128& vt, u8 e) -> void { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 product = (s16)vte.element(n); if(vs & 1) product <<= 16; s64 acc = 0; @@ -1243,7 +1243,7 @@ auto RSP::instructionVSAR(r128& vd, cr128& vs, u8 e) -> void { auto RSP::instructionVSUB(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { s32 result = vs.s16(n) - vte.s16(n) - VCOL.get(n); ACCL.s16(n) = result; vd.s16(n) = sclamp<16>(result); @@ -1268,7 +1268,7 @@ auto RSP::instructionVSUB(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVSUBC(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { u32 result = vs.u16(n) - vte.u16(n); ACCL.u16(n) = result; VCOL.set(n, result >> 16); @@ -1292,7 +1292,7 @@ auto RSP::instructionVSUBC(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { auto RSP::instructionVXOR(r128& vd, cr128& vs, cr128& vt, u8 e) -> void { if constexpr(Accuracy::RSP::SISD) { cr128 vte = vt(e); - for(uint n : range(8)) { + for(u32 n : range(8)) { ACCL.u16(n) = vs.u16(n) ^ vte.u16(n); } vd = ACCL; diff --git a/ares/n64/si/io.cpp b/ares/n64/si/io.cpp index 55ffe8acfc..8a5584c900 100644 --- a/ares/n64/si/io.cpp +++ b/ares/n64/si/io.cpp @@ -10,7 +10,7 @@ static const vector registerNames = { auto SI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //SI_DRAM_ADDRESS @@ -58,7 +58,7 @@ auto SI::readWord(u32 address) -> u32 { auto SI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //SI_DRAM_ADDRESS diff --git a/ares/n64/si/si.cpp b/ares/n64/si/si.cpp index 9e14d3afc9..418846659d 100644 --- a/ares/n64/si/si.cpp +++ b/ares/n64/si/si.cpp @@ -38,9 +38,9 @@ auto SI::main() -> void { if constexpr(Debug) { print("{\n"); - for(uint y : range(8)) { + for(u32 y : range(8)) { print(" "); - for(uint x : range(8)) { + for(u32 x : range(8)) { print(hex(pi.ram.readByte(y * 8 + x), 2L), " "); } print("\n"); @@ -48,19 +48,19 @@ auto SI::main() -> void { print("}\n"); } - uint3 channel = 0; - for(uint offset = 0; offset < 64;) { + n3 channel = 0; + for(u32 offset = 0; offset < 64;) { u8 send = pi.ram.readByte(offset++) & 0x3f; if(send == 0x00) { channel++; continue; } if(send == 0x3f) continue; if(send == 0x3e) break; u8 recvOffset = offset; u8 recv = pi.ram.readByte(offset++) & 0x3f; - uint8 input[256]; - for(uint index = 0; index < send; index++) { + n8 input[256]; + for(u32 index = 0; index < send; index++) { input[index] = pi.ram.readByte(offset++) & 0x3f; } - uint8 output[256]; + n8 output[256]; bool valid = 0; if(input[0] == 0x00 || input[0] == 0x3f) { if(channel < 4 && send == 1 && recv == 3) { @@ -73,7 +73,7 @@ auto SI::main() -> void { if(input[0] == 0x01) { if(channel < 4 && controllers[channel]->device) { u32 data = controllers[channel]->device->read(); - for(uint index = 0; index < min(4, recv); index++) { + for(u32 index = 0; index < min(4, recv); index++) { output[index] = data >> 24; data <<= 8; } @@ -88,7 +88,7 @@ auto SI::main() -> void { if(!valid) { pi.ram.writeByte(recvOffset, 0x80 | recv & 0x3f); } - for(uint index = 0; index < recv; index++) { + for(u32 index = 0; index < recv; index++) { pi.ram.writeByte(offset++, output[index]); } channel++; @@ -99,9 +99,9 @@ auto SI::main() -> void { if constexpr(Debug) { print("[\n"); - for(uint y : range(8)) { + for(u32 y : range(8)) { print(" "); - for(uint x : range(8)) { + for(u32 x : range(8)) { print(hex(pi.ram.readByte(y * 8 + x), 2L), " "); } print("\n"); diff --git a/ares/n64/si/si.hpp b/ares/n64/si/si.hpp index e0fc20fb4a..eb605eaa21 100644 --- a/ares/n64/si/si.hpp +++ b/ares/n64/si/si.hpp @@ -27,16 +27,16 @@ struct SI : Memory::IO { auto serialize(serializer&) -> void; struct IO { - uint24 dramAddress; - uint32 readAddress; - uint32 writeAddress; - uint1 dmaBusy; - uint1 ioBusy; - uint1 readPending; - uint4 pchState; - uint4 dmaState; - uint1 dmaError; - uint1 interrupt; + n24 dramAddress; + n32 readAddress; + n32 writeAddress; + n1 dmaBusy; + n1 ioBusy; + n1 readPending; + n4 pchState; + n4 dmaState; + n1 dmaError; + n1 interrupt; } io; u64 resetStrobe; //hack diff --git a/ares/n64/system/serialization.cpp b/ares/n64/system/serialization.cpp index 23ab0a8d3a..64ee52358c 100644 --- a/ares/n64/system/serialization.cpp +++ b/ares/n64/system/serialization.cpp @@ -1,7 +1,7 @@ auto System::serialize(bool synchronize) -> serializer { serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -16,7 +16,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/n64/system/system.cpp b/ares/n64/system/system.cpp index 0ea47e5de3..f14caa558f 100644 --- a/ares/n64/system/system.cpp +++ b/ares/n64/system/system.cpp @@ -2,7 +2,15 @@ namespace ares::Nintendo64 { +auto enumerate() -> vector { + return { + "[Nintendo] Nintendo 64 (NTSC)", + "[Nintendo] Nintendo 64 (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -27,8 +35,17 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("Nintendo 64")) { + information.name = "Nintendo 64"; + } + if(name.find("NTSC")) { + information.region = Region::NTSC; + } + if(name.find("PAL")) { + information.region = Region::PAL; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -38,14 +55,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC → PAL"); - regionNode->setAllowedValues({ - "NTSC → PAL", - "PAL → NTSC", - "NTSC", - "PAL" - }); - mi.load(node); vi.load(node); ai.load(node); @@ -95,20 +104,6 @@ auto System::save() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC") { - information.region = Region::NTSC; - } - if(region == "PAL") { - information.region = Region::PAL; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - //zero-initialization if(!reset) { serializer s; diff --git a/ares/n64/system/system.hpp b/ares/n64/system/system.hpp index 973ad654e8..d62536ff16 100644 --- a/ares/n64/system/system.hpp +++ b/ares/n64/system/system.hpp @@ -1,12 +1,11 @@ struct System { Node::System node; - Node::Setting::String regionNode; - enum class Region : uint { NTSC, PAL }; + enum class Region : u32 { NTSC, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto region() const -> Region { return information.region; } - auto frequency() const -> uint { return information.frequency; } + auto frequency() const -> u32 { return information.frequency; } //system.cpp auto game() -> string; @@ -22,8 +21,9 @@ struct System { private: struct Information { + string name = "Nintendo 64"; Region region = Region::NTSC; - uint frequency = 93'750'000; + u32 frequency = 93'750'000; } information; //serialization.cpp diff --git a/ares/n64/vi/io.cpp b/ares/n64/vi/io.cpp index 1a80b311a4..7b7c5b69ce 100644 --- a/ares/n64/vi/io.cpp +++ b/ares/n64/vi/io.cpp @@ -17,7 +17,7 @@ static const vector registerNames = { auto VI::readWord(u32 address) -> u32 { address = (address & 0xfffff) >> 2; - uint32 data; + n32 data; if(address == 0) { //VI_CONTROL @@ -116,7 +116,7 @@ auto VI::readWord(u32 address) -> u32 { auto VI::writeWord(u32 address, u32 data_) -> void { address = (address & 0xfffff) >> 2; - uint32 data = data_; + n32 data = data_; if(address == 0) { //VI_CONTROL diff --git a/ares/n64/vi/vi.cpp b/ares/n64/vi/vi.cpp index 12a9747066..d64a0cbef8 100644 --- a/ares/n64/vi/vi.cpp +++ b/ares/n64/vi/vi.cpp @@ -12,7 +12,7 @@ auto VI::load(Node::Object parent) -> void { screen = node->append("Screen", 640, 478); screen->setRefresh({&VI::refresh, this}); - screen->colors((1 << 24) + (1 << 15), [&](uint32 color) -> uint64 { + screen->colors((1 << 24) + (1 << 15), [&](n32 color) -> n64 { if(color < (1 << 24)) { u64 a = 65535; u64 r = image::normalize(color >> 16 & 255, 8, 16); @@ -53,22 +53,22 @@ auto VI::main() -> void { step(93'750'000 / 60 / 262); } -auto VI::step(uint clocks) -> void { +auto VI::step(u32 clocks) -> void { clock += clocks; } auto VI::refresh() -> void { - uint pitch = vi.io.width; - uint width = vi.io.width; //vi.io.xscale <= 0x300 ? 320 : 640; - uint height = vi.io.yscale <= 0x400 ? 239 : 478; + u32 pitch = vi.io.width; + u32 width = vi.io.width; //vi.io.xscale <= 0x300 ? 320 : 640; + u32 height = vi.io.yscale <= 0x400 ? 239 : 478; screen->setViewport(0, 0, width, height); if(vi.io.colorDepth == 2) { //15bpp - for(uint y : range(height)) { + for(u32 y : range(height)) { u32 address = vi.io.dramAddress + y * pitch * 2; auto line = screen->pixels(1).data() + y * 640; - for(uint x : range(min(width, pitch))) { + for(u32 x : range(min(width, pitch))) { u16 data = bus.readHalf(address + x * 2); *line++ = 1 << 24 | data >> 1; } @@ -77,10 +77,10 @@ auto VI::refresh() -> void { if(vi.io.colorDepth == 3) { //24bpp - for(uint y : range(height)) { + for(u32 y : range(height)) { u32 address = vi.io.dramAddress + y * pitch * 4; auto line = screen->pixels(1).data() + y * 640; - for(uint x : range(min(width, pitch))) { + for(u32 x : range(min(width, pitch))) { u32 data = bus.readWord(address + x * 4); *line++ = data >> 8; } diff --git a/ares/n64/vi/vi.hpp b/ares/n64/vi/vi.hpp index aeabaf9dc1..67b52fb342 100644 --- a/ares/n64/vi/vi.hpp +++ b/ares/n64/vi/vi.hpp @@ -19,7 +19,7 @@ struct VI : Thread, Memory::IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto refresh() -> void; auto power(bool reset) -> void; @@ -31,38 +31,38 @@ struct VI : Thread, Memory::IO { auto serialize(serializer&) -> void; struct IO { - uint2 colorDepth = 0; - uint1 gammaDither = 0; - uint1 gamma = 0; - uint1 divot = 0; - uint1 serrate = 0; - uint2 antialias = 0; - uint32 reserved = 0; - uint24 dramAddress = 0; - uint12 width = 0; - uint10 coincidence = 256; - uint8 hsyncWidth = 0; - uint8 colorBurstWidth = 0; - uint4 vsyncWidth = 0; - uint10 colorBurstHsync = 0; - uint10 halfLinesPerField = 0; - uint12 quarterLineDuration = 0; - uint5 palLeapPattern = 0; - uint12 hsyncLeap[2] = {}; - uint10 hend = 0; - uint10 hstart = 0; - uint10 vend = 0; - uint10 vstart = 0; - uint10 colorBurstEnd = 0; - uint10 colorBurstStart = 0; - uint12 xscale = 0; - uint12 xsubpixel = 0; - uint12 yscale = 0; - uint12 ysubpixel = 0; + n2 colorDepth = 0; + n1 gammaDither = 0; + n1 gamma = 0; + n1 divot = 0; + n1 serrate = 0; + n2 antialias = 0; + n32 reserved = 0; + n24 dramAddress = 0; + n12 width = 0; + n10 coincidence = 256; + n8 hsyncWidth = 0; + n8 colorBurstWidth = 0; + n4 vsyncWidth = 0; + n10 colorBurstHsync = 0; + n10 halfLinesPerField = 0; + n12 quarterLineDuration = 0; + n5 palLeapPattern = 0; + n12 hsyncLeap[2] = {}; + n10 hend = 0; + n10 hstart = 0; + n10 vend = 0; + n10 vstart = 0; + n10 colorBurstEnd = 0; + n10 colorBurstStart = 0; + n12 xscale = 0; + n12 xsubpixel = 0; + n12 yscale = 0; + n12 ysubpixel = 0; //internal: - uint9 vcounter = 0; - uint1 field = 0; + n9 vcounter = 0; + n1 field = 0; } io; //unserialized: diff --git a/ares/ngp/apu/apu.cpp b/ares/ngp/apu/apu.cpp index 514c1f8dec..9a7ab7dfb0 100644 --- a/ares/ngp/apu/apu.cpp +++ b/ares/ngp/apu/apu.cpp @@ -49,7 +49,7 @@ auto APU::main() -> void { instruction(); } -auto APU::step(uint clocks) -> void { +auto APU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu, psg); } diff --git a/ares/ngp/apu/apu.hpp b/ares/ngp/apu/apu.hpp index 3f4b7ceec8..3bb30add58 100644 --- a/ares/ngp/apu/apu.hpp +++ b/ares/ngp/apu/apu.hpp @@ -1,6 +1,6 @@ struct APU : Z80, Z80::Bus, Thread { Node::Object node; - Memory::Writable ram; + Memory::Writable ram; struct Debugger { //debugger.cpp @@ -26,35 +26,35 @@ struct APU : Z80, Z80::Bus, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto power() -> void; auto enable() -> void; auto disable() -> void; //memory.cpp - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto in(uint16 address) -> uint8 override; - auto out(uint16 address, uint8 data) -> void override; + auto in(n16 address) -> n8 override; + auto out(n16 address, n8 data) -> void override; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; struct NMI { - uint1 line; + n1 line; } nmi; struct IRQ { - uint1 line; + n1 line; } irq; struct Port { - uint8 data; + n8 data; } port; struct IO { - uint1 enable; + n1 enable; } io; }; diff --git a/ares/ngp/apu/memory.cpp b/ares/ngp/apu/memory.cpp index 9e4f6585a7..abf885b26e 100644 --- a/ares/ngp/apu/memory.cpp +++ b/ares/ngp/apu/memory.cpp @@ -1,6 +1,6 @@ -auto APU::read(uint16 address) -> uint8 { +auto APU::read(n16 address) -> n8 { if(address >= 0x0000 && address <= 0x0fff) { - //uint timeout = 0; + //u32 timeout = 0; //while(cpu.mar >= 0x7000 && cpu.mar <= 0x7fff && ++timeout < 64) step(1); return ram.read(0x3000 | address); } @@ -8,9 +8,9 @@ auto APU::read(uint16 address) -> uint8 { return 0x00; } -auto APU::write(uint16 address, uint8 data) -> void { +auto APU::write(n16 address, n8 data) -> void { if(address >= 0x0000 && address <= 0x0fff) { - //uint timeout = 0; + //u32 timeout = 0; //while(cpu.mar >= 0x7000 && cpu.mar <= 0x7fff && ++timeout < 64) step(1); return ram.write(0x3000 | address, data); } @@ -20,12 +20,12 @@ auto APU::write(uint16 address, uint8 data) -> void { if(address == 0xc000) return cpu.int5.raise(); } -auto APU::in(uint16 address) -> uint8 { +auto APU::in(n16 address) -> n8 { return 0x00; } -auto APU::out(uint16 address, uint8 data) -> void { - switch((uint8)address) { +auto APU::out(n16 address, n8 data) -> void { + switch((n8)address) { case 0xff: irq.line = 0; cpu.int5.lower(); diff --git a/ares/ngp/cartridge/cartridge.cpp b/ares/ngp/cartridge/cartridge.cpp index 22fa7d8b90..db9d71c39c 100644 --- a/ares/ngp/cartridge/cartridge.cpp +++ b/ares/ngp/cartridge/cartridge.cpp @@ -64,12 +64,12 @@ auto Cartridge::power() -> void { flash[1].power(); } -auto Cartridge::read(uint1 chip, uint21 address) -> uint8 { +auto Cartridge::read(n1 chip, n21 address) -> n8 { if(!flash[chip]) return 0x00; return flash[chip].read(address); } -auto Cartridge::write(uint1 chip, uint21 address, uint8 data) -> void { +auto Cartridge::write(n1 chip, n21 address, n8 data) -> void { if(!flash[chip]) return; return flash[chip].write(address, data); } diff --git a/ares/ngp/cartridge/cartridge.hpp b/ares/ngp/cartridge/cartridge.hpp index 4c85f73d77..d4c797c512 100644 --- a/ares/ngp/cartridge/cartridge.hpp +++ b/ares/ngp/cartridge/cartridge.hpp @@ -14,8 +14,8 @@ struct Cartridge { auto save() -> void; auto power() -> void; - auto read(uint1 bank, uint21 address) -> uint8; - auto write(uint1 bank, uint21 address, uint8 data) -> void; + auto read(n1 bank, n21 address) -> n8; + auto write(n1 bank, n21 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/ngp/cartridge/flash.cpp b/ares/ngp/cartridge/flash.cpp index 200194c654..f08eab1e88 100644 --- a/ares/ngp/cartridge/flash.cpp +++ b/ares/ngp/cartridge/flash.cpp @@ -13,7 +13,7 @@ auto Flash::allocate(natural size) -> bool { if(size == 16_Mibit) { rom.allocate(size); vendorID = 0x98; deviceID = 0x2f; } //vendorID 0xec => Samsung if(!rom) return false; - for(uint index : range(size / 64_KiB - 1)) blocks.append({true, index * 64_KiB, 64_KiB}); + for(u32 index : range(size / 64_KiB - 1)) blocks.append({true, index * 64_KiB, 64_KiB}); blocks.append({true, size - 64_KiB, 32_KiB}); blocks.append({true, size - 32_KiB, 8_KiB}); blocks.append({true, size - 24_KiB, 8_KiB}); @@ -35,9 +35,9 @@ auto Flash::power() -> void { status(Read); } -auto Flash::read(uint21 address) -> uint8 { +auto Flash::read(n21 address) -> n8 { if(mode == ReadID) { - switch((uint14)address) { //todo: actual mask value unknown + switch((n14)address) { //todo: actual mask value unknown case 0: return vendorID; case 1: return deviceID; case 2: return 0x02; //unknown purpose @@ -48,10 +48,10 @@ auto Flash::read(uint21 address) -> uint8 { return rom.read(address); //todo: what happens when mode != Read here? } -auto Flash::write(uint21 address, uint8 data) -> void { +auto Flash::write(n21 address, n8 data) -> void { if(mode == Write) return program(address, data); if(data == 0xf0) return status(Read); - uint15 addr = (uint15)address; + n15 addr = (n15)address; if(index == 0 && addr == 0x5555 && data == 0xaa) return status(Index); if(index == 1 && addr == 0x2aaa && data == 0x55) return status(Index); //todo: erase and protect diverge here; but they're treated the same for simplicity for now @@ -68,14 +68,14 @@ auto Flash::write(uint21 address, uint8 data) -> void { return status(Read); } -auto Flash::status(uint mode_) -> void { +auto Flash::status(u32 mode_) -> void { mode = mode_; if(mode == Read) index = 0; if(mode == Index) index++; } -auto Flash::block(uint21 address) -> maybe { - for(uint6 index : range(blocks.size())) { +auto Flash::block(n21 address) -> maybe { + for(n6 index : range(blocks.size())) { if(address < blocks[index].offset) continue; if(address >= blocks[index].offset + blocks[index].length) continue; return index; @@ -84,7 +84,7 @@ auto Flash::block(uint21 address) -> maybe { return {}; } -auto Flash::program(uint21 address, uint8 data) -> void { +auto Flash::program(n21 address, n8 data) -> void { auto blockID = block(address); if(blockID && blocks[*blockID].writable) { if(auto input = rom.read(address); input != (input & data)) { @@ -95,7 +95,7 @@ auto Flash::program(uint21 address, uint8 data) -> void { return status(Read); } -auto Flash::protect(uint21 address) -> void { +auto Flash::protect(n21 address) -> void { auto blockID = block(address); if(blockID && blocks[*blockID].writable) { blocks[*blockID].writable = false; @@ -104,12 +104,12 @@ auto Flash::protect(uint21 address) -> void { return status(Read); } -auto Flash::erase(uint21 address) -> void { +auto Flash::erase(n21 address) -> void { auto blockID = block(address); if(blockID && blocks[*blockID].writable) { auto address = blocks[*blockID].offset; auto length = blocks[*blockID].length; - for(uint offset : range(length)) rom.write(address + offset, 0xff); + for(u32 offset : range(length)) rom.write(address + offset, 0xff); modified = true; } return status(Read); diff --git a/ares/ngp/cartridge/flash.hpp b/ares/ngp/cartridge/flash.hpp index 916fc8e0f1..c2387150a7 100644 --- a/ares/ngp/cartridge/flash.hpp +++ b/ares/ngp/cartridge/flash.hpp @@ -10,9 +10,9 @@ struct Flash { natural ID; //todo: can this be made const, even though it's declared as Cartridge::Flash[2] ? boolean modified; - Memory::Writable rom; - uint8 vendorID; - uint8 deviceID; + Memory::Writable rom; + n8 vendorID; + n8 deviceID; explicit operator bool() const { return (bool)rom; } @@ -23,20 +23,20 @@ struct Flash { auto save(shared_pointer fp) -> void; auto power() -> void; - auto read(uint21 address) -> uint8; - auto write(uint21 address, uint8 data) -> void; - - auto status(uint) -> void; - auto block(uint21 address) -> maybe; - auto program(uint21 address, uint8 data) -> void; - auto protect(uint21 blockID) -> void; - auto erase(uint21 blockID) -> void; + auto read(n21 address) -> n8; + auto write(n21 address, n8 data) -> void; + + auto status(u32) -> void; + auto block(n21 address) -> maybe; + auto program(n21 address, n8 data) -> void; + auto protect(n21 blockID) -> void; + auto erase(n21 blockID) -> void; auto eraseAll() -> void; //serialization.cpp auto serialize(serializer&) -> void; - enum : uint { Read, Index, ReadID, Write }; + enum : u32 { Read, Index, ReadID, Write }; natural mode; natural index; diff --git a/ares/ngp/cpu/adc.cpp b/ares/ngp/cpu/adc.cpp index 57942b5daf..ad9a155cd3 100644 --- a/ares/ngp/cpu/adc.cpp +++ b/ares/ngp/cpu/adc.cpp @@ -1,6 +1,6 @@ //analog-to-digital converter -auto CPU::ADC::step(uint clocks) -> void { +auto CPU::ADC::step(u32 clocks) -> void { if(!busy) return; counter += clocks; if(counter >= (!speed ? 160 : 320)) { diff --git a/ares/ngp/cpu/cpu.cpp b/ares/ngp/cpu/cpu.cpp index 02a0e7ac56..fcc02e4c03 100644 --- a/ares/ngp/cpu/cpu.cpp +++ b/ares/ngp/cpu/cpu.cpp @@ -24,9 +24,9 @@ auto CPU::load(Node::Object parent) -> void { //for unknown reasons, the BIOS from (0xffff00) only writes 0x00dc. //it is not updated when language/color choices are made. //to prevent the setup from being run every boot, manually calculate and set this value. - uint16 data; + n16 data; data += ram[0x2f87]; //language: Japanese, English - for(uint address = 0x2c25; address <= 0x2c2b; address++) data += ram[address]; //always 0x00dc + for(u32 address = 0x2c25; address <= 0x2c2b; address++) data += ram[address]; //always 0x00dc if(Model::NeoGeoPocketColor()) { data += ram[0x2f94]; //K1GE color mode: Black & White, Blue, Green, Red, Classic } @@ -77,7 +77,7 @@ auto CPU::main() -> void { instruction(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { clocks <<= clock.rate; prescaler.step(clocks); adc.step(clocks); @@ -87,7 +87,7 @@ auto CPU::step(uint clocks) -> void { Thread::synchronize(); } -auto CPU::idle(uint clocks) -> void { +auto CPU::idle(u32 clocks) -> void { clocks <<= clock.rate; prescaler.step(clocks); adc.step(clocks); @@ -108,7 +108,7 @@ auto CPU::power() -> void { //halve the thread frequency instead of doubling the cycles for every instruction. Thread::create(system.frequency() / 2.0, {&CPU::main, this}); - uint24 address; + n24 address; address.byte(0) = system.bios.read(0xff00); address.byte(1) = system.bios.read(0xff01); address.byte(2) = system.bios.read(0xff02); @@ -272,54 +272,54 @@ auto CPU::power() -> void { io = {}; io.width = Byte; io.timing = 3; - io.reader = [](uint24 address) -> uint8 { return cpu.readIO(address); }; - io.writer = [](uint24 address, uint8 data) { return cpu.writeIO(address, data); }; + io.reader = [](n24 address) -> n8 { return cpu.readIO(address); }; + io.writer = [](n24 address, n8 data) { return cpu.writeIO(address, data); }; rom = {}; rom.width = Word; rom.timing = 3; - rom.reader = [](uint24 address) -> uint8 { return system.bios.read(address); }; - rom.writer = [](uint24 address, uint8 data) { return system.bios.write(address, data); }; + rom.reader = [](n24 address) -> n8 { return system.bios.read(address); }; + rom.writer = [](n24 address, n8 data) { return system.bios.write(address, data); }; cram = {}; cram.width = Word; cram.timing = 3; - cram.reader = [](uint24 address) -> uint8 { return cpu.ram.read(address); }; - cram.writer = [](uint24 address, uint8 data) { return cpu.ram.write(address, data); }; + cram.reader = [](n24 address) -> n8 { return cpu.ram.read(address); }; + cram.writer = [](n24 address, n8 data) { return cpu.ram.write(address, data); }; aram = {}; aram.width = Word; aram.timing = 3; - aram.reader = [](uint24 address) -> uint8 { return apu.ram.read(address); }; - aram.writer = [](uint24 address, uint8 data) { return apu.ram.write(address, data); }; + aram.reader = [](n24 address) -> n8 { return apu.ram.read(address); }; + aram.writer = [](n24 address, n8 data) { return apu.ram.write(address, data); }; vram = {}; vram.width = Word; vram.timing = 3; - vram.reader = [](uint24 address) -> uint8 { return vpu.read(address); }; - vram.writer = [](uint24 address, uint8 data) { return vpu.write(address, data); }; + vram.reader = [](n24 address) -> n8 { return vpu.read(address); }; + vram.writer = [](n24 address, n8 data) { return vpu.write(address, data); }; cs0 = {}; cs0.width = Word; cs0.timing = 0; - cs0.reader = [](uint24 address) -> uint8 { return cartridge.read(0, address); }; - cs0.writer = [](uint24 address, uint8 data) { return cartridge.write(0, address, data); }; + cs0.reader = [](n24 address) -> n8 { return cartridge.read(0, address); }; + cs0.writer = [](n24 address, n8 data) { return cartridge.write(0, address, data); }; cs0.address = 0xff0000; cs0.mask = 0x1fffff; cs1 = {}; cs1.width = Word; cs1.timing = 0; - cs1.reader = [](uint24 address) -> uint8 { return cartridge.read(1, address); }; - cs1.writer = [](uint24 address, uint8 data) { return cartridge.write(1, address, data); }; + cs1.reader = [](n24 address) -> n8 { return cartridge.read(1, address); }; + cs1.writer = [](n24 address, n8 data) { return cartridge.write(1, address, data); }; cs1.address = 0xff0000; cs1.mask = 0x3fffff; cs2 = {}; cs2.width = Word; cs2.timing = 0; - cs2.reader = [](uint24 address) -> uint8 { return 0x00; }; - cs2.writer = [](uint24 address, uint8 data) { return; }; + cs2.reader = [](n24 address) -> n8 { return 0x00; }; + cs2.writer = [](n24 address, n8 data) { return; }; cs2.address = 0xff0000; cs2.mask = 0x7fffff; cs2.mode = 0; @@ -327,8 +327,8 @@ auto CPU::power() -> void { cs3 = {}; cs3.width = Word; cs3.timing = 0; - cs3.reader = [](uint24 address) -> uint8 { return 0x00; }; - cs3.writer = [](uint24 address, uint8 data) { return; }; + cs3.reader = [](n24 address) -> n8 { return 0x00; }; + cs3.writer = [](n24 address, n8 data) { return; }; cs3.address = 0xff0000; cs3.mask = 0x7fffff; cs3.cas = 0; @@ -336,8 +336,8 @@ auto CPU::power() -> void { csx = {}; csx.width = Word; csx.timing = 0; - csx.reader = [](uint24 address) -> uint8 { return 0x00; }; - csx.writer = [](uint24 address, uint8 data) { return; }; + csx.reader = [](n24 address) -> n8 { return 0x00; }; + csx.writer = [](n24 address, n8 data) { return; }; clock = {}; @@ -347,7 +347,7 @@ auto CPU::power() -> void { //code to skip the BIOS boot sequence and load the game immediately. //note that this will not configure the language, color mode, or real-time clock. auto CPU::fastBoot() -> void { - uint32 address; + n32 address; address.byte(0) = cartridge.read(0, 0x1c); address.byte(1) = cartridge.read(0, 0x1d); address.byte(2) = cartridge.read(0, 0x1e); @@ -408,8 +408,8 @@ auto CPU::fastBoot() -> void { vpu.write(0x8000, 0xc0); //enable Vblank and Hblank interrupts //default color palette: Magical Drop relies on the BIOS to initialize this. - for(uint address = 0x8380; address < 0x8400; address++) { - static uint8 data[16] = { + for(u32 address = 0x8380; address < 0x8400; address++) { + static n8 data[16] = { 0xff, 0x0f, 0xdd, 0x0d, 0xbb, 0x0b, 0x99, 0x09, 0x77, 0x07, 0x44, 0x04, 0x33, 0x03, 0x00, 0x00, }; diff --git a/ares/ngp/cpu/cpu.hpp b/ares/ngp/cpu/cpu.hpp index 0c5db5eabd..c6f567b2b5 100644 --- a/ares/ngp/cpu/cpu.hpp +++ b/ares/ngp/cpu/cpu.hpp @@ -5,7 +5,7 @@ struct CPU : TLCS900H, Thread { Node::Object node; - ares::Memory::Writable ram; //12KB + ares::Memory::Writable ram; //12KB struct Debugger { //debugger.cpp @@ -29,7 +29,7 @@ struct CPU : TLCS900H, Thread { //operating in color mode, and further fails to set the K1GE compatibility //palette, resulting in incorrect colors. . I am not certain how, but the NGPC //blocks this write command, so I attempt to simulate that here. - //VPU::write(uint24, uint8) calls this function. + //VPU::write(n24, n8) calls this function. auto privilegedMode() const -> bool { return r.pc.l.l0 >= 0xff0000; //may also be r.rfp == 3 } @@ -40,20 +40,20 @@ struct CPU : TLCS900H, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; - auto idle(uint clocks) -> void override; + auto step(u32 clocks) -> void; + auto idle(u32 clocks) -> void override; auto pollPowerButton() -> void; auto power() -> void; auto fastBoot() -> void; //memory.cpp - auto width(uint24 address) -> uint override; - auto read(uint width, uint24 address) -> uint32 override; - auto write(uint width, uint24 address, uint32 data) -> void override; + auto width(n24 address) -> u32 override; + auto read(u32 width, n24 address) -> n32 override; + auto write(u32 width, n24 address, n32 data) -> void override; //io.cpp - auto readIO(uint8 address) -> uint8; - auto writeIO(uint8 address, uint8 data) -> void; + auto readIO(n8 address) -> n8; + auto writeIO(n8 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -64,44 +64,44 @@ struct CPU : TLCS900H, Thread { auto poll() -> void; auto fire() -> bool; - uint8 vector; - uint3 priority; + n8 vector; + n3 priority; } interrupts; struct Interrupt { //interrupts.cpp - auto power(uint8 vector) -> void; + auto power(n8 vector) -> void; auto operator=(bool) -> void; - auto poll(uint8& vector, uint3& priority) -> void; - auto fire(uint8 vector) -> void; + auto poll(n8& vector, n3& priority) -> void; + auto fire(n8 vector) -> void; auto set(bool line) -> void; auto raise() -> void; auto lower() -> void; auto trigger() -> void; auto clear() -> void; - auto setEnable(uint1 enable) -> void; - auto setPriority(uint3 priority) -> void; + auto setEnable(n1 enable) -> void; + auto setPriority(n3 priority) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8 vector; - uint1 dmaAllowed; - uint1 enable; - uint1 maskable; - uint3 priority; - uint1 line; - uint1 pending; + n8 vector; + n1 dmaAllowed; + n1 enable; + n1 maskable; + n3 priority; + n1 line; + n1 pending; struct Level { - uint1 high; - uint1 low; + n1 high; + n1 low; } level; struct Edge { - uint1 rising; - uint1 falling; + n1 rising; + n1 falling; } edge; }; @@ -134,34 +134,34 @@ struct CPU : TLCS900H, Thread { Interrupt inttc3; struct DMA { - uint8 vector; + n8 vector; } dma0, dma1, dma2, dma3; //ports.cpp struct PortFlow { auto readable() const { return flow == 0; } //in auto writable() const { return flow == 1; } //out - uint1 flow; + n1 flow; }; struct PortMode { auto internal() const { return mode == 0; } //port auto external() const { return mode == 1; } //timer, etc - uint1 mode; + n1 mode; }; // P10-17, D8-D15 struct P1 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p10, p11, p12, p13, p14, p15, p16, p17; // P20-P27, A16-A23 struct P2 : PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p20, p21, p22, p23, p24, p25, p26, p27; // P52, /HWR @@ -171,7 +171,7 @@ struct CPU : TLCS900H, Thread { struct P5 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p52, p53, p54, p55; // P60, /CS0 @@ -183,7 +183,7 @@ struct CPU : TLCS900H, Thread { struct P6 : PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p60, p61, p62, p63, p64, p65; // P70-P73, PG00-PG03 @@ -191,7 +191,7 @@ struct CPU : TLCS900H, Thread { struct P7 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p70, p71, p72, p73, p74, p75, p76, p77; // P80, TXD0 @@ -203,177 +203,177 @@ struct CPU : TLCS900H, Thread { struct P8F : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p81, p84; struct P8M : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } p80, p82, p83, p85; // P90-P93, AN0-AN3 struct P9 { operator bool() const; - uint1 latch; + n1 latch; } p90, p91, p92, p93; // PA0, /WAIT struct PA0 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pa0; // PA1, TI0, (/HBLANK) struct PA1 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pa1; // PA2, TO1 struct PA2 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pa2; // PA3, TO3 struct PA3 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pa3; // PB0, INT4, TI4, (/VBLANK) struct PB0 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb0; // PB1, INT5, TI5, (APU) struct PB1 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb1; // PB2, TO4 struct PB2 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb2; // PB3, TO5 struct PB3 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb3; // PB4, INT6, TI6 struct PB4 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb4; // PB5, INT7, TI7 struct PB5 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb5; // PB6, TO6 struct PB6 : PortFlow, PortMode { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb6; // PB7, INT0 struct PB7 : PortFlow { operator bool() const; auto operator=(bool) -> void; - uint1 latch; + n1 latch; } pb7; //timers.cpp struct Prescaler { - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; - uint1 enable; - uint32 counter; + n1 enable; + n32 counter; } prescaler; struct TI0 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } ti0; struct TI4 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } ti4; struct TI5 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } ti5; struct TI6 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } ti6; struct TI7 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } ti7; struct TO1 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to1; struct TO3 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to3; struct TO4 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to4; struct TO5 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to5; struct TO6 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to6; struct TO7 { operator bool() const { return latch; } auto operator=(bool) -> void; - uint1 latch; + n1 latch; } to7; //8-bit timers @@ -381,78 +381,78 @@ struct CPU : TLCS900H, Thread { struct Timer0 { auto disable() -> void; - uint1 enable; //t0run - uint2 mode; //t0clk - uint8 counter; //uc0 - uint8 compare; //treg0 + n1 enable; //t0run + n2 mode; //t0clk + n8 counter; //uc0 + n8 compare; //treg0 } t0; struct Timer1 { auto disable() -> void; - uint1 enable; //t1run - uint2 mode; //t1clk - uint8 counter; //uc1 - uint8 compare; //treg1 + n1 enable; //t1run + n2 mode; //t1clk + n8 counter; //uc1 + n8 compare; //treg1 } t1; struct FlipFlop1 { operator bool() const { return output; } auto operator=(bool) -> void; - uint1 source; //ff1is - uint1 invert; //ff1ie - uint1 output; + n1 source; //ff1is + n1 invert; //ff1ie + n1 output; } ff1; struct Timer01 { auto clockT0() -> void; auto clockT1() -> void; - uint2 mode; //t01m - uint2 pwm; //pwm0 + n2 mode; //t01m + n2 pwm; //pwm0 struct Buffer { - uint1 enable; - uint8 compare; + n1 enable; + n8 compare; } buffer; } t01; struct Timer2 { auto disable() -> void; - uint1 enable; - uint2 mode; - uint8 counter; - uint8 compare; + n1 enable; + n2 mode; + n8 counter; + n8 compare; } t2; struct Timer3 { auto disable() -> void; - uint1 enable; - uint2 mode; - uint8 counter; - uint8 compare; + n1 enable; + n2 mode; + n8 counter; + n8 compare; } t3; struct FlipFlop3 { operator bool() const { return output; } auto operator=(bool) -> void; - uint1 source; - uint1 invert; - uint1 output; + n1 source; + n1 invert; + n1 output; } ff3; struct Timer23 { auto clockT2() -> void; auto clockT3() -> void; - uint2 mode; - uint2 pwm; + n2 mode; + n2 pwm; struct Buffer { - uint1 enable; - uint8 compare; + n1 enable; + n8 compare; } buffer; } t23; @@ -462,20 +462,20 @@ struct CPU : TLCS900H, Thread { operator bool() const { return output; } auto operator=(bool) -> void; - uint1 flipOnCompare4; - uint1 flipOnCompare5; - uint1 flipOnCapture1; - uint1 flipOnCapture2; - uint1 output; + n1 flipOnCompare4; + n1 flipOnCompare5; + n1 flipOnCapture1; + n1 flipOnCapture2; + n1 output; } ff4; struct FlipFlop5 { operator bool() const { return output; } auto operator=(bool) -> void; - uint1 flipOnCompare5; - uint1 flipOnCapture2; - uint1 output; + n1 flipOnCompare5; + n1 flipOnCapture2; + n1 output; } ff5; struct Timer4 { @@ -484,18 +484,18 @@ struct CPU : TLCS900H, Thread { auto captureTo2() -> void; auto clock() -> void; - uint1 enable; - uint2 mode; - uint2 captureMode; - uint1 clearOnCompare5; - uint16 counter; - uint16 compare4; - uint16 compare5; - uint16 capture1; - uint16 capture2; + n1 enable; + n2 mode; + n2 captureMode; + n1 clearOnCompare5; + n16 counter; + n16 compare4; + n16 compare5; + n16 capture1; + n16 capture2; struct Buffer { - uint1 enable; - uint16 compare; + n1 enable; + n16 compare; } buffer; } t4; @@ -503,11 +503,11 @@ struct CPU : TLCS900H, Thread { operator bool() const { return output; } auto operator=(bool) -> void; - uint1 flipOnCompare6; - uint1 flipOnCompare7; - uint1 flipOnCapture3; - uint1 flipOnCapture4; - uint1 output; + n1 flipOnCompare6; + n1 flipOnCompare7; + n1 flipOnCapture3; + n1 flipOnCapture4; + n1 output; } ff6; struct Timer5 { @@ -516,129 +516,129 @@ struct CPU : TLCS900H, Thread { auto captureTo4() -> void; auto clock() -> void; - uint1 enable; - uint2 mode; - uint2 captureMode; - uint1 clearOnCompare7; - uint16 counter; - uint16 compare6; - uint16 compare7; - uint16 capture3; - uint16 capture4; + n1 enable; + n2 mode; + n2 captureMode; + n1 clearOnCompare7; + n16 counter; + n16 compare6; + n16 compare7; + n16 capture3; + n16 capture4; struct Buffer { - uint1 enable; - uint16 compare; + n1 enable; + n16 compare; } buffer; } t5; //adc.cpp struct ADC { - auto step(uint clocks) -> void; - - uint32 counter; - uint2 channel; - uint1 speed; //0 = 160 states, 1 = 320 states - uint1 scan; - uint1 repeat; - uint1 busy; - uint1 end; - uint10 result[4]; + auto step(u32 clocks) -> void; + + n32 counter; + n2 channel; + n1 speed; //0 = 160 states, 1 = 320 states + n1 scan; + n1 repeat; + n1 busy; + n1 end; + n10 result[4]; } adc; //rtc.cpp struct RTC { - auto step(uint clocks) -> void; - auto daysInMonth() -> uint8; - auto daysInFebruary() -> uint8; - - uint32 counter; - uint1 enable; - uint8 second; - uint8 minute; - uint8 hour; - uint8 weekday; - uint8 day; - uint8 month; - uint8 year; + auto step(u32 clocks) -> void; + auto daysInMonth() -> n8; + auto daysInFebruary() -> n8; + + n32 counter; + n1 enable; + n8 second; + n8 minute; + n8 hour; + n8 weekday; + n8 day; + n8 month; + n8 year; } rtc; //watchdog.cpp struct Watchdog { - auto step(uint clocks) -> void; - - uint32 counter; - uint1 enable; - uint1 drive; - uint1 reset; - uint2 standby; - uint1 warmup; - uint2 frequency; + auto step(u32 clocks) -> void; + + n32 counter; + n1 enable; + n1 drive; + n1 reset; + n2 standby; + n1 warmup; + n2 frequency; } watchdog; //memory.cpp struct Bus { auto wait() -> void; - auto read(uint width, uint24 address) -> uint32; - auto write(uint width, uint24 address, uint32 data) -> void; + auto read(u32 width, n24 address) -> n32; + auto write(u32 width, n24 address, n32 data) -> void; - uint8 width; - uint2 timing; - function reader; - function writer; + n8 width; + n2 timing; + function reader; + function writer; }; struct IO : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; } io; struct ROM : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; } rom; struct CRAM : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; } cram; struct ARAM : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; } aram; struct VRAM : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; } vram; struct CS0 : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; - uint1 enable; - uint24 address; - uint24 mask; + n1 enable; + n24 address; + n24 mask; } cs0; struct CS1 : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; - uint1 enable; - uint24 address; - uint24 mask; + n1 enable; + n24 address; + n24 mask; } cs1; struct CS2 : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; - uint1 enable; - uint24 address; - uint24 mask; - uint1 mode; //0 = fixed; 1 = address/mask + n1 enable; + n24 address; + n24 mask; + n1 mode; //0 = fixed; 1 = address/mask } cs2; struct CS3 : Bus { - auto select(uint24 address) const -> bool; + auto select(n24 address) const -> bool; - uint1 enable; - uint24 address; - uint24 mask; - uint1 cas; //0 = /CS3, 1 = /CAS + n1 enable; + n24 address; + n24 mask; + n1 cas; //0 = /CS3, 1 = /CAS } cs3; struct CSX : Bus { @@ -653,14 +653,14 @@ struct CPU : TLCS900H, Thread { //5 = 192000hz? (undocumented) //6 = 96000hz? (undocumented) //7 = 48000hz? (undocumented) - uint3 rate = 4; //default value unconfirmed + n3 rate = 4; //default value unconfirmed } clock; struct Misc { - uint1 p5; //Port 5: 0 = PSRAM mode, 1 = (not PSRAM mode?) [unemulated] - uint1 rtsDisable; - uint8 b4; - uint8 b5; + n1 p5; //Port 5: 0 = PSRAM mode, 1 = (not PSRAM mode?) [unemulated] + n1 rtsDisable; + n8 b4; + n8 b5; } misc; }; diff --git a/ares/ngp/cpu/interrupts.cpp b/ares/ngp/cpu/interrupts.cpp index 574de25fe8..a91b909c77 100644 --- a/ares/ngp/cpu/interrupts.cpp +++ b/ares/ngp/cpu/interrupts.cpp @@ -77,7 +77,7 @@ auto CPU::Interrupt::operator=(bool value) -> void { set(value); } -auto CPU::Interrupt::poll(uint8& vector, uint3& priority) -> void { +auto CPU::Interrupt::poll(n8& vector, n3& priority) -> void { if(!enable || !pending) return; if(!maskable) { priority = 7; vector = this->vector; return; } if(dmaAllowed && cpu.r.iff <= 6) { @@ -90,7 +90,7 @@ auto CPU::Interrupt::poll(uint8& vector, uint3& priority) -> void { if(this->priority >= priority) { priority = this->priority; vector = this->vector; return; } } -auto CPU::Interrupt::fire(uint8 vector) -> void { +auto CPU::Interrupt::fire(n8 vector) -> void { if(this->vector != vector) return; if(line == 0 && !level.low ) pending = 0; if(line == 1 && !level.high) pending = 0; @@ -128,19 +128,19 @@ auto CPU::Interrupt::clear() -> void { cpu.interrupts.poll(); } -auto CPU::Interrupt::setEnable(uint1 enable) -> void { +auto CPU::Interrupt::setEnable(n1 enable) -> void { if(this->enable == enable) return; this->enable = enable; cpu.interrupts.poll(); } -auto CPU::Interrupt::setPriority(uint3 priority) -> void { +auto CPU::Interrupt::setPriority(n3 priority) -> void { if(this->priority == priority) return; this->priority = priority; cpu.interrupts.poll(); } -auto CPU::Interrupt::power(uint8 vector) -> void { +auto CPU::Interrupt::power(n8 vector) -> void { this->vector = vector; //set up defaults that apply to most vectors diff --git a/ares/ngp/cpu/io.cpp b/ares/ngp/cpu/io.cpp index 4b8dd06998..124729b6b9 100644 --- a/ares/ngp/cpu/io.cpp +++ b/ares/ngp/cpu/io.cpp @@ -1,6 +1,6 @@ -auto CPU::readIO(uint8 address) -> uint8 { +auto CPU::readIO(n8 address) -> n8 { //print("CPU::readIO(", hex(address, 2L), ")\n"); - uint8 data = 0x00; + n8 data = 0x00; switch(address) { @@ -495,7 +495,7 @@ auto CPU::readIO(uint8 address) -> uint8 { return data; } -auto CPU::writeIO(uint8 address, uint8 data) -> void { +auto CPU::writeIO(n8 address, n8 data) -> void { //print("CPU::writeIO(", hex(address, 2L), " = ", hex(data, 2L), ")\n"); switch(address) { @@ -980,9 +980,9 @@ auto CPU::writeIO(uint8 address, uint8 data) -> void { //ADMOD case 0x6d: { - uint1 busy = adc.busy; + n1 busy = adc.busy; adc.channel = data.bit(0,1); - uint1 start = data.bit(2); + n1 start = data.bit(2); adc.speed = data.bit(3); adc.scan = data.bit(4); adc.repeat = data.bit(5); diff --git a/ares/ngp/cpu/memory.cpp b/ares/ngp/cpu/memory.cpp index 457e1f4bb9..007b4f6a7d 100644 --- a/ares/ngp/cpu/memory.cpp +++ b/ares/ngp/cpu/memory.cpp @@ -18,8 +18,8 @@ auto CPU::Bus::wait() -> void { unreachable; } -auto CPU::Bus::read(uint size, uint24 address) -> uint32 { - uint32 data; +auto CPU::Bus::read(u32 size, n24 address) -> n32 { + n32 data; if(width == Byte) { if(size == Byte) { @@ -88,7 +88,7 @@ auto CPU::Bus::read(uint size, uint24 address) -> uint32 { return data; } -auto CPU::Bus::write(uint size, uint24 address, uint32 data) -> void { +auto CPU::Bus::write(u32 size, n24 address, n32 data) -> void { if(width == Byte) { if(size == Byte) { wait(); @@ -157,35 +157,35 @@ auto CPU::Bus::write(uint size, uint24 address, uint32 data) -> void { /* IO: (internal I/O registers) */ -auto CPU::IO::select(uint24 compare) const -> bool { +auto CPU::IO::select(n24 compare) const -> bool { return compare <= 0x0000ff; } /* ROM: (BIOS) */ -auto CPU::ROM::select(uint24 compare) const -> bool { +auto CPU::ROM::select(n24 compare) const -> bool { return compare >= 0xff0000; } /* CRAM: (CPU memory) */ -auto CPU::CRAM::select(uint24 compare) const -> bool { +auto CPU::CRAM::select(n24 compare) const -> bool { return compare >= 0x004000 && compare <= 0x006fff; } /* ARAM: (APU memory) */ -auto CPU::ARAM::select(uint24 compare) const -> bool { +auto CPU::ARAM::select(n24 compare) const -> bool { return compare >= 0x007000 && compare <= 0x007fff; } /* VRAM: (VPU memory) */ -auto CPU::VRAM::select(uint24 compare) const -> bool { +auto CPU::VRAM::select(n24 compare) const -> bool { return compare >= 0x008000 && compare <= 0x00bfff; } @@ -193,47 +193,47 @@ auto CPU::VRAM::select(uint24 compare) const -> bool { * Connected to cartridge flash chip 0. */ -auto CPU::CS0::select(uint24 compare) const -> bool { +auto CPU::CS0::select(n24 compare) const -> bool { if(!enable) return false; - return !(uint24)((compare ^ address) & ~mask); + return !(n24)((compare ^ address) & ~mask); } /* CS1: (chip select 1) * Connected to cartridge flash chip 1. */ -auto CPU::CS1::select(uint24 compare) const -> bool { +auto CPU::CS1::select(n24 compare) const -> bool { if(!enable) return false; - return !(uint24)((compare ^ address) & ~mask); + return !(n24)((compare ^ address) & ~mask); } /* CS2: (chip select 2) * Not connected and not used. */ -auto CPU::CS2::select(uint24 compare) const -> bool { +auto CPU::CS2::select(n24 compare) const -> bool { if(!enable) return false; //TMP95C061 range is 000080-ffffff //however, the Neo Geo Pocket maps I/O registers from 000000-0000ff //the exact range is unknown, so it is a guess that the range was expanded here if(!mode) return compare >= 0x000100; - return !(uint24)((compare ^ address) & ~mask); + return !(n24)((compare ^ address) & ~mask); } /* CS3: (chip select 3) * Not connected and not used. */ -auto CPU::CS3::select(uint24 compare) const -> bool { +auto CPU::CS3::select(n24 compare) const -> bool { if(!enable) return false; - return !(uint24)((compare ^ address) & ~mask); + return !(n24)((compare ^ address) & ~mask); } /* CSX: (chip select external) * Not connected and not used. */ -auto CPU::width(uint24 address) -> uint { +auto CPU::width(n24 address) -> u32 { if( io.select(address)) return io.width; if( rom.select(address)) return rom.width; if(cram.select(address)) return cram.width; @@ -246,7 +246,7 @@ auto CPU::width(uint24 address) -> uint { return csx.width; } -auto CPU::read(uint size, uint24 address) -> uint32 { +auto CPU::read(u32 size, n24 address) -> n32 { mar = address; if( io.select(address)) return io.read(size, address); if( rom.select(address)) return rom.read(size, address); @@ -260,7 +260,7 @@ auto CPU::read(uint size, uint24 address) -> uint32 { return csx.read(size, address); } -auto CPU::write(uint size, uint24 address, uint32 data) -> void { +auto CPU::write(u32 size, n24 address, n32 data) -> void { mar = address; mdr = data; if( io.select(address)) return io.write(size, address, data); diff --git a/ares/ngp/cpu/rtc.cpp b/ares/ngp/cpu/rtc.cpp index 7e7a1438e2..a784ed32ae 100644 --- a/ares/ngp/cpu/rtc.cpp +++ b/ares/ngp/cpu/rtc.cpp @@ -1,4 +1,4 @@ -auto CPU::RTC::step(uint clocks) -> void { +auto CPU::RTC::step(u32 clocks) -> void { counter += clocks; while(counter >= cpu.frequency()) { counter -= cpu.frequency(); @@ -8,43 +8,43 @@ auto CPU::RTC::step(uint clocks) -> void { //if it is anything like the Epson RTC-4513, the answer could be quite horrifying second += 1; - if((uint4)second <= 0x09) continue; + if((n4)second <= 0x09) continue; second += 6; //BCD adjust: 0x0a -> 0x10 - if((uint8)second <= 0x59) continue; + if((n8)second <= 0x59) continue; second = 0; minute++; - if((uint4)minute <= 0x09) continue; + if((n4)minute <= 0x09) continue; minute += 6; - if((uint8)minute <= 0x59) continue; + if((n8)minute <= 0x59) continue; minute = 0; hour++; - if((uint4)hour >= 0x0a) hour += 6; - if((uint8)hour <= 0x23) continue; + if((n4)hour >= 0x0a) hour += 6; + if((n8)hour <= 0x23) continue; hour = 0; weekday++; if(weekday >= 7) weekday = 0; day++; - if((uint4)day >= 0x0a) day += 6; - if((uint8)day <= daysInMonth()) continue; + if((n4)day >= 0x0a) day += 6; + if((n8)day <= daysInMonth()) continue; day = 1; month++; - if((uint4)month >= 0x0a) month += 6; - if((uint8)month <= 0x12) continue; + if((n4)month >= 0x0a) month += 6; + if((n8)month <= 0x12) continue; month = 1; year++; - if((uint4)year >= 0x0a) year += 6; - if((uint4)year <= 0x99) continue; + if((n4)year >= 0x0a) year += 6; + if((n4)year <= 0x99) continue; year = 0; } } -auto CPU::RTC::daysInMonth() -> uint8 { +auto CPU::RTC::daysInMonth() -> n8 { switch(day) { case 0x01: return 0x31; //January case 0x02: return daysInFebruary(); @@ -65,7 +65,7 @@ auto CPU::RTC::daysInMonth() -> uint8 { //the Neo Geo Pocket RTC year only holds two digits, which is meant to track 1991 - 2090 //every year possible has a leap year on the fourth year, so we don't have to support the //rule that every 100 years is not a leap year, except every 400 years is a leap year -auto CPU::RTC::daysInFebruary() -> uint8 { +auto CPU::RTC::daysInFebruary() -> n8 { if((year & 3) == 0) return 0x29; //leap year return 0x28; //regular year } diff --git a/ares/ngp/cpu/timers.cpp b/ares/ngp/cpu/timers.cpp index c0b5c96717..fa5edf5db7 100644 --- a/ares/ngp/cpu/timers.cpp +++ b/ares/ngp/cpu/timers.cpp @@ -1,4 +1,4 @@ -auto CPU::Prescaler::step(uint clocks) -> void { +auto CPU::Prescaler::step(u32 clocks) -> void { if(!enable) return; while(clocks--) { auto latch = counter++; @@ -166,9 +166,9 @@ auto CPU::Timer01::clockT0() -> void { } if(mode == 3) { ++cpu.t0.counter; - if(pwm == 1) cpu.t0.counter = (uint6)cpu.t0.counter; - if(pwm == 2) cpu.t0.counter = (uint7)cpu.t0.counter; - if(pwm == 3) cpu.t0.counter = (uint8)cpu.t0.counter; + if(pwm == 1) cpu.t0.counter = (n6)cpu.t0.counter; + if(pwm == 2) cpu.t0.counter = (n7)cpu.t0.counter; + if(pwm == 3) cpu.t0.counter = (n8)cpu.t0.counter; bool matchT0 = cpu.t0.counter == cpu.t0.compare; bool matchPWM = cpu.t0.counter == 0; if(matchT0 || matchPWM) { @@ -251,9 +251,9 @@ auto CPU::Timer23::clockT2() -> void { } if(mode == 3) { ++cpu.t2.counter; - if(pwm == 1) cpu.t2.counter = (uint6)cpu.t2.counter; - if(pwm == 2) cpu.t2.counter = (uint7)cpu.t2.counter; - if(pwm == 3) cpu.t2.counter = (uint8)cpu.t2.counter; + if(pwm == 1) cpu.t2.counter = (n6)cpu.t2.counter; + if(pwm == 2) cpu.t2.counter = (n7)cpu.t2.counter; + if(pwm == 3) cpu.t2.counter = (n8)cpu.t2.counter; bool matchT2 = cpu.t2.counter == cpu.t2.compare; bool matchPWM = cpu.t2.counter == 0; if(matchT2 || matchPWM) { diff --git a/ares/ngp/cpu/watchdog.cpp b/ares/ngp/cpu/watchdog.cpp index b36f79920e..c55b1b0e62 100644 --- a/ares/ngp/cpu/watchdog.cpp +++ b/ares/ngp/cpu/watchdog.cpp @@ -1,4 +1,4 @@ -auto CPU::Watchdog::step(uint clocks) -> void { +auto CPU::Watchdog::step(u32 clocks) -> void { if(!enable) return; counter += clocks; if(counter < cpu.frequency()) return; diff --git a/ares/ngp/ngp.hpp b/ares/ngp/ngp.hpp index f94cad0e90..0d5a166fdd 100644 --- a/ares/ngp/ngp.hpp +++ b/ares/ngp/ngp.hpp @@ -9,6 +9,7 @@ namespace ares::NeoGeoPocket { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { diff --git a/ares/ngp/psg/psg.cpp b/ares/ngp/psg/psg.cpp index fc929748ad..5ba88a64be 100644 --- a/ares/ngp/psg/psg.cpp +++ b/ares/ngp/psg/psg.cpp @@ -20,8 +20,8 @@ auto PSG::unload() -> void { } auto PSG::main() -> void { - double left = 0.0; - double right = 0.0; + f64 left = 0.0; + f64 right = 0.0; if(psg.enable) { auto channels = T6W28::clock(); @@ -44,7 +44,7 @@ auto PSG::main() -> void { step(1); } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); synchronize(apu); @@ -58,11 +58,11 @@ auto PSG::enableDAC() -> void { psg.enable = 0; } -auto PSG::writeLeftDAC(uint8 data) -> void { +auto PSG::writeLeftDAC(n8 data) -> void { dac.left = data; } -auto PSG::writeRightDAC(uint8 data) -> void { +auto PSG::writeRightDAC(n8 data) -> void { dac.right = data; } @@ -71,7 +71,7 @@ auto PSG::power() -> void { psg = {}; dac = {}; - for(uint level : range(15)) { + for(u32 level : range(15)) { volume[level] = pow(2, level * -2.0 / 6.0); } volume[15] = 0; diff --git a/ares/ngp/psg/psg.hpp b/ares/ngp/psg/psg.hpp index ca58b3614d..28c3a06baf 100644 --- a/ares/ngp/psg/psg.hpp +++ b/ares/ngp/psg/psg.hpp @@ -7,27 +7,27 @@ struct PSG : T6W28, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto enablePSG() -> void; auto enableDAC() -> void; - auto writeLeftDAC(uint8 data) -> void; - auto writeRightDAC(uint8 data) -> void; + auto writeLeftDAC(n8 data) -> void; + auto writeRightDAC(n8 data) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; struct { - uint1 enable; + n1 enable; } psg; struct DAC { - uint8 left; - uint8 right; + n8 left; + n8 right; } dac; private: - double volume[16]; + f64 volume[16]; }; extern PSG psg; diff --git a/ares/ngp/system/serialization.cpp b/ares/ngp/system/serialization.cpp index 1580e39e96..05ee95821e 100644 --- a/ares/ngp/system/serialization.cpp +++ b/ares/ngp/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/ngp/system/system.cpp b/ares/ngp/system/system.cpp index e438b2bcdb..fbaa8f6ad0 100644 --- a/ares/ngp/system/system.cpp +++ b/ares/ngp/system/system.cpp @@ -2,7 +2,15 @@ namespace ares::NeoGeoPocket { +auto enumerate() -> vector { + return { + "[SNK] Neo Geo Pocket", + "[SNK] Neo Geo Pocket Color", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -27,10 +35,16 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "Neo Geo Pocket" ) information.model = Model::NeoGeoPocket; - if(name == "Neo Geo Pocket Color") information.model = Model::NeoGeoPocketColor; + if(name.find("Neo Geo Pocket")) { + information.name = "Neo Geo Pocket"; + information.model = Model::NeoGeoPocket; + } + if(name.find("Neo Geo Pocket Color")) { + information.name = "Neo Geo Pocket Color"; + information.model = Model::NeoGeoPocketColor; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); diff --git a/ares/ngp/system/system.hpp b/ares/ngp/system/system.hpp index a681beb04f..607fbedb1e 100644 --- a/ares/ngp/system/system.hpp +++ b/ares/ngp/system/system.hpp @@ -26,12 +26,12 @@ struct System { bool rightLatch = 0; } controls; - enum class Model : uint { NeoGeoPocket, NeoGeoPocketColor }; - Memory::Readable bios; + enum class Model : u32 { NeoGeoPocket, NeoGeoPocketColor }; + Memory::Readable bios; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } - auto frequency() const -> double { return 6'144'000; } + auto frequency() const -> f64 { return 6'144'000; } //system.cpp auto game() -> string; @@ -48,6 +48,7 @@ struct System { private: struct Information { + string name; Model model = Model::NeoGeoPocket; } information; diff --git a/ares/ngp/vpu/color.cpp b/ares/ngp/vpu/color.cpp index 152088e328..6f618c52b5 100644 --- a/ares/ngp/vpu/color.cpp +++ b/ares/ngp/vpu/color.cpp @@ -1,19 +1,19 @@ -auto VPU::colorNeoGeoPocket(uint32 color) -> uint64 { - uint3 l = color.bit(0,2); +auto VPU::colorNeoGeoPocket(n32 color) -> n64 { + n3 l = color.bit(0,2); - natural L = image::normalize(7 - l, 3, 16); + n64 L = image::normalize(7 - l, 3, 16); return L << 32 | L << 16 | L << 0; } -auto VPU::colorNeoGeoPocketColor(uint32 color) -> uint64 { - uint r = color.bit(0, 3); - uint g = color.bit(4, 7); - uint b = color.bit(8,11); +auto VPU::colorNeoGeoPocketColor(n32 color) -> n64 { + n4 r = color.bit(0, 3); + n4 g = color.bit(4, 7); + n4 b = color.bit(8,11); - natural R = image::normalize(r, 4, 16); - natural G = image::normalize(g, 4, 16); - natural B = image::normalize(b, 4, 16); + n64 R = image::normalize(r, 4, 16); + n64 G = image::normalize(g, 4, 16); + n64 B = image::normalize(b, 4, 16); return R << 32 | G << 16 | B << 0; } diff --git a/ares/ngp/vpu/memory.cpp b/ares/ngp/vpu/memory.cpp index b914ceeaa6..e445f1119f 100644 --- a/ares/ngp/vpu/memory.cpp +++ b/ares/ngp/vpu/memory.cpp @@ -1,12 +1,12 @@ -auto VPU::read(uint24 address) -> uint8 { - address = 0x8000 | (uint14)address; +auto VPU::read(n24 address) -> n8 { + address = 0x8000 | (n14)address; if(address >= 0x8200 && address <= 0x83ff && Model::NeoGeoPocketColor()) return readColor(address); if(address >= 0x8800 && address <= 0x88ff) return readSprite(address); if(address >= 0x8c00 && address <= 0x8c3f && Model::NeoGeoPocketColor()) return readSpriteColor(address); if(address >= 0x9000 && address <= 0x9fff) return readAttribute(address); if(address >= 0xa000 && address <= 0xbfff) return readCharacter(address); - uint8 data = 0x00; + n8 data = 0x00; switch(address) { case 0x8000: @@ -93,8 +93,8 @@ auto VPU::read(uint24 address) -> uint8 { return data; } -auto VPU::write(uint24 address, uint8 data) -> void { - address = 0x8000 | (uint14)address; +auto VPU::write(n24 address, n8 data) -> void { + address = 0x8000 | (n14)address; if(address >= 0x8200 && address <= 0x83ff && Model::NeoGeoPocketColor()) return writeColor(address, data); if(address >= 0x8800 && address <= 0x88ff) return writeSprite(address, data); if(address >= 0x8c00 && address <= 0x8cff && Model::NeoGeoPocketColor()) return writeSpriteColor(address, data); @@ -180,7 +180,7 @@ auto VPU::write(uint24 address, uint8 data) -> void { } } -auto VPU::readSprite(uint8 address) -> uint8 { +auto VPU::readSprite(n8 address) -> n8 { auto& s = sprites[address >> 2]; switch(address & 3) { case 0: return s.character; @@ -191,7 +191,7 @@ auto VPU::readSprite(uint8 address) -> uint8 { unreachable; } -auto VPU::writeSprite(uint8 address, uint8 data) -> void { +auto VPU::writeSprite(n8 address, n8 data) -> void { auto& s = sprites[address >> 2]; switch(address & 3) { case 0: @@ -215,15 +215,15 @@ auto VPU::writeSprite(uint8 address, uint8 data) -> void { } } -auto VPU::readSpriteColor(uint6 address) -> uint8 { +auto VPU::readSpriteColor(n6 address) -> n8 { return sprites[address].code; //d4-d7 = 0 } -auto VPU::writeSpriteColor(uint6 address, uint8 data) -> void { +auto VPU::writeSpriteColor(n6 address, n8 data) -> void { sprites[address].code = data.bit(0,3); } -auto VPU::readColor(uint9 address) -> uint8 { +auto VPU::readColor(n9 address) -> n8 { auto& p = colors[address >> 1]; if(!address.bit(0)) { return p.bit(0, 7); @@ -232,7 +232,7 @@ auto VPU::readColor(uint9 address) -> uint8 { } } -auto VPU::writeColor(uint9 address, uint8 data) -> void { +auto VPU::writeColor(n9 address, n8 data) -> void { auto& p = colors[address >> 1]; if(!address.bit(0)) { p.bit(0, 7) = data.bit(0,7); @@ -241,7 +241,7 @@ auto VPU::writeColor(uint9 address, uint8 data) -> void { } } -auto VPU::readAttribute(uint12 address) -> uint8 { +auto VPU::readAttribute(n12 address) -> n8 { auto& a = attributes[address >> 1]; if(!address.bit(0)) { return a.character.bit(0,7); @@ -250,7 +250,7 @@ auto VPU::readAttribute(uint12 address) -> uint8 { } } -auto VPU::writeAttribute(uint12 address, uint8 data) -> void { +auto VPU::writeAttribute(n12 address, n8 data) -> void { auto& a = attributes[address >> 1]; if(!address.bit(0)) { a.character.bit(0,7) = data.bit(0,7); @@ -263,11 +263,11 @@ auto VPU::writeAttribute(uint12 address, uint8 data) -> void { } } -auto VPU::readCharacter(uint13 address) -> uint8 { +auto VPU::readCharacter(n13 address) -> n8 { auto& c = characters[address >> 4]; - uint3 y = address >> 1; - uint3 x = address >> 0 << 2; - uint8 data; + n3 y = address >> 1; + n3 x = address >> 0 << 2; + n8 data; data.bit(0,1) = c[y][x++]; data.bit(2,3) = c[y][x++]; data.bit(4,5) = c[y][x++]; @@ -275,10 +275,10 @@ auto VPU::readCharacter(uint13 address) -> uint8 { return data; } -auto VPU::writeCharacter(uint13 address, uint8 data) -> void { +auto VPU::writeCharacter(n13 address, n8 data) -> void { auto& c = characters[address >> 4]; - uint3 y = address >> 1; - uint3 x = address >> 0 << 2; + n3 y = address >> 1; + n3 x = address >> 0 << 2; c[y][x++] = data.bit(0,1); c[y][x++] = data.bit(2,3); c[y][x++] = data.bit(4,5); diff --git a/ares/ngp/vpu/plane.cpp b/ares/ngp/vpu/plane.cpp index 47f0e40c69..1dfc69047e 100644 --- a/ares/ngp/vpu/plane.cpp +++ b/ares/ngp/vpu/plane.cpp @@ -1,19 +1,19 @@ -auto VPU::renderPlane(uint8 x, uint8 y, Plane& plane) -> bool { +auto VPU::renderPlane(n8 x, n8 y, Plane& plane) -> bool { x += plane.hscroll; y += plane.vscroll; - uint address = plane.address; + u32 address = plane.address; address += (y >> 3) << 6; address += (x >> 3) << 1; - x = (uint3)x; - y = (uint3)y; + x = (n3)x; + y = (n3)y; auto& a = attributes[address >> 1]; if(a.hflip == 0) x ^= 7; if(a.vflip == 1) y ^= 7; - if(uint2 index = characters[a.character][y][x]) { + if(n2 index = characters[a.character][y][x]) { plane.priority = (&plane == &vpu.plane1) ^ vpu.io.planePriority; if(Model::NeoGeoPocket()) { if(index) plane.output = plane.palette[a.palette][index]; diff --git a/ares/ngp/vpu/sprite.cpp b/ares/ngp/vpu/sprite.cpp index 7399200c64..3424a84546 100644 --- a/ares/ngp/vpu/sprite.cpp +++ b/ares/ngp/vpu/sprite.cpp @@ -4,22 +4,22 @@ //writing to VRAM during active display is not emulated, nor is the exact timing //of the caching used by real hardware, as this information is not currently known. -auto VPU::cacheSprites(uint8 ly) -> void { +auto VPU::cacheSprites(n8 ly) -> void { tileCount = 0; - uint8 px = 0; - uint8 py = 0; + n8 px = 0; + n8 py = 0; for(auto& s : sprites) { - uint8 sx = s.hoffset; - uint8 sy = s.voffset; + n8 sx = s.hoffset; + n8 sy = s.voffset; if(s.hchain) sx += px; if(s.vchain) sy += py; px = sx; py = sy; if(s.priority == 0) continue; - uint8 x = sx + sprite.hscroll + 7; - uint8 y = sy + sprite.vscroll + 7 - ly; + n8 x = sx + sprite.hscroll + 7; + n8 y = sy + sprite.vscroll + 7 - ly; if(y >= 8) continue; //out of range? if(s.vflip == 0) y ^= 7; @@ -27,16 +27,16 @@ auto VPU::cacheSprites(uint8 ly) -> void { } } -auto VPU::renderSprite(uint8 lx) -> bool { - for(uint tileIndex : range(tileCount)) { +auto VPU::renderSprite(n8 lx) -> bool { + for(u32 tileIndex : range(tileCount)) { auto& t = tiles[tileIndex]; - uint8 x = t.x - lx; - uint8 y = t.y; + n8 x = t.x - lx; + n8 y = t.y; if(x >= 8) continue; //out of range? if(t.hflip == 1) x ^= 7; //bit endian of tiledata is reversed - if(uint2 index = characters[t.character][y][x]) { + if(n2 index = characters[t.character][y][x]) { sprite.priority = t.priority; if(Model::NeoGeoPocket()) { sprite.output = sprite.palette[t.palette][index]; diff --git a/ares/ngp/vpu/vpu.cpp b/ares/ngp/vpu/vpu.cpp index 65a258e924..fd28a3a9d4 100644 --- a/ares/ngp/vpu/vpu.cpp +++ b/ares/ngp/vpu/vpu.cpp @@ -36,16 +36,16 @@ auto VPU::unload() -> void { auto VPU::main() -> void { if(io.vcounter < 152) { - uint8 y = io.vcounter; + n8 y = io.vcounter; auto line = screen->pixels().data() + y * 160; cacheSprites(y); - for(uint8 x : range(160)) { + for(n8 x : range(160)) { bool validPlane1 = renderPlane(x, y, plane1); bool validPlane2 = renderPlane(x, y, plane2); bool validSprite = renderSprite(x); bool validWindow = renderWindow(x, y); - uint12 color; + n12 color; //the dev manual says only background.mode = 0b10 enables background.color //Ogre Battle however sets 0b00 and expects the background color to be used //as such, it appears that only the lower bit of background.mode matters? @@ -104,7 +104,7 @@ auto VPU::main() -> void { cpu.pollPowerButton(); } -auto VPU::step(uint clocks) -> void { +auto VPU::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); } diff --git a/ares/ngp/vpu/vpu.hpp b/ares/ngp/vpu/vpu.hpp index 5d14e9c37e..551b63576c 100644 --- a/ares/ngp/vpu/vpu.hpp +++ b/ares/ngp/vpu/vpu.hpp @@ -11,141 +11,141 @@ struct VPU : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //memory.cpp - auto read(uint24 address) -> uint8; - auto write(uint24 address, uint8 data) -> void; - auto readSprite(uint8 address) -> uint8; - auto writeSprite(uint8 address, uint8 data) -> void; - auto readSpriteColor(uint6 address) -> uint8; - auto writeSpriteColor(uint6 address, uint8 data) -> void; - auto readColor(uint9 address) -> uint8; - auto writeColor(uint9 address, uint8 data) -> void; - auto readAttribute(uint12 address) -> uint8; - auto writeAttribute(uint12 address, uint8 data) -> void; - auto readCharacter(uint13 address) -> uint8; - auto writeCharacter(uint13 address, uint8 data) -> void; + auto read(n24 address) -> n8; + auto write(n24 address, n8 data) -> void; + auto readSprite(n8 address) -> n8; + auto writeSprite(n8 address, n8 data) -> void; + auto readSpriteColor(n6 address) -> n8; + auto writeSpriteColor(n6 address, n8 data) -> void; + auto readColor(n9 address) -> n8; + auto writeColor(n9 address, n8 data) -> void; + auto readAttribute(n12 address) -> n8; + auto writeAttribute(n12 address, n8 data) -> void; + auto readCharacter(n13 address) -> n8; + auto writeCharacter(n13 address, n8 data) -> void; //window.cpp - auto renderWindow(uint8 x, uint8 y) -> bool; + auto renderWindow(n8 x, n8 y) -> bool; //plane.cpp struct Plane; - auto renderPlane(uint8 x, uint8 y, Plane&) -> bool; + auto renderPlane(n8 x, n8 y, Plane&) -> bool; //sprite.cpp - auto cacheSprites(uint8 y) -> void; - auto renderSprite(uint8 x) -> bool; + auto cacheSprites(n8 y) -> void; + auto renderSprite(n8 x) -> bool; //color.cpp - auto colorNeoGeoPocket(uint32) -> uint64; - auto colorNeoGeoPocketColor(uint32) -> uint64; + auto colorNeoGeoPocket(n32) -> n64; + auto colorNeoGeoPocketColor(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; //private: - uint12 colors[256]; + n12 colors[256]; struct Background { - uint3 color; //K2GE - uint3 unused; //K2GE - uint2 mode; //K2GE + n3 color; //K2GE + n3 unused; //K2GE + n2 mode; //K2GE } background; struct Window { - uint8 hoffset; - uint8 voffset; - uint8 hlength; - uint8 vlength; - uint3 color; //color drawn outside of window + n8 hoffset; + n8 voffset; + n8 hlength; + n8 vlength; + n3 color; //color drawn outside of window - uint12 output; + n12 output; } window; struct Attribute { - uint9 character; - uint4 code; //K2GE - uint1 palette; - uint1 vflip; - uint1 hflip; + n9 character; + n4 code; //K2GE + n1 palette; + n1 vflip; + n1 hflip; } attributes[2048]; - uint2 characters[512][8][8]; + n2 characters[512][8][8]; struct Plane { - uint12 address; - uint8 colorNative; //K2GE - uint8 colorCompatible; //K2GE - uint8 hscroll; - uint8 vscroll; - uint3 palette[2][4]; - - uint12 output; - uint1 priority; + n12 address; + n8 colorNative; //K2GE + n8 colorCompatible; //K2GE + n8 hscroll; + n8 vscroll; + n3 palette[2][4]; + + n12 output; + n1 priority; } plane1, plane2; struct Sprites { - uint8 colorNative; //K2GE - uint8 colorCompatible; //K2GE - uint8 hscroll; - uint8 vscroll; - uint3 palette[2][4]; - - uint12 output; - uint2 priority; + n8 colorNative; //K2GE + n8 colorCompatible; //K2GE + n8 hscroll; + n8 vscroll; + n3 palette[2][4]; + + n12 output; + n2 priority; } sprite; struct Sprite { - uint9 character; - uint1 vchain; - uint1 hchain; - uint2 priority; - uint1 palette; - uint1 vflip; - uint1 hflip; - uint8 hoffset; - uint8 voffset; - uint4 code; //K2GE + n9 character; + n1 vchain; + n1 hchain; + n2 priority; + n1 palette; + n1 vflip; + n1 hflip; + n8 hoffset; + n8 voffset; + n4 code; //K2GE } sprites[64]; struct Tile { - uint8 x; - uint8 y; - uint9 character; - uint2 priority; - uint1 palette; - uint1 hflip; - uint4 code; //K2GE + n8 x; + n8 y; + n9 character; + n2 priority; + n1 palette; + n1 hflip; + n4 code; //K2GE } tiles[64]; - uint8 tileCount; + n8 tileCount; struct LED { - uint8 control = 0x07; - uint8 frequency = 0x80; + n8 control = 0x07; + n8 frequency = 0x80; } led; struct DAC { - uint1 negate; //0 = normal, 1 = inverted display - uint1 colorMode; //0 = K2GE, 1 = K1GE compatible + n1 negate; //0 = normal, 1 = inverted display + n1 colorMode; //0 = K2GE, 1 = K1GE compatible } dac; struct IO { - uint8 vlines = 0xc6; - uint8 vcounter; - uint10 hcounter; + n8 vlines = 0xc6; + n8 vcounter; + n10 hcounter; - uint1 hblankEnableIRQ = 1; //todo: should be 0 - uint1 vblankEnableIRQ = 1; - uint1 hblankActive; - uint1 vblankActive; + n1 hblankEnableIRQ = 1; //todo: should be 0 + n1 vblankEnableIRQ = 1; + n1 hblankActive; + n1 vblankActive; - uint1 characterOver; + n1 characterOver; - uint1 planePriority; //0 = plane1 > plane2; 1 = plane2 > plane1 + n1 planePriority; //0 = plane1 > plane2; 1 = plane2 > plane1 } io; }; diff --git a/ares/ngp/vpu/window.cpp b/ares/ngp/vpu/window.cpp index e5deaa4f32..c0b3fefd30 100644 --- a/ares/ngp/vpu/window.cpp +++ b/ares/ngp/vpu/window.cpp @@ -1,4 +1,4 @@ -auto VPU::renderWindow(uint8 x, uint8 y) -> bool { +auto VPU::renderWindow(n8 x, n8 y) -> bool { if(x >= window.hoffset && y >= window.voffset && x < window.hoffset + window.hlength diff --git a/ares/pce/cartridge/board/arcade-card-duo.cpp b/ares/pce/cartridge/board/arcade-card-duo.cpp index 98721f0459..490baf2be4 100644 --- a/ares/pce/cartridge/board/arcade-card-duo.cpp +++ b/ares/pce/cartridge/board/arcade-card-duo.cpp @@ -1,7 +1,7 @@ struct ArcadeCardDuo : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable dram; + Memory::Readable rom; + Memory::Writable dram; struct Debugger { maybe super; @@ -31,7 +31,7 @@ struct ArcadeCardDuo : Interface { debugger.unload(cartridge.node); } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } @@ -72,7 +72,7 @@ struct ArcadeCardDuo : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { if(bank >= 0x40 && bank <= 0x43) { auto& page = pages[bank - 0x40]; return dram.write(page.address(), data); @@ -125,7 +125,7 @@ struct ArcadeCardDuo : Interface { alu = {}; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(dram); for(auto& page : pages) { @@ -141,8 +141,8 @@ struct ArcadeCardDuo : Interface { } struct Page { - auto address() -> uint21 { - uint21 address = base; + auto address() -> n21 { + n21 address = base; if(control.bit(1) == 1) address += offset + 0xff0000 * control.bit(3); if(control.bit(0) == 1) increment(); return address; @@ -153,15 +153,15 @@ struct ArcadeCardDuo : Interface { if(control.bit(4) == 1) base += adjust; } - uint7 control; - uint24 base; - uint16 offset; - uint16 adjust; + n7 control; + n24 base; + n16 offset; + n16 adjust; } pages[4]; struct ALU { - uint32 value; - uint4 shift; - uint4 rotate; + n32 value; + n4 shift; + n4 rotate; } alu; }; diff --git a/ares/pce/cartridge/board/arcade-card-pro.cpp b/ares/pce/cartridge/board/arcade-card-pro.cpp index c6baa1cd38..e9e08ed4fc 100644 --- a/ares/pce/cartridge/board/arcade-card-pro.cpp +++ b/ares/pce/cartridge/board/arcade-card-pro.cpp @@ -1,8 +1,8 @@ struct ArcadeCardPro : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; - Memory::Writable dram; + Memory::Readable rom; + Memory::Writable ram; + Memory::Writable dram; struct Debugger { maybe super; @@ -34,7 +34,7 @@ struct ArcadeCardPro : Interface { debugger.unload(cartridge.node); } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } @@ -86,7 +86,7 @@ struct ArcadeCardPro : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { if(bank >= 0x40 && bank <= 0x43) { auto& page = pages[bank - 0x40]; return dram.write(page.address(), data); @@ -143,7 +143,7 @@ struct ArcadeCardPro : Interface { alu = {}; } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(ram); s(dram); @@ -160,8 +160,8 @@ struct ArcadeCardPro : Interface { } struct Page { - auto address() -> uint21 { - uint21 address = base; + auto address() -> n21 { + n21 address = base; if(control.bit(1) == 1) address += offset + 0xff0000 * control.bit(3); if(control.bit(0) == 1) increment(); return address; @@ -172,15 +172,15 @@ struct ArcadeCardPro : Interface { if(control.bit(4) == 1) base += adjust; } - uint7 control; - uint24 base; - uint16 offset; - uint16 adjust; + n7 control; + n24 base; + n16 offset; + n16 adjust; } pages[4]; struct ALU { - uint32 value; - uint4 shift; - uint4 rotate; + n32 value; + n4 shift; + n4 rotate; } alu; }; diff --git a/ares/pce/cartridge/board/banked.cpp b/ares/pce/cartridge/board/banked.cpp index 9243f9e8b9..fe6231954c 100644 --- a/ares/pce/cartridge/board/banked.cpp +++ b/ares/pce/cartridge/board/banked.cpp @@ -1,6 +1,6 @@ struct Banked : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -13,19 +13,19 @@ struct Banked : Interface { auto unload() -> void override { } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } if(bank >= 0x40 && bank <= 0x7f) { - return rom.read(1 + romBank << 19 | (uint6)bank << 13 | address); + return rom.read(1 + romBank << 19 | (n6)bank << 13 | address); } return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { if(bank == 0x00 && address >= 0x01ff0 && address <= 0x01ffe) { romBank = address.bit(0,1); } @@ -39,5 +39,5 @@ struct Banked : Interface { s(romBank); } - uint2 romBank; + n2 romBank; }; diff --git a/ares/pce/cartridge/board/board.cpp b/ares/pce/cartridge/board/board.cpp index dc908de7fd..78d5720de8 100644 --- a/ares/pce/cartridge/board/board.cpp +++ b/ares/pce/cartridge/board/board.cpp @@ -10,7 +10,7 @@ namespace Board { #include "arcade-card-pro.cpp" #include "debugger.cpp" -auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); @@ -21,7 +21,7 @@ auto Interface::load(Memory::Readable& memory, Markup::Node node) -> bool return false; } -auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; memory.allocate(node["size"].natural()); if(node["volatile"]) return true; @@ -33,7 +33,7 @@ auto Interface::load(Memory::Writable& memory, Markup::Node node) -> bool return false; } -auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { +auto Interface::save(Memory::Writable& memory, Markup::Node node) -> bool { if(!node) return false; if(node["volatile"]) return true; auto name = string{node["content"].string(), ".", node["type"].string()}.downcase(); diff --git a/ares/pce/cartridge/board/board.hpp b/ares/pce/cartridge/board/board.hpp index f47cde4810..3aff3c2c8f 100644 --- a/ares/pce/cartridge/board/board.hpp +++ b/ares/pce/cartridge/board/board.hpp @@ -6,14 +6,14 @@ struct Interface { virtual auto load(Markup::Node) -> void {} virtual auto save(Markup::Node) -> void {} virtual auto unload() -> void {} - virtual auto read(uint8 bank, uint13 address, uint8 data) -> uint8 { return data; } - virtual auto write(uint8 bank, uint13 address, uint8 data) -> void {} + virtual auto read(n8 bank, n13 address, n8 data) -> n8 { return data; } + virtual auto write(n8 bank, n13 address, n8 data) -> void {} virtual auto power() -> void {} virtual auto serialize(serializer&) -> void {} - auto load(Memory::Readable&, Markup::Node) -> bool; - auto load(Memory::Writable&, Markup::Node) -> bool; - auto save(Memory::Writable&, Markup::Node) -> bool; + auto load(Memory::Readable&, Markup::Node) -> bool; + auto load(Memory::Writable&, Markup::Node) -> bool; + auto save(Memory::Writable&, Markup::Node) -> bool; Cartridge& cartridge; }; diff --git a/ares/pce/cartridge/board/linear.cpp b/ares/pce/cartridge/board/linear.cpp index db76045cfe..05f46fec7c 100644 --- a/ares/pce/cartridge/board/linear.cpp +++ b/ares/pce/cartridge/board/linear.cpp @@ -1,6 +1,6 @@ struct Linear : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -13,7 +13,7 @@ struct Linear : Interface { auto unload() -> void override { } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x7f) { return rom.read(bank << 13 | address); } @@ -21,7 +21,7 @@ struct Linear : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { } auto power() -> void override { diff --git a/ares/pce/cartridge/board/ram.cpp b/ares/pce/cartridge/board/ram.cpp index dc6ea8c155..d5da1c71bf 100644 --- a/ares/pce/cartridge/board/ram.cpp +++ b/ares/pce/cartridge/board/ram.cpp @@ -1,7 +1,7 @@ struct RAM : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; struct Debugger { maybe super; @@ -33,7 +33,7 @@ struct RAM : Interface { debugger.unload(cartridge.node); } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } @@ -45,7 +45,7 @@ struct RAM : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { if(bank >= 0x40 && bank <= 0x43) { return ram.write(bank << 13 | address, data); } diff --git a/ares/pce/cartridge/board/split.cpp b/ares/pce/cartridge/board/split.cpp index 71416503ed..e935ab533c 100644 --- a/ares/pce/cartridge/board/split.cpp +++ b/ares/pce/cartridge/board/split.cpp @@ -1,6 +1,6 @@ struct Split : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -18,8 +18,8 @@ struct Split : Interface { auto unload() -> void override { } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { - uint19 linear = (uint6)bank << 13 | address; + auto read(n8 bank, n13 address, n8 data) -> n8 override { + n19 linear = (n6)bank << 13 | address; if(bank >= 0x00 && bank <= 0x3f) { return rom.read(romAddress[0] + linear); @@ -32,7 +32,7 @@ struct Split : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { } auto power() -> void override { @@ -41,5 +41,5 @@ struct Split : Interface { auto serialize(serializer& s) -> void override { } - uint20 romAddress[2]; + n20 romAddress[2]; }; diff --git a/ares/pce/cartridge/board/super-system-card.cpp b/ares/pce/cartridge/board/super-system-card.cpp index b256d31e5a..584fb0c3b1 100644 --- a/ares/pce/cartridge/board/super-system-card.cpp +++ b/ares/pce/cartridge/board/super-system-card.cpp @@ -1,7 +1,7 @@ struct SuperSystemCard : Interface { using Interface::Interface; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; struct Debugger { maybe super; @@ -31,7 +31,7 @@ struct SuperSystemCard : Interface { debugger.load(cartridge.node); } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } @@ -52,7 +52,7 @@ struct SuperSystemCard : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { if(bank >= 0x68 && bank <= 0x7f) { return ram.write(bank - 0x68 << 13 | address, data); } @@ -61,7 +61,7 @@ struct SuperSystemCard : Interface { auto power() -> void override { } - auto serialize(serializer& s) -> void { + auto serialize(serializer& s) -> void override { s(ram); } }; diff --git a/ares/pce/cartridge/board/system-card.cpp b/ares/pce/cartridge/board/system-card.cpp index 5adfa1e2ba..3db5816199 100644 --- a/ares/pce/cartridge/board/system-card.cpp +++ b/ares/pce/cartridge/board/system-card.cpp @@ -1,6 +1,6 @@ struct SystemCard : Interface { using Interface::Interface; - Memory::Readable rom; + Memory::Readable rom; auto load(Markup::Node document) -> void override { auto board = document["game/board"]; @@ -13,7 +13,7 @@ struct SystemCard : Interface { auto unload() -> void override { } - auto read(uint8 bank, uint13 address, uint8 data) -> uint8 override { + auto read(n8 bank, n13 address, n8 data) -> n8 override { if(bank >= 0x00 && bank <= 0x3f) { return rom.read(bank << 13 | address); } @@ -21,7 +21,7 @@ struct SystemCard : Interface { return data; } - auto write(uint8 bank, uint13 address, uint8 data) -> void override { + auto write(n8 bank, n13 address, n8 data) -> void override { } auto power() -> void override { diff --git a/ares/pce/cartridge/cartridge.cpp b/ares/pce/cartridge/cartridge.cpp index f123a887a6..3b32d6b3c0 100644 --- a/ares/pce/cartridge/cartridge.cpp +++ b/ares/pce/cartridge/cartridge.cpp @@ -64,11 +64,11 @@ auto Cartridge::power() -> void { board->power(); } -auto Cartridge::read(uint8 bank, uint13 address, uint8 data) -> uint8 { +auto Cartridge::read(n8 bank, n13 address, n8 data) -> n8 { return board->read(bank, address, data); } -auto Cartridge::write(uint8 bank, uint13 address, uint8 data) -> void { +auto Cartridge::write(n8 bank, n13 address, n8 data) -> void { return board->write(bank, address, data); } diff --git a/ares/pce/cartridge/cartridge.hpp b/ares/pce/cartridge/cartridge.hpp index 8ea3daf7bf..06a48b605c 100644 --- a/ares/pce/cartridge/cartridge.hpp +++ b/ares/pce/cartridge/cartridge.hpp @@ -17,8 +17,8 @@ struct Cartridge { auto save() -> void; auto power() -> void; - auto read(uint8 bank, uint13 address, uint8 data) -> uint8; - auto write(uint8 bank, uint13 address, uint8 data) -> void; + auto read(n8 bank, n13 address, n8 data) -> n8; + auto write(n8 bank, n13 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/pce/controller/avenuepad/avenuepad.cpp b/ares/pce/controller/avenuepad/avenuepad.cpp index 0e1f825b2c..da6db93135 100644 --- a/ares/pce/controller/avenuepad/avenuepad.cpp +++ b/ares/pce/controller/avenuepad/avenuepad.cpp @@ -15,7 +15,7 @@ AvenuePad::AvenuePad(Node::Port parent) { run = node->append("Run"); } -auto AvenuePad::read() -> uint4 { +auto AvenuePad::read() -> n4 { if(clr) return 0; platform->input(up); @@ -43,7 +43,7 @@ auto AvenuePad::read() -> uint4 { xHold = 1, swap(leftLatch, rightLatch); } - uint4 data; + n4 data; if(active == 0) { if(sel) { @@ -76,7 +76,7 @@ auto AvenuePad::read() -> uint4 { return data; } -auto AvenuePad::write(uint2 data) -> void { +auto AvenuePad::write(n2 data) -> void { //there should be a small delay for this to take effect ... if(!sel && data.bit(0)) active ^= 1; diff --git a/ares/pce/controller/avenuepad/avenuepad.hpp b/ares/pce/controller/avenuepad/avenuepad.hpp index f8177a4aff..7209168f3c 100644 --- a/ares/pce/controller/avenuepad/avenuepad.hpp +++ b/ares/pce/controller/avenuepad/avenuepad.hpp @@ -14,8 +14,8 @@ struct AvenuePad : Controller { AvenuePad(Node::Port); - auto read() -> uint4 override; - auto write(uint2 data) -> void override; + auto read() -> n4 override; + auto write(n2 data) -> void override; private: bool sel = 0; diff --git a/ares/pce/controller/controller.hpp b/ares/pce/controller/controller.hpp index f1caabc6df..9e94c12c0b 100644 --- a/ares/pce/controller/controller.hpp +++ b/ares/pce/controller/controller.hpp @@ -3,8 +3,8 @@ struct Controller : Thread { virtual ~Controller() = default; - virtual auto read() -> uint4 { return 0x0f; } - virtual auto write(uint2) -> void {} + virtual auto read() -> n4 { return 0x0f; } + virtual auto write(n2) -> void {} }; #include "port.hpp" diff --git a/ares/pce/controller/gamepad/gamepad.cpp b/ares/pce/controller/gamepad/gamepad.cpp index e79b93ecdf..78647a579f 100644 --- a/ares/pce/controller/gamepad/gamepad.cpp +++ b/ares/pce/controller/gamepad/gamepad.cpp @@ -11,7 +11,7 @@ Gamepad::Gamepad(Node::Port parent) { run = node->append("Run"); } -auto Gamepad::read() -> uint4 { +auto Gamepad::read() -> n4 { if(clr) return 0; platform->input(up); @@ -35,7 +35,7 @@ auto Gamepad::read() -> uint4 { xHold = 1, swap(leftLatch, rightLatch); } - uint4 data; + n4 data; if(sel) { data.bit(0) = !upLatch; @@ -52,7 +52,7 @@ auto Gamepad::read() -> uint4 { return data; } -auto Gamepad::write(uint2 data) -> void { +auto Gamepad::write(n2 data) -> void { //there should be a small delay for this to take effect ... sel = data.bit(0); clr = data.bit(1); diff --git a/ares/pce/controller/gamepad/gamepad.hpp b/ares/pce/controller/gamepad/gamepad.hpp index e6015b821e..407bbe2fba 100644 --- a/ares/pce/controller/gamepad/gamepad.hpp +++ b/ares/pce/controller/gamepad/gamepad.hpp @@ -10,17 +10,17 @@ struct Gamepad : Controller { Gamepad(Node::Port); - auto read() -> uint4 override; - auto write(uint2 data) -> void override; + auto read() -> n4 override; + auto write(n2 data) -> void override; private: - bool sel = 0; - bool clr = 0; + b1 sel; + b1 clr; - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/pce/controller/port.hpp b/ares/pce/controller/port.hpp index a5f2a7a762..82472892af 100644 --- a/ares/pce/controller/port.hpp +++ b/ares/pce/controller/port.hpp @@ -8,8 +8,8 @@ struct ControllerPort { auto unload() -> void; auto allocate(string name) -> Node::Peripheral; - auto read() -> uint4 { if(device) return device->read(); return 0b1111; } - auto write(uint2 data) -> void { if(device) return device->write(data); } + auto read() -> n4 { if(device) return device->read(); return 0b1111; } + auto write(n2 data) -> void { if(device) return device->write(data); } auto serialize(serializer&) -> void; diff --git a/ares/pce/cpu/cpu.cpp b/ares/pce/cpu/cpu.cpp index 492bf87e03..f5757530b8 100644 --- a/ares/pce/cpu/cpu.cpp +++ b/ares/pce/cpu/cpu.cpp @@ -43,7 +43,7 @@ auto CPU::main() -> void { instruction(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { timer.counter -= clocks; while(timer.counter < 0) { synchronize(psg); @@ -63,8 +63,8 @@ auto CPU::power() -> void { HuC6280::power(); Thread::create(system.colorburst() * 6.0, {&CPU::main, this}); - r.pc.byte(0) = read(r.mpr[reset.vector >> 13], uint13(reset.vector + 0)); - r.pc.byte(1) = read(r.mpr[reset.vector >> 13], uint13(reset.vector + 1)); + r.pc.byte(0) = read(r.mpr[reset.vector >> 13], n13(reset.vector + 0)); + r.pc.byte(1) = read(r.mpr[reset.vector >> 13], n13(reset.vector + 1)); ram.fill(0x00); diff --git a/ares/pce/cpu/cpu.hpp b/ares/pce/cpu/cpu.hpp index d1fde4ef0a..10cff25886 100644 --- a/ares/pce/cpu/cpu.hpp +++ b/ares/pce/cpu/cpu.hpp @@ -2,7 +2,7 @@ struct CPU : HuC6280, Thread { Node::Object node; - Memory::Writable ram; //PC Engine = 8KB, SuperGrafx = 32KB + Memory::Writable ram; //PC Engine = 8KB, SuperGrafx = 32KB struct Debugger { //debugger.cpp @@ -25,57 +25,57 @@ struct CPU : HuC6280, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto power() -> void; auto lastCycle() -> void override; //io.cpp - auto read(uint8 bank, uint13 address) -> uint8 override; - auto write(uint8 bank, uint13 address, uint8 data) -> void override; - auto store(uint2 address, uint8 data) -> void override; + auto read(n8 bank, n13 address) -> n8 override; + auto write(n8 bank, n13 address, n8 data) -> void override; + auto store(n2 address, n8 data) -> void override; //serialization.cpp auto serialize(serializer&) -> void; private: struct IRQ2 { //CD-ROM, BRK instruction - static constexpr uint16_t vector = 0xfff6; - uint1 disable; - uint1 pending; + static constexpr u16 vector = 0xfff6; + n1 disable; + n1 pending; } irq2; struct IRQ1 { //VDC - static constexpr uint16_t vector = 0xfff8; - uint1 disable; - uint1 pending; + static constexpr u16 vector = 0xfff8; + n1 disable; + n1 pending; } irq1; struct TIQ { //Timer - static constexpr uint16_t vector = 0xfffa; - uint1 disable; - uint1 pending; + static constexpr u16 vector = 0xfffa; + n1 disable; + n1 pending; } tiq; struct NMI { //not exposed by the PC Engine - static constexpr uint16_t vector = 0xfffc; + static constexpr u16 vector = 0xfffc; } nmi; struct Reset { - static constexpr uint16_t vector = 0xfffe; + static constexpr u16 vector = 0xfffe; } reset; struct Timer { auto irqLine() const -> bool { return line; } - uint1 line; - uint1 enable; - uint7 reload; - uint7 value; - int32 counter; + n1 line; + n1 enable; + n7 reload; + n7 value; + i32 counter; } timer; struct IO { - uint8 buffer; //latches only on $ff:0800-17ff writes + n8 buffer; //latches only on $ff:0800-17ff writes } io; }; diff --git a/ares/pce/cpu/debugger.cpp b/ares/pce/cpu/debugger.cpp index e50ad44d59..cec181b4f5 100644 --- a/ares/pce/cpu/debugger.cpp +++ b/ares/pce/cpu/debugger.cpp @@ -17,7 +17,7 @@ auto CPU::Debugger::load(Node::Object parent) -> void { auto CPU::Debugger::instruction() -> void { if(tracer.instruction->enabled()) { auto bank = cpu.r.mpr[cpu.r.pc >> 13]; - auto address = (uint13)cpu.r.pc; + auto address = (n13)cpu.r.pc; if(tracer.instruction->address(bank << 16 | address)) { tracer.instruction->notify(cpu.disassembleInstruction(), cpu.disassembleContext(), { "V:", pad(vdp.io.vcounter, 3L), " ", "H:", pad(vdp.io.hcounter, 4L) diff --git a/ares/pce/cpu/io.cpp b/ares/pce/cpu/io.cpp index 9c178cf8f3..9fe1b0e8d4 100644 --- a/ares/pce/cpu/io.cpp +++ b/ares/pce/cpu/io.cpp @@ -1,5 +1,5 @@ -auto CPU::read(uint8 bank, uint13 address) -> uint8 { - uint8 data = 0xff; +auto CPU::read(n8 bank, n13 address) -> n8 { + n8 data = 0xff; //$00-7f HuCard or PC Engine Duo //$80-87 CD WRAM @@ -99,7 +99,7 @@ auto CPU::read(uint8 bank, uint13 address) -> uint8 { return data; } -auto CPU::write(uint8 bank, uint13 address, uint8 data) -> void { +auto CPU::write(n8 bank, n13 address, n8 data) -> void { //$00-7f HuCard or PC Engine Duo //$80-87 CD WRAM //$f7 CD BRAM @@ -186,7 +186,7 @@ auto CPU::write(uint8 bank, uint13 address, uint8 data) -> void { } //ST0, ST1, ST2 -auto CPU::store(uint2 address, uint8 data) -> void { +auto CPU::store(n2 address, n8 data) -> void { if(address) address++; //0,1,2 => 0,2,3 if(Model::SuperGrafx() == 0) vdp.vdc0.write(address, data); if(Model::SuperGrafx() == 1) vdp.vpc.store(address, data); diff --git a/ares/pce/pcd/adpcm.cpp b/ares/pce/pcd/adpcm.cpp index 9f1199fadb..248cffcdf2 100644 --- a/ares/pce/pcd/adpcm.cpp +++ b/ares/pce/pcd/adpcm.cpp @@ -42,7 +42,7 @@ auto PCD::ADPCM::clock() -> void { } auto PCD::ADPCM::clockSample() -> void { - stream->frame((io.playing ? msm5205.sample() : (int12)0) * fader->adpcm() / 2048.0); + stream->frame((io.playing ? msm5205.sample() : (i12)0) * fader->adpcm() / 2048.0); if(++period < divider) return; period = 0; @@ -65,7 +65,7 @@ auto PCD::ADPCM::clockSample() -> void { } } -auto PCD::ADPCM::control(uint8 data) -> void { +auto PCD::ADPCM::control(n8 data) -> void { io.writeOffset = data.bit(0); if(!io.writeLatch && data.bit(1)) { write.address = latch - !io.writeOffset; diff --git a/ares/pce/pcd/drive.cpp b/ares/pce/pcd/drive.cpp index b5117dc99d..9af31dbc00 100644 --- a/ares/pce/pcd/drive.cpp +++ b/ares/pce/pcd/drive.cpp @@ -1,6 +1,6 @@ //computes the number of 75hz intervals required to seek to a given sector. //the logarithm is based on observed results from a TurboDuo, and errs on seeking too fast. -auto PCD::Drive::distance() -> uint { +auto PCD::Drive::distance() -> u32 { auto distance = abs(lba - start); return 17 + pow(sqrt(distance), 0.99) * 0.3; } diff --git a/ares/pce/pcd/io.cpp b/ares/pce/pcd/io.cpp index 62dd06dcc1..dcb874483c 100644 --- a/ares/pce/pcd/io.cpp +++ b/ares/pce/pcd/io.cpp @@ -1,4 +1,4 @@ -auto PCD::read(uint8 bank, uint13 address, uint8 data) -> uint8 { +auto PCD::read(n8 bank, n13 address, n8 data) -> n8 { if(bank >= 0x00 && bank <= 0x3f && Model::PCEngineDuo()) { return bios.read(address); } @@ -18,7 +18,7 @@ auto PCD::read(uint8 bank, uint13 address, uint8 data) -> uint8 { return data; } -auto PCD::write(uint8 bank, uint13 address, uint8 data) -> void { +auto PCD::write(n8 bank, n13 address, n8 data) -> void { if(bank >= 0x68 && bank <= 0x7f && Model::PCEngineDuo() && sramEnable()) { return sram.write(bank - 0x68 << 13 | address, data); } @@ -32,7 +32,7 @@ auto PCD::write(uint8 bank, uint13 address, uint8 data) -> void { } } -auto PCD::readIO(uint13 address, uint8 data) -> uint8 { +auto PCD::readIO(n13 address, n8 data) -> n8 { if(address == 0x18c0 && Model::PCEngineDuo()) return 0x00; if(address == 0x18c1 && Model::PCEngineDuo()) return 0xaa; if(address == 0x18c2 && Model::PCEngineDuo()) return 0x55; @@ -40,7 +40,7 @@ auto PCD::readIO(uint13 address, uint8 data) -> uint8 { if(address >= 0x18c4) return data; scsi.update(); - address = (uint4)address; + address = (n4)address; data = io.mdr[address]; if(address == 0x0) { @@ -145,11 +145,11 @@ auto PCD::readIO(uint13 address, uint8 data) -> uint8 { return data; } -auto PCD::writeIO(uint13 address, uint8 data) -> void { +auto PCD::writeIO(n13 address, n8 data) -> void { if(address == 0x18c0) io.sramEnable = io.sramEnable << 8 | data; if(address >= 0x18c4) return; - address = (uint4)address; + address = (n4)address; //print("* wr ff:180", hex(address, 1L), " = ", hex(data, 2L), "\n"); diff --git a/ares/pce/pcd/pcd.cpp b/ares/pce/pcd/pcd.cpp index c7d937d3c6..68a170c28c 100644 --- a/ares/pce/pcd/pcd.cpp +++ b/ares/pce/pcd/pcd.cpp @@ -81,10 +81,10 @@ auto PCD::connect() -> void { if(!fd) return disconnect(); //read TOC (table of contents) from disc lead-in - uint sectors = min(7500, fd->size() / 2448); - vector subchannel; + u32 sectors = fd->size() / 2448; + vector subchannel; subchannel.resize(sectors * 96); - for(uint sector : range(sectors)) { + for(u32 sector : range(sectors)) { fd->seek(sector * 2448 + 2352); fd->read(subchannel.data() + sector * 96, 96); } @@ -130,7 +130,7 @@ auto PCD::main() -> void { step(1); } -auto PCD::step(uint clocks) -> void { +auto PCD::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } diff --git a/ares/pce/pcd/pcd.hpp b/ares/pce/pcd/pcd.hpp index 2075650e9f..ef425ba4da 100644 --- a/ares/pce/pcd/pcd.hpp +++ b/ares/pce/pcd/pcd.hpp @@ -6,11 +6,11 @@ struct PCD : Thread { Node::Peripheral disc; Shared::File fd; CD::Session session; - Memory::Writable wram; // 64KB - Memory::Writable bram; // 2KB + Memory::Writable wram; // 64KB + Memory::Writable bram; // 2KB //PC Engine Duo only: - Memory::Readable bios; //256KB - Memory::Writable sram; //192KB + Memory::Readable bios; //256KB + Memory::Writable sram; //192KB struct Debugger { //debugger.cpp @@ -41,16 +41,16 @@ struct PCD : Thread { auto save() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto irqLine() const -> bool; auto power() -> void; //io.cpp - auto read(uint8 bank, uint13 address, uint8 data) -> uint8; - auto write(uint8 bank, uint13 address, uint8 data) -> void; + auto read(n8 bank, n13 address, n8 data) -> n8; + auto write(n8 bank, n13 address, n8 data) -> void; - auto readIO(uint13 address, uint8 data) -> uint8; - auto writeIO(uint13 address, uint8 data) -> void; + auto readIO(n13 address, n8 data) -> n8; + auto writeIO(n13 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -61,19 +61,19 @@ struct PCD : Thread { auto raise() -> void { line = 1; } auto lower() -> void { line = 0; } - uint1 enable; - uint1 line; + n1 enable; + n1 line; }; struct Buffer { auto reset() -> void { reads = 0; writes = 0; } auto end() const -> bool { return reads >= writes; } - auto read() -> uint8 { return data[reads++]; } - auto write(uint8 value) -> void { data[writes++] = value; } + auto read() -> n8 { return data[reads++]; } + auto write(n8 value) -> void { data[writes++] = value; } - uint8 data[4_KiB]; - uint12 reads; - uint12 writes; + n8 data[4_KiB]; + n12 reads; + n12 writes; }; struct Drive; @@ -85,7 +85,7 @@ struct PCD : Thread { struct Drive { maybe session; - enum class Mode : uint { + enum class Mode : u32 { Inactive, //drive is not running Seeking, //seeking Reading, //reading CD data @@ -118,7 +118,7 @@ struct PCD : Thread { } //drive.cpp - auto distance() -> uint; + auto distance() -> u32; auto seekRead() -> void; auto seekPlay() -> void; auto seekPause() -> void; @@ -128,13 +128,13 @@ struct PCD : Thread { //serialization.cpp auto serialize(serializer&) -> void; - Mode mode = Mode::Inactive; //current drive mode - Mode seek = Mode::Inactive; //which mode to enter after seeking is completed - uint latency = 0; //how many 75hz cycles are remaining in seek mode - int lba = 0; //wnere the laser is currently at - int start = 0; //where the laser should start reading - int end = 0; //where the laser should stop reading - uint8 sector[2448]; //contains the most recently read disc sector + Mode mode = Mode::Inactive; //current drive mode + Mode seek = Mode::Inactive; //which mode to enter after seeking is completed + u32 latency = 0; //how many 75hz cycles are remaining in seek mode + s32 lba = 0; //wnere the laser is currently at + s32 start = 0; //where the laser should start reading + s32 end = 0; //where the laser should stop reading + n8 sector[2448]; //contains the most recently read disc sector } drive; struct SCSI { @@ -142,13 +142,13 @@ struct PCD : Thread { maybe drive; maybe cdda; maybe adpcm; - enum class Status : uint { OK, CheckCondition }; + enum class Status : u32 { OK, CheckCondition }; //scsi.cpp auto clock() -> void; auto clockSector() -> void; - auto clockSample() -> maybe; - auto readData() -> uint8; + auto clockSample() -> maybe; + auto readData() -> n8; auto update() -> void; auto messageInput() -> void; auto messageOutput() -> void; @@ -174,26 +174,26 @@ struct PCD : Thread { } irq; struct Pin { - uint1 reset; //RST - uint1 acknowledge; //ACK - uint1 select; //SEL (1 = bus select requested) - uint1 input; //I/O (1 = input, 0 = output) - uint1 control; //C/D (1 = control, 0 = data) - uint1 message; //MSG - uint1 request; //REQ - uint1 busy; //BSY + n1 reset; //RST + n1 acknowledge; //ACK + n1 select; //SEL (1 = bus select requested) + n1 input; //I/O (1 = input, 0 = output) + n1 control; //C/D (1 = control, 0 = data) + n1 message; //MSG + n1 request; //REQ + n1 busy; //BSY } pin; struct Bus { - uint1 select; //1 = bus is currently selected - uint8 data; //D0-D7 + n1 select; //1 = bus is currently selected + n8 data; //D0-D7 } bus; - uint8 acknowledging; - uint1 dataTransferCompleted; - uint1 messageAfterStatus; - uint1 messageSent; - uint1 statusSent; + n8 acknowledging; + n1 dataTransferCompleted; + n1 messageAfterStatus; + n1 messageSent; + n1 statusSent; Buffer request; Buffer response; @@ -216,12 +216,12 @@ struct PCD : Thread { //serialization.cpp auto serialize(serializer&) -> void; - enum class PlayMode : uint { Loop, IRQ, Once } playMode = PlayMode::Loop; + enum class PlayMode : u32 { Loop, IRQ, Once } playMode = PlayMode::Loop; struct Sample { - int16 left; - int16 right; - uint12 offset; + i16 left; + i16 right; + n12 offset; } sample; } cdda; @@ -230,10 +230,10 @@ struct PCD : Thread { maybe fader; MSM5205 msm5205; Node::Audio::Stream stream; - Memory::Writable memory; //64KB + Memory::Writable memory; //64KB - static constexpr uint ReadLatency = 20; //estimation - static constexpr uint WriteLatency = 20; //estimation + static constexpr u32 ReadLatency = 20; //estimation + static constexpr u32 WriteLatency = 20; //estimation //adpcm.cpp auto load(Node::Object) -> void; @@ -241,7 +241,7 @@ struct PCD : Thread { auto clock() -> void; auto clockSample() -> void; - auto control(uint8 data) -> void; + auto control(n8 data) -> void; auto power() -> void; //serialization.cpp @@ -253,39 +253,39 @@ struct PCD : Thread { } irq; struct IO { - uint1 writeOffset; - uint1 writeLatch; - uint1 readLatch; - uint1 readOffset; - uint1 lengthLatch; - uint1 playing; - uint1 noRepeat; //0 = do not stop playing when length reaches zero - uint1 reset; + n1 writeOffset; + n1 writeLatch; + n1 readLatch; + n1 readOffset; + n1 lengthLatch; + n1 playing; + n1 noRepeat; //0 = do not stop playing when length reaches zero + n1 reset; } io; struct Bus { - uint16 address; - uint8 data; - uint8 pending; + n16 address; + n8 data; + n8 pending; } read, write; struct Sample { - uint8 data; - uint1 nibble; + n8 data; + n1 nibble; } sample; - uint2 dmaActive; - uint8 divider; //0x01-0x10 - uint8 period; //count-up for divider - uint16 latch; - uint16 length; + n2 dmaActive; + n8 divider; //0x01-0x10 + n8 period; //count-up for divider + n16 latch; + n16 length; } adpcm; struct Fader { - enum class Mode : uint { Idle, CDDA, ADPCM }; + enum class Mode : u32 { Idle, CDDA, ADPCM }; - auto cdda() const -> double { return mode == Mode::CDDA ? volume : 1.0; } - auto adpcm() const -> double { return mode == Mode::ADPCM ? volume : 1.0; } + auto cdda() const -> f64 { return mode == Mode::CDDA ? volume : 1.0; } + auto adpcm() const -> f64 { return mode == Mode::ADPCM ? volume : 1.0; } //fader.cpp auto clock() -> void; @@ -295,22 +295,22 @@ struct PCD : Thread { auto serialize(serializer&) -> void; Mode mode; - double step; - double volume; + f64 step; + f64 volume; } fader; struct Clock { - uint32 drive; - uint32 cdda; - uint32 adpcm; - uint32 fader; + n32 drive; + n32 cdda; + n32 adpcm; + n32 fader; } clock; struct IO { - uint8 mdr[16]; - uint1 cddaSampleSelect; - uint16 sramEnable; - uint1 bramEnable; + n8 mdr[16]; + n1 cddaSampleSelect; + n16 sramEnable; + n1 bramEnable; } io; //unserialized: diff --git a/ares/pce/pcd/scsi.cpp b/ares/pce/pcd/scsi.cpp index 53767184c8..6a70ce4416 100644 --- a/ares/pce/pcd/scsi.cpp +++ b/ares/pce/pcd/scsi.cpp @@ -12,7 +12,7 @@ auto PCD::SCSI::clockSector() -> void { if(!drive->read()) return; response.reset(); - for(uint offset : range(2048)) { + for(u32 offset : range(2048)) { response.write(drive->sector[16 + offset]); } @@ -21,15 +21,15 @@ auto PCD::SCSI::clockSector() -> void { dataTransferCompleted = drive->inactive(); } -auto PCD::SCSI::clockSample() -> maybe { +auto PCD::SCSI::clockSample() -> maybe { if(pin.request && !pin.acknowledge && !pin.control && pin.input) { return readData(); } return {}; } -auto PCD::SCSI::readData() -> uint8 { - uint8 result = bus.data; +auto PCD::SCSI::readData() -> n8 { + n8 result = bus.data; if(pin.request && !pin.acknowledge && !pin.control && pin.input) { pin.acknowledge = 1; @@ -219,7 +219,7 @@ auto PCD::SCSI::commandReadData() -> void { auto PCD::SCSI::commandAudioSetStartPosition() -> void { if(!pcd.fd) return reply(Status::CheckCondition); - maybe lba; + maybe lba; if(request.data[9].bit(6,7) == 0) { lba = request.data[3] << 16 | request.data[4] << 8 | request.data[5] << 0; @@ -269,7 +269,7 @@ auto PCD::SCSI::commandAudioSetStartPosition() -> void { auto PCD::SCSI::commandAudioSetStopPosition() -> void { if(!pcd.fd) return reply(Status::CheckCondition); - maybe lba; + maybe lba; if(request.data[9].bit(6,7) == 0) { lba = request.data[3] << 16 | request.data[4] << 8 | request.data[5] << 0; @@ -337,12 +337,12 @@ auto PCD::SCSI::commandReadSubchannel() -> void { //1 = inactive //2 = paused //3 = stopped - uint8 mode = 1; + n8 mode = 1; if(drive->playing()) mode = 0; if(drive->paused()) mode = 2; if(drive->stopped()) mode = 3; - array_view q{pcd.drive.sector + 2364, 12}; + array_view q{pcd.drive.sector + 2364, 12}; response.write(mode); //CDDA mode response.write(q[0]); //control + address response.write(q[1]); //track# diff --git a/ares/pce/pcd/serialization.cpp b/ares/pce/pcd/serialization.cpp index cebce0a625..9388661dc0 100644 --- a/ares/pce/pcd/serialization.cpp +++ b/ares/pce/pcd/serialization.cpp @@ -21,8 +21,8 @@ auto PCD::serialize(serializer& s) -> void { } auto PCD::Drive::serialize(serializer& s) -> void { - s((uint&)mode); - s((uint&)seek); + s((u32&)mode); + s((u32&)seek); s(latency); s(lba); s(start); @@ -64,7 +64,7 @@ auto PCD::SCSI::serialize(serializer& s) -> void { } auto PCD::CDDA::serialize(serializer& s) -> void { - s((uint&)playMode); + s((u32&)playMode); s(sample.left); s(sample.right); s(sample.offset); @@ -107,7 +107,7 @@ auto PCD::ADPCM::serialize(serializer& s) -> void { } auto PCD::Fader::serialize(serializer& s) -> void { - s((uint&)mode); + s((u32&)mode); s(step); s(volume); } diff --git a/ares/pce/pce.hpp b/ares/pce/pce.hpp index 0f0dd25199..1d333280d1 100644 --- a/ares/pce/pce.hpp +++ b/ares/pce/pce.hpp @@ -8,6 +8,7 @@ namespace ares::PCEngine { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Model { diff --git a/ares/pce/psg/channel.cpp b/ares/pce/psg/channel.cpp index 3f74bb16bf..05ed5b801c 100644 --- a/ares/pce/psg/channel.cpp +++ b/ares/pce/psg/channel.cpp @@ -1,4 +1,4 @@ -auto PSG::Channel::power(uint id) -> void { +auto PSG::Channel::power(u32 id) -> void { this->id = id; io = {}; } @@ -24,6 +24,6 @@ auto PSG::Channel::run() -> void { return sample(io.noiseSample); } -auto PSG::Channel::sample(uint5 sample) -> void { +auto PSG::Channel::sample(n5 sample) -> void { io.output = sample; } diff --git a/ares/pce/psg/io.cpp b/ares/pce/psg/io.cpp index 0c16ea8d8c..a066e032d3 100644 --- a/ares/pce/psg/io.cpp +++ b/ares/pce/psg/io.cpp @@ -1,4 +1,4 @@ -auto PSG::write(uint4 address, uint8 data) -> void { +auto PSG::write(n4 address, n8 data) -> void { if(address == 0x00) { io.channel = data.bit(0,2); } @@ -29,7 +29,7 @@ auto PSG::write(uint4 address, uint8 data) -> void { } } -auto PSG::Channel::write(uint4 address, uint8 data) -> void { +auto PSG::Channel::write(n4 address, n8 data) -> void { if(address == 0x02) { io.waveFrequency.bit(0,7) = data.bit(0,7); io.wavePeriod = io.waveFrequency; diff --git a/ares/pce/psg/psg.cpp b/ares/pce/psg/psg.cpp index 812a3c326b..bf8b37b1be 100644 --- a/ares/pce/psg/psg.cpp +++ b/ares/pce/psg/psg.cpp @@ -27,8 +27,8 @@ auto PSG::unload() -> void { } auto PSG::main() -> void { - int16 outputLeft; - int16 outputRight; + i16 outputLeft; + i16 outputRight; #if defined(PROFILE_ACCURACY) frame(outputLeft, outputRight); @@ -39,14 +39,14 @@ auto PSG::main() -> void { #if defined(PROFILE_PERFORMANCE) //3.57MHz stereo audio through a 6th-order biquad IIR filter is very demanding. //decimate the audio to ~56KHz, which is still well above the range of human hearing. - for(uint n : range(64)) frame(outputLeft, outputRight); + for(u32 n : range(64)) frame(outputLeft, outputRight); stream->frame(sclamp<16>(outputLeft) / 32768.0, sclamp<16>(outputRight) / 32768.0); step(64); #endif } -auto PSG::frame(int16& outputLeft, int16& outputRight) -> void { - static const uint5 volumeScale[16] = { +auto PSG::frame(i16& outputLeft, i16& outputRight) -> void { + static const n5 volumeScale[16] = { 0x00, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f, 0x10, 0x13, 0x15, 0x17, 0x19, 0x1b, 0x1d, 0x1f, }; @@ -54,16 +54,16 @@ auto PSG::frame(int16& outputLeft, int16& outputRight) -> void { outputLeft = 0; outputRight = 0; - uint5 lmal = volumeScale[io.volumeLeft]; - uint5 rmal = volumeScale[io.volumeRight]; + n5 lmal = volumeScale[io.volumeLeft]; + n5 rmal = volumeScale[io.volumeRight]; - for(uint C : range(6)) { - uint5 al = channel[C].io.volume; - uint5 lal = volumeScale[channel[C].io.volumeLeft]; - uint5 ral = volumeScale[channel[C].io.volumeRight]; + for(u32 C : range(6)) { + n5 al = channel[C].io.volume; + n5 lal = volumeScale[channel[C].io.volumeLeft]; + n5 ral = volumeScale[channel[C].io.volumeRight]; - uint5 volumeLeft = min(0x1f, (0x1f - lmal) + (0x1f - lal) + (0x1f - al)); - uint5 volumeRight = min(0x1f, (0x1f - rmal) + (0x1f - ral) + (0x1f - al)); + n5 volumeLeft = min(0x1f, (0x1f - lmal) + (0x1f - lal) + (0x1f - al)); + n5 volumeRight = min(0x1f, (0x1f - rmal) + (0x1f - ral) + (0x1f - al)); channel[C].run(); if(C == 1 && io.lfoEnable) { @@ -75,7 +75,7 @@ auto PSG::frame(int16& outputLeft, int16& outputRight) -> void { } } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); } @@ -86,9 +86,9 @@ auto PSG::power() -> void { io = {}; for(auto C : range(6)) channel[C].power(C); - double level = 32768.0 / 6.0 / 32.0; //max volume / channels / steps - double step = 48.0 / 32.0; //48dB volume range spread over 32 steps - for(uint n : range(31)) { + f64 level = 32768.0 / 6.0 / 32.0; //max volume / channels / steps + f64 step = 48.0 / 32.0; //48dB volume range spread over 32 steps + for(u32 n : range(31)) { volumeScalar[n] = level; level /= pow(10.0, step / 20.0); } diff --git a/ares/pce/psg/psg.hpp b/ares/pce/psg/psg.hpp index ad37d869e7..cc7cf64f21 100644 --- a/ares/pce/psg/psg.hpp +++ b/ares/pce/psg/psg.hpp @@ -9,61 +9,61 @@ struct PSG : Thread { auto unload() -> void; auto main() -> void; - auto frame(int16&, int16&) -> void; - auto step(uint clocks) -> void; + auto frame(i16&, i16&) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //io.cpp - auto write(uint4 address, uint8 data) -> void; + auto write(n4 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; private: struct IO { - uint3 channel; - uint4 volumeLeft; - uint4 volumeRight; - uint8 lfoFrequency; - uint2 lfoControl; - uint1 lfoEnable; + n3 channel; + n4 volumeLeft; + n4 volumeRight; + n8 lfoFrequency; + n2 lfoControl; + n1 lfoEnable; } io; struct Channel { //channel.cpp - auto power(uint id) -> void; + auto power(u32 id) -> void; auto run() -> void; - auto sample(uint5 sample) -> void; + auto sample(n5 sample) -> void; //io.cpp - auto write(uint4 address, uint8 data) -> void; + auto write(n4 address, n8 data) -> void; struct IO { - uint12 waveFrequency; - uint5 volume; - uint1 direct; - uint1 enable; - uint4 volumeLeft; - uint4 volumeRight; - uint5 waveBuffer[32]; - uint5 noiseFrequency; //channels 4 and 5 only - uint1 noiseEnable; //channels 4 and 5 only + n12 waveFrequency; + n5 volume; + n1 direct; + n1 enable; + n4 volumeLeft; + n4 volumeRight; + n5 waveBuffer[32]; + n5 noiseFrequency; //channels 4 and 5 only + n1 noiseEnable; //channels 4 and 5 only - uint12 wavePeriod; - uint5 waveSample; - uint5 waveOffset; - uint12 noisePeriod; - uint5 noiseSample; + n12 wavePeriod; + n5 waveSample; + n5 waveOffset; + n12 noisePeriod; + n5 noiseSample; - uint5 output; + n5 output; } io; - uint id; + u32 id; } channel[6]; //unserialized: - double volumeScalar[32]; + f64 volumeScalar[32]; }; extern PSG psg; diff --git a/ares/pce/system/serialization.cpp b/ares/pce/system/serialization.cpp index 2ca7da1204..9dbd322379 100644 --- a/ares/pce/system/serialization.cpp +++ b/ares/pce/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/pce/system/system.cpp b/ares/pce/system/system.cpp index f4c3ead41c..2275149a56 100644 --- a/ares/pce/system/system.cpp +++ b/ares/pce/system/system.cpp @@ -2,7 +2,18 @@ namespace ares::PCEngine { +auto enumerate() -> vector { + return { + "[NEC] PC Engine (NTSC-J)", + "[NEC] TurboGrafx 16 (NTSC-U)", + "[NEC] PC Engine Duo (NTSC-J)", + "[NEC] TurboDuo (NTSC-U)", + "[NEC] SuperGrafx (NTSC-J)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -30,11 +41,34 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "PC Engine" ) information.model = Model::PCEngine; - if(name == "PC Engine Duo") information.model = Model::PCEngineDuo; - if(name == "SuperGrafx" ) information.model = Model::SuperGrafx; + if(name.find("PC Engine")) { + information.name = "PC Engine"; + information.model = Model::PCEngine; + } + if(name.find("TurboGrafx 16")) { + information.name = "PC Engine"; + information.model = Model::PCEngine; + } + if(name.find("PC Engine Duo")) { + information.name = "PC Engine"; + information.model = Model::PCEngineDuo; + } + if(name.find("TurboDuo")) { + information.name = "PC Engine"; + information.model = Model::PCEngineDuo; + } + if(name.find("SuperGrafx")) { + information.name = "SuperGrafx"; + information.model = Model::SuperGrafx; + } + if(name.find("NTSC-J")) { + information.region = Region::NTSCJ; + } + if(name.find("NTSC-U")) { + information.region = Region::NTSCU; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -44,14 +78,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC-U → NTSC-J"); - regionNode->setAllowedValues({ - "NTSC-J → NTSC-U", - "NTSC-U → NTSC-J", - "NTSC-J", - "NTSC-U" - }); - scheduler.reset(); cpu.load(node); vdp.load(node); @@ -83,20 +109,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC-J") { - information.region = Region::NTSCJ; - } - if(region == "NTSC-U") { - information.region = Region::NTSCU; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - if(PCD::Present()) pcd.power(); cartridgeSlot.power(); cpu.power(); diff --git a/ares/pce/system/system.hpp b/ares/pce/system/system.hpp index 2d27e0305d..512d9241a8 100644 --- a/ares/pce/system/system.hpp +++ b/ares/pce/system/system.hpp @@ -1,14 +1,13 @@ struct System { Node::System node; - Node::Setting::String regionNode; - enum class Model : uint { PCEngine, PCEngineDuo, SuperGrafx }; - enum class Region : uint { NTSCJ, NTSCU }; + enum class Model : u32 { PCEngine, PCEngineDuo, SuperGrafx }; + enum class Region : u32 { NTSCJ, NTSCU }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto region() const -> Region { return information.region; } - auto colorburst() const -> double { return information.colorburst; } + auto colorburst() const -> f64 { return information.colorburst; } //system.cpp auto game() -> string; @@ -25,9 +24,10 @@ struct System { private: struct Information { + string name = "PC Engine"; Model model = Model::PCEngine; Region region = Region::NTSCU; //more compatible - double colorburst = Constants::Colorburst::NTSC; + f64 colorburst = Constants::Colorburst::NTSC; } information; //serialization.cpp diff --git a/ares/pce/vdp-performance/background.cpp b/ares/pce/vdp-performance/background.cpp index 5803f38be2..145e3a1027 100644 --- a/ares/pce/vdp-performance/background.cpp +++ b/ares/pce/vdp-performance/background.cpp @@ -1,4 +1,4 @@ -auto VDC::Background::scanline(uint16 y) -> void { +auto VDC::Background::scanline(n16 y) -> void { if(y == 0) { vcounter = vscroll; } else { @@ -8,18 +8,18 @@ auto VDC::Background::scanline(uint16 y) -> void { voffset = vcounter; } -auto VDC::Background::render(uint16 y) -> void { +auto VDC::Background::render(n16 y) -> void { if(!enable) return (void)memset(&output, 0, sizeof(output)); - for(uint x = 0; x < vdp.vce.width();) { - uint8 tileX = hoffset >> 3 & width - 1; - uint8 tileY = voffset >> 3 & height - 1; - uint16 attributes = vdc->vram.read(tileY * width + tileX); + for(u32 x = 0; x < vdp.vce.width();) { + n8 tileX = hoffset >> 3 & width - 1; + n8 tileY = voffset >> 3 & height - 1; + n16 attributes = vdc->vram.read(tileY * width + tileX); - uint16 patternAddress = attributes.bit(0,11) << 4 | (uint3)voffset; - uint4 palette = attributes.bit(12,15); + n16 patternAddress = attributes.bit(0,11) << 4 | (n3)voffset; + n4 palette = attributes.bit(12,15); - uint16 d0 = 0, d1 = 0; + n16 d0 = 0, d1 = 0; if(latch.vramMode != 3) { d0 = vdc->vram.read(patternAddress + 0); d1 = vdc->vram.read(patternAddress + 8); @@ -29,9 +29,9 @@ auto VDC::Background::render(uint16 y) -> void { if(latch.characterMode == 1) d0 = vdc->vram.read(patternAddress + 8); } - uint3 index = ~hoffset; + n3 index = ~hoffset; do { - uint4 color; + n4 color; color.bit(0) = d0.bit(0 + index); color.bit(1) = d0.bit(8 + index); color.bit(2) = d1.bit(0 + index); diff --git a/ares/pce/vdp-performance/color.cpp b/ares/pce/vdp-performance/color.cpp index b2c36d05df..5953df0f3d 100644 --- a/ares/pce/vdp-performance/color.cpp +++ b/ares/pce/vdp-performance/color.cpp @@ -1,19 +1,19 @@ -auto VDP::color(uint32 color) -> uint64 { - uint3 B = color.bit(0,2); - uint3 R = color.bit(3,5); - uint3 G = color.bit(6,8); - uint1 M = color.bit(9); +auto VDP::color(n32 color) -> n64 { + n3 B = color.bit(0,2); + n3 R = color.bit(3,5); + n3 G = color.bit(6,8); + n1 M = color.bit(9); - uint64 r = image::normalize(R, 3, 16); - uint64 g = image::normalize(G, 3, 16); - uint64 b = image::normalize(B, 3, 16); + n64 r = image::normalize(R, 3, 16); + n64 g = image::normalize(G, 3, 16); + n64 b = image::normalize(B, 3, 16); if(M == 0) { //color return r << 32 | g << 16 | b << 0; } else { //grayscale - uint64 l = r * 0.2126 + g * 0.7152 + b * 0.0722; + n64 l = r * 0.2126 + g * 0.7152 + b * 0.0722; return l << 32 | l << 16 | l << 0; } } diff --git a/ares/pce/vdp-performance/debugger.cpp b/ares/pce/vdp-performance/debugger.cpp index 1a1af85fdb..14398fa8ea 100644 --- a/ares/pce/vdp-performance/debugger.cpp +++ b/ares/pce/vdp-performance/debugger.cpp @@ -2,10 +2,10 @@ auto VCE::Debugger::load(VCE& vce, Node::Object parent) -> void { memory.cram = parent->append("VCE CRAM"); memory.cram->setSize(0x200 << 1); memory.cram->setRead([&](u32 address) -> u8 { - return vce.cram.memory[uint9(address >> 1)].byte(address & 1); + return vce.cram.memory[n9(address >> 1)].byte(address & 1); }); memory.cram->setWrite([&](u32 address, u8 data) -> void { - vce.cram.memory[uint9(address >> 1)].byte(address & 1) = data; + vce.cram.memory[n9(address >> 1)].byte(address & 1) = data; }); } @@ -16,18 +16,18 @@ auto VDC::Debugger::load(VDC& vdc, Node::Object parent) -> void { memory.vram = parent->append(string{vdcID, " VRAM"}); memory.vram->setSize(32_KiB << 1); memory.vram->setRead([&](u32 address) -> u8 { - return vdc.vram.memory[uint15(address >> 1)].byte(address & 1); + return vdc.vram.memory[n15(address >> 1)].byte(address & 1); }); memory.vram->setWrite([&](u32 address, u8 data) -> void { - vdc.vram.memory[uint15(address >> 1)].byte(address & 1) = data; + vdc.vram.memory[n15(address >> 1)].byte(address & 1) = data; }); memory.satb = parent->append(string{vdcID, " SATB"}); memory.satb->setSize(0x100 << 1); memory.satb->setRead([&](u32 address) -> u8 { - return vdc.satb.memory[uint8(address >> 1)].byte(address & 1); + return vdc.satb.memory[n8(address >> 1)].byte(address & 1); }); memory.satb->setWrite([&](u32 address, u8 data) -> void { - vdc.satb.memory[uint8(address >> 1)].byte(address & 1) = data; + vdc.satb.memory[n8(address >> 1)].byte(address & 1) = data; }); } diff --git a/ares/pce/vdp-performance/dma.cpp b/ares/pce/vdp-performance/dma.cpp index 1a313f0f94..35683fee6b 100644 --- a/ares/pce/vdp-performance/dma.cpp +++ b/ares/pce/vdp-performance/dma.cpp @@ -1,4 +1,4 @@ -auto VDC::DMA::step(uint clocks) -> void { +auto VDC::DMA::step(u32 clocks) -> void { do { if(!vramActive && !satbActive) break; @@ -10,7 +10,7 @@ auto VDC::DMA::step(uint clocks) -> void { continue; } - uint16 data = vdc->vram.read(source); + n16 data = vdc->vram.read(source); vdc->vram.write(target, data); sourceIncrementMode == 0 ? source++ : source--; targetIncrementMode == 0 ? target++ : target--; @@ -22,7 +22,7 @@ auto VDC::DMA::step(uint clocks) -> void { } if(satbActive) { - uint16 data = vdc->vram.read(satbSource + satbOffset); + n16 data = vdc->vram.read(satbSource + satbOffset); vdc->satb.write(satbOffset, data); if(!++satbOffset) { satbActive = 0; diff --git a/ares/pce/vdp-performance/irq.cpp b/ares/pce/vdp-performance/irq.cpp index e31446aee9..7149ccdf9a 100644 --- a/ares/pce/vdp-performance/irq.cpp +++ b/ares/pce/vdp-performance/irq.cpp @@ -1,5 +1,5 @@ auto VDC::IRQ::poll() -> void { - uint1 pending = 0; + n1 pending = 0; pending |= collision.pending; pending |= overflow.pending; pending |= coincidence.pending; diff --git a/ares/pce/vdp-performance/sprite.cpp b/ares/pce/vdp-performance/sprite.cpp index 4d42cb1699..df7ad235c3 100644 --- a/ares/pce/vdp-performance/sprite.cpp +++ b/ares/pce/vdp-performance/sprite.cpp @@ -1,18 +1,18 @@ -auto VDC::Sprite::scanline(uint16 y) -> void { +auto VDC::Sprite::scanline(n16 y) -> void { objects.reset(); if(!enable) return; y += 64; - static const uint widths [2] = {15, 31}; - static const uint heights[4] = {15, 31, 63, 63}; + static const u32 widths [2] = {15, 31}; + static const u32 heights[4] = {15, 31, 63, 63}; - uint count = 0; - for(uint index : range(64)) { - uint16 d0 = vdc->satb.read(index << 2 | 0); - uint16 d1 = vdc->satb.read(index << 2 | 1); - uint16 d2 = vdc->satb.read(index << 2 | 2); - uint16 d3 = vdc->satb.read(index << 2 | 3); + u32 count = 0; + for(u32 index : range(64)) { + n16 d0 = vdc->satb.read(index << 2 | 0); + n16 d1 = vdc->satb.read(index << 2 | 1); + n16 d2 = vdc->satb.read(index << 2 | 2); + n16 d3 = vdc->satb.read(index << 2 | 3); Object object; object.y = d0.bit(0,9); @@ -52,30 +52,30 @@ auto VDC::Sprite::scanline(uint16 y) -> void { } } -auto VDC::Sprite::render(uint16 y) -> void { +auto VDC::Sprite::render(n16 y) -> void { if(!enable) return (void)memset(&output, 0, sizeof(output)); y += 64; - for(uint x : range(vdp.vce.width())) { + for(u32 x : range(vdp.vce.width())) { output[x] = {}; bool first = false; for(auto& object : objects) { if(x + 32 < object.x) continue; if(x + 32 > object.x + object.width) continue; - uint10 hoffset = x + 32 - object.x; - uint10 voffset = y - object.y; + n10 hoffset = x + 32 - object.x; + n10 voffset = y - object.y; if(object.hflip) hoffset ^= object.width; if(object.vflip) voffset ^= object.height; - uint16 patternAddress = object.pattern; + n16 patternAddress = object.pattern; patternAddress += (voffset >> 4) << 1; patternAddress += (hoffset >> 4); patternAddress <<= 6; patternAddress += (voffset & 15); - uint16 d0 = 0, d1 = 0, d2 = 0, d3 = 0; + n16 d0 = 0, d1 = 0, d2 = 0, d3 = 0; if(latch.vramMode != 1) { d0 = vdc->vram.read(patternAddress + 0); d1 = vdc->vram.read(patternAddress + 16); @@ -93,8 +93,8 @@ auto VDC::Sprite::render(uint16 y) -> void { } } - uint4 index = 15 - (hoffset & 15); - uint4 color; + n4 index = 15 - (hoffset & 15); + n4 color; color.bit(0) = d0.bit(index); color.bit(1) = d1.bit(index); color.bit(2) = d2.bit(index); diff --git a/ares/pce/vdp-performance/vce.cpp b/ares/pce/vdp-performance/vce.cpp index 5cd3e82121..dbf26e1110 100644 --- a/ares/pce/vdp-performance/vce.cpp +++ b/ares/pce/vdp-performance/vce.cpp @@ -1,6 +1,6 @@ -auto VCE::read(uint3 address) -> uint8 { +auto VCE::read(n3 address) -> n8 { cpu.idle(); //penalty cycle - uint8 data = 0xff; + n8 data = 0xff; if(address == 0x4) { //CTR @@ -18,7 +18,7 @@ auto VCE::read(uint3 address) -> uint8 { return data; } -auto VCE::write(uint3 address, uint8 data) -> void { +auto VCE::write(n3 address, n8 data) -> void { cpu.idle(); //penalty cycle if(address == 0x0) { @@ -65,11 +65,11 @@ auto VCE::power() -> void { io = {}; } -auto VCE::CRAM::read(uint9 address) -> uint9 { +auto VCE::CRAM::read(n9 address) -> n9 { return memory[address]; } -auto VCE::CRAM::write(uint9 address, uint1 a0, uint8 data) -> void { +auto VCE::CRAM::write(n9 address, n1 a0, n8 data) -> void { if(a0 == 0) memory[address].bit(0,7) = data.bit(0,7); if(a0 == 1) memory[address].bit(8) = data.bit(0); } diff --git a/ares/pce/vdp-performance/vce.hpp b/ares/pce/vdp-performance/vce.hpp index 9e869dcee0..e89222745f 100644 --- a/ares/pce/vdp-performance/vce.hpp +++ b/ares/pce/vdp-performance/vce.hpp @@ -10,12 +10,12 @@ struct VCE { } memory; } debugger; - auto clock() const -> uint { return io.clock; } - auto width() const -> uint { return io.clock == 4 ? 256 : io.clock == 3 ? 344 : 512; } + auto clock() const -> u32 { return io.clock; } + auto width() const -> u32 { return io.clock == 4 ? 256 : io.clock == 3 ? 344 : 512; } //vce.cpp - auto read(uint3 address) -> uint8; - auto write(uint3 address, uint8 data) -> void; + auto read(n3 address) -> n8; + auto write(n3 address, n8 data) -> void; auto power() -> void; //serialization.cpp @@ -23,16 +23,16 @@ struct VCE { struct CRAM { //vce.cpp - auto read(uint9 address) -> uint9; - auto write(uint9 address, uint1 a0, uint8 data) -> void; + auto read(n9 address) -> n9; + auto write(n9 address, n1 a0, n8 data) -> void; - uint9 memory[0x200]; - uint9 address; + n9 memory[0x200]; + n9 address; } cram; struct IO { - uint8 clock = 4; - uint1 extraLine; - uint1 grayscale; + n8 clock = 4; + n1 extraLine; + n1 grayscale; } io; }; diff --git a/ares/pce/vdp-performance/vdc.cpp b/ares/pce/vdp-performance/vdc.cpp index c921ee62de..1937b9ae1c 100644 --- a/ares/pce/vdp-performance/vdc.cpp +++ b/ares/pce/vdp-performance/vdc.cpp @@ -35,7 +35,7 @@ auto VDC::hclock() -> void { background.render(timing.voffset); sprite.render(timing.voffset); - for(uint x : range(vdp.vce.width())) { + for(u32 x : range(vdp.vce.width())) { output[x] = 0; if(sprite.output[x].color && sprite.output[x].priority) { output[x] = sprite.output[x].color << 0 | sprite.output[x].palette << 4 | 1 << 8; @@ -84,9 +84,9 @@ auto VDC::vclock() -> void { } } -auto VDC::read(uint2 address) -> uint8 { +auto VDC::read(n2 address) -> n8 { if(!burstMode()) cpu.idle(); //penalty cycle - uint8 data = 0x00; + n8 data = 0x00; if(address == 0x0) { //SR @@ -106,7 +106,7 @@ auto VDC::read(uint2 address) -> uint8 { return data; } - uint1 a0 = address.bit(0); + n1 a0 = address.bit(0); if(io.address == 0x02) { //VRR @@ -121,7 +121,7 @@ auto VDC::read(uint2 address) -> uint8 { return data; } -auto VDC::write(uint2 address, uint8 data) -> void { +auto VDC::write(n2 address, n8 data) -> void { if(!burstMode()) cpu.idle(); //penalty cycle if(address == 0x0) { @@ -135,7 +135,7 @@ auto VDC::write(uint2 address, uint8 data) -> void { return; } - uint1 a0 = address.bit(0); + n1 a0 = address.bit(0); if(io.address == 0x00) { //MAWR @@ -310,20 +310,20 @@ auto VDC::power() -> void { sprite.vdc = *this; } -inline auto VDC::VRAM::read(uint16 address) const -> uint16 { +inline auto VDC::VRAM::read(n16 address) const -> n16 { if(address.bit(15)) return 0x0000; //todo: random data? return memory[address]; } -inline auto VDC::VRAM::write(uint16 address, uint16 data) -> void { +inline auto VDC::VRAM::write(n16 address, n16 data) -> void { if(address.bit(15)) return; memory[address] = data; } -inline auto VDC::SATB::read(uint8 address) const -> uint16 { +inline auto VDC::SATB::read(n8 address) const -> n16 { return memory[address]; } -inline auto VDC::SATB::write(uint8 address, uint16 data) -> void { +inline auto VDC::SATB::write(n8 address, n16 data) -> void { memory[address] = data; } diff --git a/ares/pce/vdp-performance/vdc.hpp b/ares/pce/vdp-performance/vdc.hpp index 5250874c16..70b0c3d693 100644 --- a/ares/pce/vdp-performance/vdc.hpp +++ b/ares/pce/vdp-performance/vdc.hpp @@ -19,40 +19,40 @@ struct VDC { auto vsync() -> void; auto hclock() -> void; auto vclock() -> void; - auto read(uint2 address) -> uint8; - auto write(uint2 address, uint8 data) -> void; + auto read(n2 address) -> n8; + auto write(n2 address, n8 data) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint9 output[512]; + n9 output[512]; struct VRAM { //vdc.cpp - auto read(uint16 address) const -> uint16; - auto write(uint16 address, uint16 data) -> void; + auto read(n16 address) const -> n16; + auto write(n16 address, n16 data) -> void; - uint16 memory[0x8000]; + n16 memory[0x8000]; - uint16 addressRead; - uint16 addressWrite; - uint16 addressIncrement = 0x01; + n16 addressRead; + n16 addressWrite; + n16 addressIncrement = 0x01; - uint16 dataRead; - uint16 dataWrite; + n16 dataRead; + n16 dataWrite; } vram; struct SATB { //vdc.cpp - auto read(uint8 address) const -> uint16; - auto write(uint8 address, uint16 data) -> void; + auto read(n8 address) const -> n16; + auto write(n8 address, n16 data) -> void; - uint16 memory[0x100]; + n16 memory[0x100]; } satb; struct IRQ { - enum class Line : uint { + enum class Line : u32 { Collision, Overflow, Coincidence, @@ -62,8 +62,8 @@ struct VDC { }; struct Source { - uint1 enable; - uint1 pending; + n1 enable; + n1 pending; }; //irq.cpp @@ -71,7 +71,7 @@ struct VDC { auto raise(Line) -> void; auto lower() -> void; - uint1 line; + n1 line; Source collision; Source overflow; @@ -85,98 +85,98 @@ struct VDC { maybe vdc; //dma.cpp - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto vramStart() -> void; auto satbStart() -> void; auto satbQueue() -> void; - uint1 sourceIncrementMode; - uint1 targetIncrementMode; - uint1 satbRepeat; - uint16 source; - uint16 target; - uint16 length; - uint16 satbSource; - - uint1 vramActive; - uint1 satbActive; - uint1 satbPending; - uint8 satbOffset; + n1 sourceIncrementMode; + n1 targetIncrementMode; + n1 satbRepeat; + n16 source; + n16 target; + n16 length; + n16 satbSource; + + n1 vramActive; + n1 satbActive; + n1 satbPending; + n8 satbOffset; } dma; - enum : uint { HDS, HDW, HDE, HSW }; - enum : uint { VSW, VDS, VDW, VCR }; + enum : u32 { HDS, HDW, HDE, HSW }; + enum : u32 { VSW, VDS, VDW, VCR }; struct Timing { - uint5 horizontalSyncWidth = 2; - uint7 horizontalDisplayStart = 2; - uint7 horizontalDisplayWidth = 31; - uint7 horizontalDisplayEnd = 4; + n5 horizontalSyncWidth = 2; + n7 horizontalDisplayStart = 2; + n7 horizontalDisplayWidth = 31; + n7 horizontalDisplayEnd = 4; - uint5 verticalSyncWidth = 2; - uint8 verticalDisplayStart = 15; - uint9 verticalDisplayWidth = 239; - uint8 verticalDisplayEnd = 4; + n5 verticalSyncWidth = 2; + n8 verticalDisplayStart = 15; + n9 verticalDisplayWidth = 239; + n8 verticalDisplayEnd = 4; - uint8 hstate = HDS; - uint8 vstate = VSW; + n8 hstate = HDS; + n8 vstate = VSW; - uint16 hoffset; - uint16 voffset; + n16 hoffset; + n16 voffset; - uint10 coincidence = 64; + n10 coincidence = 64; } timing; struct Latch { - uint16 horizontalSyncWidth; - uint16 horizontalDisplayStart; - uint16 horizontalDisplayWidth; - uint16 horizontalDisplayEnd; + n16 horizontalSyncWidth; + n16 horizontalDisplayStart; + n16 horizontalDisplayWidth; + n16 horizontalDisplayEnd; - uint16 verticalSyncWidth; - uint16 verticalDisplayStart; - uint16 verticalDisplayWidth; - uint16 verticalDisplayEnd; + n16 verticalSyncWidth; + n16 verticalDisplayStart; + n16 verticalDisplayWidth; + n16 verticalDisplayEnd; - uint1 burstMode = 1; + n1 burstMode = 1; } latch; struct IO { - uint5 address; + n5 address; - uint2 externalSync; - uint2 displayOutput; - uint1 dramRefresh; - uint10 coincidence; + n2 externalSync; + n2 displayOutput; + n1 dramRefresh; + n10 coincidence; } io; struct Background { maybe vdc; //background.cpp - auto scanline(uint16 y) -> void; - auto render(uint16 y) -> void; + auto scanline(n16 y) -> void; + auto render(n16 y) -> void; - uint1 enable; - uint2 vramMode; //partially emulated - uint1 characterMode; - uint10 hscroll; - uint9 vscroll; - uint9 vcounter; - uint8 width = 32; - uint8 height = 32; + n1 enable; + n2 vramMode; //partially emulated + n1 characterMode; + n10 hscroll; + n9 vscroll; + n9 vcounter; + n8 width = 32; + n8 height = 32; - uint10 hoffset; - uint9 voffset; + n10 hoffset; + n9 voffset; struct Latch { - uint2 vramMode; - uint1 characterMode; + n2 vramMode; + n1 characterMode; } latch; struct Output { - uint4 color; - uint4 palette; + n4 color; + n4 palette; } output[512]; } background; @@ -184,39 +184,39 @@ struct VDC { //serialization.cpp auto serialize(serializer&) -> void; - uint10 y; - uint10 x; - uint1 characterMode; - uint10 pattern; - uint4 palette; - uint1 priority; - uint8 width; - uint8 height; - uint1 hflip; - uint1 vflip; - uint1 first; + n10 y; + n10 x; + n1 characterMode; + n10 pattern; + n4 palette; + n1 priority; + n8 width; + n8 height; + n1 hflip; + n1 vflip; + n1 first; }; struct Sprite { maybe vdc; //sprite.cpp - auto scanline(uint16 y) -> void; - auto render(uint16 y) -> void; + auto scanline(n16 y) -> void; + auto render(n16 y) -> void; adaptive_array objects; - uint1 enable; - uint2 vramMode; //partially emulated + n1 enable; + n2 vramMode; //partially emulated struct Latch { - uint2 vramMode; + n2 vramMode; } latch; struct Output { - uint4 color; - uint4 palette; - uint1 priority; + n4 color; + n4 palette; + n1 priority; } output[512]; } sprite; }; diff --git a/ares/pce/vdp-performance/vdp.cpp b/ares/pce/vdp-performance/vdp.cpp index f73c796003..22a52fcbd2 100644 --- a/ares/pce/vdp-performance/vdp.cpp +++ b/ares/pce/vdp-performance/vdp.cpp @@ -63,14 +63,14 @@ auto VDP::main() -> void { auto line = screen->pixels().data() + 1365 * io.vcounter; if(Model::SuperGrafx() == 0) { - for(uint x : range(vce.width())) { + for(u32 x : range(vce.width())) { line[x] = vce.io.grayscale << 9 | vce.cram.read(vdc0.output[x]); } } if(Model::SuperGrafx() == 1) { vpc.render(); - for(uint x : range(vce.width())) { + for(u32 x : range(vce.width())) { line[x] = vce.io.grayscale << 9 | vce.cram.read(vpc.output[x]); } } @@ -89,7 +89,7 @@ auto VDP::main() -> void { } } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { io.hcounter += clocks; vdc0.dma.step(clocks); if(Model::SuperGrafx()) vdc1.dma.step(clocks); @@ -112,14 +112,14 @@ auto VDP::refresh() -> void { } //this frame contains mixed resolutions: normalize every scanline to 1024-width - for(uint y = 21; y < 239 + 21; y++) { + for(u32 y = 21; y < 239 + 21; y++) { auto output = screen->pixels(1).data() + 1365 * y; switch(widths[y]) { case 256: { auto source = &output[256]; auto target = &output[256 * 4]; - for(uint x : range(256)) { + for(u32 x : range(256)) { auto color = *--source; *--target = color; *--target = color; @@ -131,7 +131,7 @@ auto VDP::refresh() -> void { case 344: { auto source = &output[344]; auto target = &output[344 * 3]; - for(uint x : range(344)) { + for(u32 x : range(344)) { auto color = *--source; *--target = color; *--target = color; @@ -142,7 +142,7 @@ auto VDP::refresh() -> void { case 512: { auto source = &output[512]; auto target = &output[512 * 2]; - for(uint x : range(512)) { + for(u32 x : range(512)) { auto color = *--source; *--target = color; *--target = color; diff --git a/ares/pce/vdp-performance/vdp.hpp b/ares/pce/vdp-performance/vdp.hpp index bcfeb6e62e..07a52b9593 100644 --- a/ares/pce/vdp-performance/vdp.hpp +++ b/ares/pce/vdp-performance/vdp.hpp @@ -13,12 +13,12 @@ struct VDP : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto refresh() -> void; auto power() -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; @@ -29,14 +29,14 @@ struct VDP : Thread { VPC vpc; struct IO { - uint16 hcounter; - uint16 vcounter; + n16 hcounter; + n16 vcounter; } io; - uint1 width256; - uint1 width344; - uint1 width512; - uint9 widths[263]; + n1 width256; + n1 width344; + n1 width512; + n9 widths[263]; }; extern VDP vdp; diff --git a/ares/pce/vdp-performance/vpc.cpp b/ares/pce/vdp-performance/vpc.cpp index a50003a95d..44b21aafb2 100644 --- a/ares/pce/vdp-performance/vpc.cpp +++ b/ares/pce/vdp-performance/vpc.cpp @@ -1,5 +1,5 @@ auto VPC::render() -> void { - for(uint x : range(vdp.vce.width())) { + for(u32 x : range(vdp.vce.width())) { auto bus0 = vdp.vdc0.output[x]; auto bus1 = vdp.vdc1.output[x]; @@ -7,7 +7,7 @@ auto VPC::render() -> void { bool window0 = window[0] >= 64 && (window[0] - 64) >= x * vdp.vce.clock() / 2; bool window1 = window[1] >= 64 && (window[1] - 64) >= x * vdp.vce.clock() / 2; - uint2 mode = !window0 << 0 | !window1 << 1; + n2 mode = !window0 << 0 | !window1 << 1; bool enableVDC0 = settings[mode].enableVDC0 && bus0.bit(0,3); bool enableVDC1 = settings[mode].enableVDC1 && bus1.bit(0,3); auto priority = settings[mode].priority; @@ -40,12 +40,12 @@ auto VPC::render() -> void { } } -auto VPC::read(uint5 address) -> uint8 { +auto VPC::read(n5 address) -> n8 { if(address >= 0x00 && address <= 0x07) return vdp.vdc0.read(address); if(address >= 0x10 && address <= 0x17) return vdp.vdc1.read(address); if(address >= 0x18 && address <= 0x1f) return 0xff; - uint8 data = 0x00; + n8 data = 0x00; if(address == 0x08) { data.bit(0) = settings[0].enableVDC0; @@ -100,7 +100,7 @@ auto VPC::read(uint5 address) -> uint8 { unreachable; } -auto VPC::write(uint5 address, uint8 data) -> void { +auto VPC::write(n5 address, n8 data) -> void { if(address >= 0x00 && address <= 0x07) return vdp.vdc0.write(address, data); if(address >= 0x10 && address <= 0x17) return vdp.vdc1.write(address, data); if(address >= 0x18 && address <= 0x1f) return; @@ -156,7 +156,7 @@ auto VPC::write(uint5 address, uint8 data) -> void { } } -auto VPC::store(uint2 address, uint8 data) -> void { +auto VPC::store(n2 address, n8 data) -> void { if(select == 0) return vdp.vdc0.write(address, data); if(select == 1) return vdp.vdc1.write(address, data); } diff --git a/ares/pce/vdp-performance/vpc.hpp b/ares/pce/vdp-performance/vpc.hpp index 4104075d1b..1e363eb595 100644 --- a/ares/pce/vdp-performance/vpc.hpp +++ b/ares/pce/vdp-performance/vpc.hpp @@ -3,22 +3,22 @@ struct VPC { //vpc.cpp auto render() -> void; - auto read(uint5 address) -> uint8; - auto write(uint5 address, uint8 data) -> void; - auto store(uint2 address, uint8 data) -> void; + auto read(n5 address) -> n8; + auto write(n5 address, n8 data) -> void; + auto store(n2 address, n8 data) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint9 output[512]; + n9 output[512]; struct Settings { - uint1 enableVDC0 = 1; - uint1 enableVDC1 = 0; - uint2 priority = 0; + n1 enableVDC0 = 1; + n1 enableVDC1 = 0; + n2 priority = 0; } settings[4]; - uint10 window[2]; - uint1 select; + n10 window[2]; + n1 select; }; diff --git a/ares/pce/vdp/background.cpp b/ares/pce/vdp/background.cpp index 919dc84dc1..6d672832d3 100644 --- a/ares/pce/vdp/background.cpp +++ b/ares/pce/vdp/background.cpp @@ -1,4 +1,4 @@ -auto VDC::Background::scanline(uint y) -> void { +auto VDC::Background::scanline(u32 y) -> void { if(y == 0) { vcounter = vscroll; } else { @@ -8,19 +8,19 @@ auto VDC::Background::scanline(uint y) -> void { voffset = vcounter; } -auto VDC::Background::run(uint x, uint y) -> void { +auto VDC::Background::run(u32 x, u32 y) -> void { color = 0; palette = 0; if(!enable) return; - uint8 tileX = hoffset >> 3 & width - 1; - uint8 tileY = voffset >> 3 & height - 1; - uint16 attributes = vdc->vram.read(tileY * width + tileX); + n8 tileX = hoffset >> 3 & width - 1; + n8 tileY = voffset >> 3 & height - 1; + n16 attributes = vdc->vram.read(tileY * width + tileX); - uint16 patternAddress = attributes.bit(0,11) << 4 | (uint3)voffset; - uint4 palette = attributes.bit(12,15); + n16 patternAddress = attributes.bit(0,11) << 4 | (n3)voffset; + n4 palette = attributes.bit(12,15); - uint16 d0 = 0, d1 = 0; + n16 d0 = 0, d1 = 0; if(latch.vramMode != 3) { d0 = vdc->vram.read(patternAddress + 0); d1 = vdc->vram.read(patternAddress + 8); @@ -30,8 +30,8 @@ auto VDC::Background::run(uint x, uint y) -> void { if(latch.characterMode == 1) d0 = vdc->vram.read(patternAddress + 8); } - uint3 index = ~hoffset; - uint4 color; + n3 index = ~hoffset; + n4 color; color.bit(0) = d0.bit(0 + index); color.bit(1) = d0.bit(8 + index); color.bit(2) = d1.bit(0 + index); diff --git a/ares/pce/vdp/color.cpp b/ares/pce/vdp/color.cpp index b2c36d05df..5953df0f3d 100644 --- a/ares/pce/vdp/color.cpp +++ b/ares/pce/vdp/color.cpp @@ -1,19 +1,19 @@ -auto VDP::color(uint32 color) -> uint64 { - uint3 B = color.bit(0,2); - uint3 R = color.bit(3,5); - uint3 G = color.bit(6,8); - uint1 M = color.bit(9); +auto VDP::color(n32 color) -> n64 { + n3 B = color.bit(0,2); + n3 R = color.bit(3,5); + n3 G = color.bit(6,8); + n1 M = color.bit(9); - uint64 r = image::normalize(R, 3, 16); - uint64 g = image::normalize(G, 3, 16); - uint64 b = image::normalize(B, 3, 16); + n64 r = image::normalize(R, 3, 16); + n64 g = image::normalize(G, 3, 16); + n64 b = image::normalize(B, 3, 16); if(M == 0) { //color return r << 32 | g << 16 | b << 0; } else { //grayscale - uint64 l = r * 0.2126 + g * 0.7152 + b * 0.0722; + n64 l = r * 0.2126 + g * 0.7152 + b * 0.0722; return l << 32 | l << 16 | l << 0; } } diff --git a/ares/pce/vdp/debugger.cpp b/ares/pce/vdp/debugger.cpp index 1a1af85fdb..14398fa8ea 100644 --- a/ares/pce/vdp/debugger.cpp +++ b/ares/pce/vdp/debugger.cpp @@ -2,10 +2,10 @@ auto VCE::Debugger::load(VCE& vce, Node::Object parent) -> void { memory.cram = parent->append("VCE CRAM"); memory.cram->setSize(0x200 << 1); memory.cram->setRead([&](u32 address) -> u8 { - return vce.cram.memory[uint9(address >> 1)].byte(address & 1); + return vce.cram.memory[n9(address >> 1)].byte(address & 1); }); memory.cram->setWrite([&](u32 address, u8 data) -> void { - vce.cram.memory[uint9(address >> 1)].byte(address & 1) = data; + vce.cram.memory[n9(address >> 1)].byte(address & 1) = data; }); } @@ -16,18 +16,18 @@ auto VDC::Debugger::load(VDC& vdc, Node::Object parent) -> void { memory.vram = parent->append(string{vdcID, " VRAM"}); memory.vram->setSize(32_KiB << 1); memory.vram->setRead([&](u32 address) -> u8 { - return vdc.vram.memory[uint15(address >> 1)].byte(address & 1); + return vdc.vram.memory[n15(address >> 1)].byte(address & 1); }); memory.vram->setWrite([&](u32 address, u8 data) -> void { - vdc.vram.memory[uint15(address >> 1)].byte(address & 1) = data; + vdc.vram.memory[n15(address >> 1)].byte(address & 1) = data; }); memory.satb = parent->append(string{vdcID, " SATB"}); memory.satb->setSize(0x100 << 1); memory.satb->setRead([&](u32 address) -> u8 { - return vdc.satb.memory[uint8(address >> 1)].byte(address & 1); + return vdc.satb.memory[n8(address >> 1)].byte(address & 1); }); memory.satb->setWrite([&](u32 address, u8 data) -> void { - vdc.satb.memory[uint8(address >> 1)].byte(address & 1) = data; + vdc.satb.memory[n8(address >> 1)].byte(address & 1) = data; }); } diff --git a/ares/pce/vdp/dma.cpp b/ares/pce/vdp/dma.cpp index 1a313f0f94..35683fee6b 100644 --- a/ares/pce/vdp/dma.cpp +++ b/ares/pce/vdp/dma.cpp @@ -1,4 +1,4 @@ -auto VDC::DMA::step(uint clocks) -> void { +auto VDC::DMA::step(u32 clocks) -> void { do { if(!vramActive && !satbActive) break; @@ -10,7 +10,7 @@ auto VDC::DMA::step(uint clocks) -> void { continue; } - uint16 data = vdc->vram.read(source); + n16 data = vdc->vram.read(source); vdc->vram.write(target, data); sourceIncrementMode == 0 ? source++ : source--; targetIncrementMode == 0 ? target++ : target--; @@ -22,7 +22,7 @@ auto VDC::DMA::step(uint clocks) -> void { } if(satbActive) { - uint16 data = vdc->vram.read(satbSource + satbOffset); + n16 data = vdc->vram.read(satbSource + satbOffset); vdc->satb.write(satbOffset, data); if(!++satbOffset) { satbActive = 0; diff --git a/ares/pce/vdp/irq.cpp b/ares/pce/vdp/irq.cpp index e31446aee9..7149ccdf9a 100644 --- a/ares/pce/vdp/irq.cpp +++ b/ares/pce/vdp/irq.cpp @@ -1,5 +1,5 @@ auto VDC::IRQ::poll() -> void { - uint1 pending = 0; + n1 pending = 0; pending |= collision.pending; pending |= overflow.pending; pending |= coincidence.pending; diff --git a/ares/pce/vdp/sprite.cpp b/ares/pce/vdp/sprite.cpp index 36d8e87995..5def0ee4b9 100644 --- a/ares/pce/vdp/sprite.cpp +++ b/ares/pce/vdp/sprite.cpp @@ -1,18 +1,18 @@ -auto VDC::Sprite::scanline(uint y) -> void { +auto VDC::Sprite::scanline(u32 y) -> void { objects.reset(); if(!enable) return; y += 64; - static const uint widths [2] = {15, 31}; - static const uint heights[4] = {15, 31, 63, 63}; + static const u32 widths [2] = {15, 31}; + static const u32 heights[4] = {15, 31, 63, 63}; - uint count = 0; - for(uint index : range(64)) { - uint16 d0 = vdc->satb.read(index << 2 | 0); - uint16 d1 = vdc->satb.read(index << 2 | 1); - uint16 d2 = vdc->satb.read(index << 2 | 2); - uint16 d3 = vdc->satb.read(index << 2 | 3); + u32 count = 0; + for(u32 index : range(64)) { + n16 d0 = vdc->satb.read(index << 2 | 0); + n16 d1 = vdc->satb.read(index << 2 | 1); + n16 d2 = vdc->satb.read(index << 2 | 2); + n16 d3 = vdc->satb.read(index << 2 | 3); Object object; object.y = d0.bit(0,9); @@ -52,7 +52,7 @@ auto VDC::Sprite::scanline(uint y) -> void { } } -auto VDC::Sprite::run(uint x, uint y) -> void { +auto VDC::Sprite::run(u32 x, u32 y) -> void { color = 0; palette = 0; priority = 0; @@ -66,18 +66,18 @@ auto VDC::Sprite::run(uint x, uint y) -> void { if(x < object.x) continue; if(x > object.x + object.width) continue; - uint10 hoffset = x - object.x; - uint10 voffset = y - object.y; + n10 hoffset = x - object.x; + n10 voffset = y - object.y; if(object.hflip) hoffset ^= object.width; if(object.vflip) voffset ^= object.height; - uint16 patternAddress = object.pattern; + n16 patternAddress = object.pattern; patternAddress += (voffset >> 4) << 1; patternAddress += (hoffset >> 4); patternAddress <<= 6; patternAddress += (voffset & 15); - uint16 d0 = 0, d1 = 0, d2 = 0, d3 = 0; + n16 d0 = 0, d1 = 0, d2 = 0, d3 = 0; if(latch.vramMode != 1) { d0 = vdc->vram.read(patternAddress + 0); d1 = vdc->vram.read(patternAddress + 16); @@ -95,8 +95,8 @@ auto VDC::Sprite::run(uint x, uint y) -> void { } } - uint4 index = 15 - (hoffset & 15); - uint4 color; + n4 index = 15 - (hoffset & 15); + n4 color; color.bit(0) = d0.bit(index); color.bit(1) = d1.bit(index); color.bit(2) = d2.bit(index); diff --git a/ares/pce/vdp/vce.cpp b/ares/pce/vdp/vce.cpp index 4579f2d0d1..6e96fecbec 100644 --- a/ares/pce/vdp/vce.cpp +++ b/ares/pce/vdp/vce.cpp @@ -1,6 +1,6 @@ -auto VCE::read(uint3 address) -> uint8 { +auto VCE::read(n3 address) -> n8 { cpu.idle(); //penalty cycle - uint8 data = 0xff; + n8 data = 0xff; if(address == 0x4) { //CTR @@ -18,7 +18,7 @@ auto VCE::read(uint3 address) -> uint8 { return data; } -auto VCE::write(uint3 address, uint8 data) -> void { +auto VCE::write(n3 address, n8 data) -> void { cpu.idle(); //penalty cycle if(address == 0x0) { @@ -65,11 +65,11 @@ auto VCE::power() -> void { io = {}; } -auto VCE::CRAM::read(uint9 address) -> uint9 { +auto VCE::CRAM::read(n9 address) -> n9 { return memory[address]; } -auto VCE::CRAM::write(uint9 address, uint1 a0, uint8 data) -> void { +auto VCE::CRAM::write(n9 address, n1 a0, n8 data) -> void { if(a0 == 0) memory[address].bit(0,7) = data.bit(0,7); if(a0 == 1) memory[address].bit(8) = data.bit(0); } diff --git a/ares/pce/vdp/vce.hpp b/ares/pce/vdp/vce.hpp index 2c21d42276..3509bb4295 100644 --- a/ares/pce/vdp/vce.hpp +++ b/ares/pce/vdp/vce.hpp @@ -10,11 +10,11 @@ struct VCE { } memory; } debugger; - auto clock() const -> uint { return io.clock; } + auto clock() const -> u32 { return io.clock; } //vce.cpp - auto read(uint3 address) -> uint8; - auto write(uint3 address, uint8 data) -> void; + auto read(n3 address) -> n8; + auto write(n3 address, n8 data) -> void; auto power() -> void; //serialization.cpp @@ -22,16 +22,16 @@ struct VCE { struct CRAM { //vce.cpp - auto read(uint9 address) -> uint9; - auto write(uint9 address, uint1 a0, uint8 data) -> void; + auto read(n9 address) -> n9; + auto write(n9 address, n1 a0, n8 data) -> void; - uint9 memory[0x200]; - uint9 address; + n9 memory[0x200]; + n9 address; } cram; struct IO { - uint8 clock = 4; - uint1 extraLine; - uint1 grayscale; + n8 clock = 4; + n1 extraLine; + n1 grayscale; } io; }; diff --git a/ares/pce/vdp/vdc.cpp b/ares/pce/vdp/vdc.cpp index fe768c5276..7ae1ac12e4 100644 --- a/ares/pce/vdp/vdc.cpp +++ b/ares/pce/vdp/vdc.cpp @@ -108,9 +108,9 @@ auto VDC::vclock() -> void { } } -auto VDC::read(uint2 address) -> uint8 { +auto VDC::read(n2 address) -> n8 { if(!burstMode()) cpu.idle(); //penalty cycle - uint8 data = 0x00; + n8 data = 0x00; if(address == 0x0) { //SR @@ -130,7 +130,7 @@ auto VDC::read(uint2 address) -> uint8 { return data; } - uint1 a0 = address.bit(0); + n1 a0 = address.bit(0); if(io.address == 0x02) { //VRR @@ -146,7 +146,7 @@ auto VDC::read(uint2 address) -> uint8 { return data; } -auto VDC::write(uint2 address, uint8 data) -> void { +auto VDC::write(n2 address, n8 data) -> void { if(!burstMode()) cpu.idle(); //penalty cycle if(address == 0x0) { @@ -160,7 +160,7 @@ auto VDC::write(uint2 address, uint8 data) -> void { return; } - uint1 a0 = address.bit(0); + n1 a0 = address.bit(0); if(io.address == 0x00) { //MAWR @@ -343,20 +343,20 @@ auto VDC::power() -> void { sprite.vdc = *this; } -inline auto VDC::VRAM::read(uint16 address) const -> uint16 { +inline auto VDC::VRAM::read(n16 address) const -> n16 { if(address.bit(15)) return 0x0000; //todo: random data? return memory[address]; } -inline auto VDC::VRAM::write(uint16 address, uint16 data) -> void { +inline auto VDC::VRAM::write(n16 address, n16 data) -> void { if(address.bit(15)) return; memory[address] = data; } -inline auto VDC::SATB::read(uint8 address) const -> uint16 { +inline auto VDC::SATB::read(n8 address) const -> n16 { return memory[address]; } -inline auto VDC::SATB::write(uint8 address, uint16 data) -> void { +inline auto VDC::SATB::write(n8 address, n16 data) -> void { memory[address] = data; } diff --git a/ares/pce/vdp/vdc.hpp b/ares/pce/vdp/vdc.hpp index da306de51b..90ef386114 100644 --- a/ares/pce/vdp/vdc.hpp +++ b/ares/pce/vdp/vdc.hpp @@ -11,7 +11,7 @@ struct VDC { } memory; } debugger; - auto bus() const -> uint9 { return output; } + auto bus() const -> n9 { return output; } auto burstMode() const -> bool { return latch.burstMode || timing.vstate != VDW; } auto irqLine() const -> bool { return irq.line; } @@ -20,40 +20,40 @@ struct VDC { auto vsync() -> void; auto hclock() -> void; auto vclock() -> void; - auto read(uint2 address) -> uint8; - auto write(uint2 address, uint8 data) -> void; + auto read(n2 address) -> n8; + auto write(n2 address, n8 data) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint9 output; + n9 output; struct VRAM { //vdc.cpp - auto read(uint16 address) const -> uint16; - auto write(uint16 address, uint16 data) -> void; + auto read(n16 address) const -> n16; + auto write(n16 address, n16 data) -> void; - uint16 memory[0x8000]; + n16 memory[0x8000]; - uint16 addressRead; - uint16 addressWrite; - uint16 addressIncrement = 0x01; + n16 addressRead; + n16 addressWrite; + n16 addressIncrement = 0x01; - uint16 dataRead; - uint16 dataWrite; + n16 dataRead; + n16 dataWrite; } vram; struct SATB { //vdc.cpp - auto read(uint8 address) const -> uint16; - auto write(uint8 address, uint16 data) -> void; + auto read(n8 address) const -> n16; + auto write(n8 address, n16 data) -> void; - uint16 memory[0x100]; + n16 memory[0x100]; } satb; struct IRQ { - enum class Line : uint { + enum class Line : u32 { Collision, Overflow, Coincidence, @@ -63,8 +63,8 @@ struct VDC { }; struct Source { - uint1 enable; - uint1 pending; + n1 enable; + n1 pending; }; //irq.cpp @@ -72,7 +72,7 @@ struct VDC { auto raise(Line) -> void; auto lower() -> void; - uint1 line; + n1 line; Source collision; Source overflow; @@ -86,96 +86,96 @@ struct VDC { maybe vdc; //dma.cpp - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto vramStart() -> void; auto satbStart() -> void; auto satbQueue() -> void; - uint1 sourceIncrementMode; - uint1 targetIncrementMode; - uint1 satbRepeat; - uint16 source; - uint16 target; - uint16 length; - uint16 satbSource; - - uint1 vramActive; - uint1 satbActive; - uint1 satbPending; - uint8 satbOffset; + n1 sourceIncrementMode; + n1 targetIncrementMode; + n1 satbRepeat; + n16 source; + n16 target; + n16 length; + n16 satbSource; + + n1 vramActive; + n1 satbActive; + n1 satbPending; + n8 satbOffset; } dma; - enum : uint { HDS, HDW, HDE, HSW }; - enum : uint { VSW, VDS, VDW, VCR }; + enum : u32 { HDS, HDW, HDE, HSW }; + enum : u32 { VSW, VDS, VDW, VCR }; struct Timing { - uint5 horizontalSyncWidth = 2; - uint7 horizontalDisplayStart = 2; - uint7 horizontalDisplayWidth = 31; - uint7 horizontalDisplayEnd = 4; + n5 horizontalSyncWidth = 2; + n7 horizontalDisplayStart = 2; + n7 horizontalDisplayWidth = 31; + n7 horizontalDisplayEnd = 4; - uint5 verticalSyncWidth = 2; - uint8 verticalDisplayStart = 15; - uint9 verticalDisplayWidth = 239; - uint8 verticalDisplayEnd = 4; + n5 verticalSyncWidth = 2; + n8 verticalDisplayStart = 15; + n9 verticalDisplayWidth = 239; + n8 verticalDisplayEnd = 4; - uint8 hstate = HDS; - uint8 vstate = VSW; + n8 hstate = HDS; + n8 vstate = VSW; - uint16 hoffset; - uint16 voffset; + n16 hoffset; + n16 voffset; - uint10 coincidence = 64; + n10 coincidence = 64; } timing; struct Latch { - uint16 horizontalSyncWidth; - uint16 horizontalDisplayStart; - uint16 horizontalDisplayWidth; - uint16 horizontalDisplayEnd; + n16 horizontalSyncWidth; + n16 horizontalDisplayStart; + n16 horizontalDisplayWidth; + n16 horizontalDisplayEnd; - uint16 verticalSyncWidth; - uint16 verticalDisplayStart; - uint16 verticalDisplayWidth; - uint16 verticalDisplayEnd; + n16 verticalSyncWidth; + n16 verticalDisplayStart; + n16 verticalDisplayWidth; + n16 verticalDisplayEnd; - uint1 burstMode = 1; + n1 burstMode = 1; } latch; struct IO { - uint5 address; + n5 address; - uint2 externalSync; - uint2 displayOutput; - uint1 dramRefresh; - uint10 coincidence; + n2 externalSync; + n2 displayOutput; + n1 dramRefresh; + n10 coincidence; } io; struct Background { maybe vdc; //background.cpp - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; - uint1 enable; - uint2 vramMode; //partially emulated - uint1 characterMode; - uint10 hscroll; - uint9 vscroll; - uint9 vcounter; - uint8 width = 32; - uint8 height = 32; + n1 enable; + n2 vramMode; //partially emulated + n1 characterMode; + n10 hscroll; + n9 vscroll; + n9 vcounter; + n8 width = 32; + n8 height = 32; - uint10 hoffset; - uint9 voffset; + n10 hoffset; + n9 voffset; - uint4 color; - uint4 palette; + n4 color; + n4 palette; struct Latch { - uint2 vramMode; - uint1 characterMode; + n2 vramMode; + n1 characterMode; } latch; } background; @@ -183,37 +183,37 @@ struct VDC { //serialization.cpp auto serialize(serializer&) -> void; - uint10 y; - uint10 x; - uint1 characterMode; - uint10 pattern; - uint4 palette; - uint1 priority; - uint8 width; - uint8 height; - uint1 hflip; - uint1 vflip; - uint1 first; + n10 y; + n10 x; + n1 characterMode; + n10 pattern; + n4 palette; + n1 priority; + n8 width; + n8 height; + n1 hflip; + n1 vflip; + n1 first; }; struct Sprite { maybe vdc; //sprite.cpp - auto scanline(uint y) -> void; - auto run(uint x, uint y) -> void; + auto scanline(u32 y) -> void; + auto run(u32 x, u32 y) -> void; adaptive_array objects; - uint1 enable; - uint2 vramMode; //partially emulated + n1 enable; + n2 vramMode; //partially emulated - uint4 color; - uint4 palette; - uint1 priority; + n4 color; + n4 palette; + n1 priority; struct Latch { - uint2 vramMode; + n2 vramMode; } latch; } sprite; diff --git a/ares/pce/vdp/vdp.cpp b/ares/pce/vdp/vdp.cpp index 3b7d86ac23..5e726d7e79 100644 --- a/ares/pce/vdp/vdp.cpp +++ b/ares/pce/vdp/vdp.cpp @@ -62,7 +62,7 @@ auto VDP::main() -> void { vdc0.hclock(); if(Model::SuperGrafx()) vdc1.hclock(); - uint10 color; + n10 color; if(Model::SuperGrafx() == 0) color = vdc0.bus(); if(Model::SuperGrafx() == 1) color = vpc.bus(io.hcounter); color = vce.io.grayscale << 9 | vce.cram.read(color); @@ -89,7 +89,7 @@ auto VDP::main() -> void { } } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { io.hcounter += clocks; vdc0.dma.step(clocks); if(Model::SuperGrafx()) vdc1.dma.step(clocks); diff --git a/ares/pce/vdp/vdp.hpp b/ares/pce/vdp/vdp.hpp index 6039372b29..0e37b352f0 100644 --- a/ares/pce/vdp/vdp.hpp +++ b/ares/pce/vdp/vdp.hpp @@ -17,11 +17,11 @@ struct VDP : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; @@ -32,8 +32,8 @@ struct VDP : Thread { VPC vpc; struct IO { - uint16 hcounter; - uint16 vcounter; + n16 hcounter; + n16 vcounter; } io; }; diff --git a/ares/pce/vdp/vpc.cpp b/ares/pce/vdp/vpc.cpp index af04cc3bb8..5aab394865 100644 --- a/ares/pce/vdp/vpc.cpp +++ b/ares/pce/vdp/vpc.cpp @@ -1,4 +1,4 @@ -inline auto VPC::bus(uint16 hcounter) const -> uint9 { +inline auto VPC::bus(n16 hcounter) const -> n9 { //bus values are direct CRAM entry indexes: //d0-d3 => color (0 = neither background nor sprite) //d4-d7 => palette @@ -9,7 +9,7 @@ inline auto VPC::bus(uint16 hcounter) const -> uint9 { bool window0 = window[0] >= 64 && (window[0] - 64) >= hcounter / 2; bool window1 = window[1] >= 64 && (window[1] - 64) >= hcounter / 2; - uint2 mode = !window0 << 0 | !window1 << 1; + n2 mode = !window0 << 0 | !window1 << 1; bool enableVDC0 = settings[mode].enableVDC0 && bus0.bit(0,3); bool enableVDC1 = settings[mode].enableVDC1 && bus1.bit(0,3); auto priority = settings[mode].priority; @@ -41,12 +41,12 @@ inline auto VPC::bus(uint16 hcounter) const -> uint9 { return 0x000; } -auto VPC::read(uint5 address) -> uint8 { +auto VPC::read(n5 address) -> n8 { if(address >= 0x00 && address <= 0x07) return vdp.vdc0.read(address); if(address >= 0x10 && address <= 0x17) return vdp.vdc1.read(address); if(address >= 0x18 && address <= 0x1f) return 0xff; - uint8 data = 0x00; + n8 data = 0x00; if(address == 0x08) { data.bit(0) = settings[0].enableVDC0; @@ -101,7 +101,7 @@ auto VPC::read(uint5 address) -> uint8 { unreachable; } -auto VPC::write(uint5 address, uint8 data) -> void { +auto VPC::write(n5 address, n8 data) -> void { if(address >= 0x00 && address <= 0x07) return vdp.vdc0.write(address, data); if(address >= 0x10 && address <= 0x17) return vdp.vdc1.write(address, data); if(address >= 0x18 && address <= 0x1f) return; @@ -157,7 +157,7 @@ auto VPC::write(uint5 address, uint8 data) -> void { } } -auto VPC::store(uint2 address, uint8 data) -> void { +auto VPC::store(n2 address, n8 data) -> void { if(select == 0) return vdp.vdc0.write(address, data); if(select == 1) return vdp.vdc1.write(address, data); } diff --git a/ares/pce/vdp/vpc.hpp b/ares/pce/vdp/vpc.hpp index 8c7ae33aca..f005d72569 100644 --- a/ares/pce/vdp/vpc.hpp +++ b/ares/pce/vdp/vpc.hpp @@ -2,22 +2,22 @@ struct VPC { //vpc.cpp - auto bus(uint16 hcounter) const -> uint9; + auto bus(n16 hcounter) const -> n9; - auto read(uint5 address) -> uint8; - auto write(uint5 address, uint8 data) -> void; - auto store(uint2 address, uint8 data) -> void; + auto read(n5 address) -> n8; + auto write(n5 address, n8 data) -> void; + auto store(n2 address, n8 data) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; struct Settings { - uint1 enableVDC0 = 1; - uint1 enableVDC1 = 0; - uint2 priority = 0; + n1 enableVDC0 = 1; + n1 enableVDC1 = 0; + n2 priority = 0; } settings[4]; - uint10 window[2]; - uint1 select; + n10 window[2]; + n1 select; }; diff --git a/ares/ps1/cpu/breakpoints.cpp b/ares/ps1/cpu/breakpoints.cpp index 13d8715116..b138500d16 100644 --- a/ares/ps1/cpu/breakpoints.cpp +++ b/ares/ps1/cpu/breakpoints.cpp @@ -31,7 +31,7 @@ auto CPU::Breakpoint::testCode(u32 address) -> bool { return true; } -template +template auto CPU::Breakpoint::testData(u32 address) -> bool { if(!self.scc.breakpoint.enable.master) return false; if(!self.scc.breakpoint.enable.kernel && (address >> 31) == 1) return false; diff --git a/ares/ps1/cpu/cpu.cpp b/ares/ps1/cpu/cpu.cpp index f996312757..5bb6734666 100644 --- a/ares/ps1/cpu/cpu.cpp +++ b/ares/ps1/cpu/cpu.cpp @@ -38,7 +38,7 @@ auto CPU::main() -> void { synchronize(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { Thread::clock += clocks; } @@ -134,7 +134,7 @@ auto CPU::instructionHook() -> void { ipu.pd = pc; ipu.r[28] = gp; - for(uint address : range(exe.size - source)) { + for(u32 address : range(exe.size - source)) { ram.writeByte(target + address, exe.readByte(source + address)); } } @@ -155,7 +155,7 @@ auto CPU::instructionDebug() -> void { if(mask[ipu.pc >> 2 & 0x07ff'ffff]) return; mask[ipu.pc >> 2 & 0x07ff'ffff] = 1; - static uint counter = 0; + static u32 counter = 0; //if(++counter > 100) return; print( disassembler.hint(hex(pipeline.address, 8L)), " ", diff --git a/ares/ps1/cpu/cpu.hpp b/ares/ps1/cpu/cpu.hpp index 3d6149df13..b37149f997 100644 --- a/ares/ps1/cpu/cpu.hpp +++ b/ares/ps1/cpu/cpu.hpp @@ -40,7 +40,7 @@ struct CPU : Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto synchronize() -> void; auto instruction() -> void; @@ -65,9 +65,9 @@ struct CPU : Thread { //branch delay slots struct Branch { - uint1 slot; - uint1 take; - uint32 address; + n1 slot; + n1 take; + n32 address; } branch[2]; //interrupt delay counter @@ -77,15 +77,15 @@ struct CPU : Thread { auto load(u32& target) const -> u32; auto load(u32& target, u32 source) -> void; auto store(u32& target, u32 source) -> void; - template auto branch(u32 address, bool take = true) -> void; + template auto branch(u32 address, bool take = true) -> void; auto processDelayLoad() -> void; auto processDelayBranch() -> void; //memory.cpp auto fetch(u32 address) -> u32; - template auto read(u32 address) -> u32; - template auto write(u32 address, u32 data) -> void; + template auto read(u32 address) -> u32; + template auto write(u32 address, u32 data) -> void; //cache.cpp struct InstructionCache { @@ -108,11 +108,11 @@ struct CPU : Thread { Exception(CPU& self) : self(self) {} auto operator()() -> bool; - auto trigger(uint code) -> void; + auto trigger(u32 code) -> void; auto interruptsPending() -> u8; auto interrupt() -> void; - template auto address(u32 address) -> void; + template auto address(u32 address) -> void; auto busInstruction() -> void; auto busData() -> void; auto systemCall() -> void; @@ -131,7 +131,7 @@ struct CPU : Thread { Breakpoint(CPU& self) : self(self) {} auto testCode(u32 address) -> bool; - template auto testData(u32 address) -> bool; + template auto testData(u32 address) -> bool; u32 lastPC; } breakpoint{*this}; @@ -243,27 +243,27 @@ struct CPU : Thread { // 7: Breakpoint Control struct Status { - uint1 any; - uint1 code; - uint1 data; - uint1 read; - uint1 write; - uint1 trace; + n1 any; + n1 code; + n1 data; + n1 read; + n1 write; + n1 trace; } status; - uint2 redirection; - uint2 unknown; + n2 redirection; + n2 unknown; struct Test { - uint1 code; - uint1 data; - uint1 read; - uint1 write; - uint1 trace; + n1 code; + n1 data; + n1 read; + n1 write; + n1 trace; } test; struct Enable { - uint1 master; - uint1 kernel; - uint1 user; - uint1 trap; + n1 master; + n1 kernel; + n1 user; + n1 trap; } enable; } breakpoint; @@ -276,35 +276,35 @@ struct CPU : Thread { //12: Status struct Status { struct Frame { - uint1 interruptEnable; - uint1 userMode; + n1 interruptEnable; + n1 userMode; } frame[3]; - uint8 interruptMask; + n8 interruptMask; struct Cache { - uint1 isolate; - uint1 swap; - uint1 parityZero; - uint1 loadWasData; - uint1 parityError; + n1 isolate; + n1 swap; + n1 parityZero; + n1 loadWasData; + n1 parityError; } cache; - uint1 tlbShutdown; - uint1 vectorLocation; - uint1 reverseEndian; + n1 tlbShutdown; + n1 vectorLocation; + n1 reverseEndian; struct Enable { - uint1 coprocessor0; - uint1 coprocessor1; - uint1 coprocessor2; - uint1 coprocessor3; + n1 coprocessor0; + n1 coprocessor1; + n1 coprocessor2; + n1 coprocessor3; } enable; } status; //13: Cause struct Cause { - uint5 exceptionCode; - uint8 interruptPending; - uint2 coprocessorError; - uint1 branchTaken; - uint1 branchDelay; + n5 exceptionCode; + n8 interruptPending; + n2 coprocessorError; + n1 branchTaken; + n1 branchDelay; } cause; //14: Exception Program Counter @@ -368,23 +368,23 @@ struct CPU : Thread { //gte.cpp auto constructTable() -> void; - auto countLeadingZeroes16(u16) -> uint; - auto countLeadingZeroes32(u32) -> uint; + auto countLeadingZeroes16(u16) -> u32; + auto countLeadingZeroes32(u32) -> u32; - auto getDataRegister(uint) -> u32; - auto setDataRegister(uint, u32) -> void; + auto getDataRegister(u32) -> u32; + auto setDataRegister(u32, u32) -> void; - auto getControlRegister(uint) -> u32; - auto setControlRegister(uint, u32) -> void; + auto getControlRegister(u32) -> u32; + auto setControlRegister(u32, u32) -> void; - template auto checkMac(s64 value) -> s64; - template auto extend(s64 mac) -> s64; - template auto saturateIr(s32 value, bool lm = 0) -> s32; - template auto saturateColor(s32 value) -> u8; + template auto checkMac(s64 value) -> s64; + template auto extend(s64 mac) -> s64; + template auto saturateIr(s32 value, bool lm = 0) -> s32; + template auto saturateColor(s32 value) -> u8; - template auto setMac(s64 value) -> s64; - template auto setIr(s32 value, bool lm = 0) -> void; - template auto setMacAndIr(s64 value, bool lm = 0) -> void; + template auto setMac(s64 value) -> s64; + template auto setIr(s32 value, bool lm = 0) -> void; + template auto setMacAndIr(s64 value, bool lm = 0) -> void; auto setMacAndIr(const v64& vector) -> void; auto setOtz(s64 value) -> void; @@ -419,7 +419,7 @@ struct CPU : Thread { auto MFC2(u32& rt, u8 rd) -> void; auto MTC2(cu32& rt, u8 rd) -> void; auto MVMVA(bool lm, u8 tv, u8 mv, u8 mm, u8 sf) -> void; - template auto NC(const v16&) -> void; + template auto NC(const v16&) -> void; auto NCCS(bool lm, u8 sf) -> void; auto NCCT(bool lm, u8 sf) -> void; auto NCDS(bool lm, u8 sf) -> void; diff --git a/ares/ps1/cpu/debugger.cpp b/ares/ps1/cpu/debugger.cpp index 71e8007376..000f81752f 100644 --- a/ares/ps1/cpu/debugger.cpp +++ b/ares/ps1/cpu/debugger.cpp @@ -104,7 +104,7 @@ auto CPU::Debugger::messageChar(char c) -> void { auto CPU::Debugger::messageText(u32 address) -> void { if(!tracer.message->enabled()) return; - for(uint index : range(512)) { + for(u32 index : range(512)) { char data = bus.read(address + index); if(!data) break; messageChar(data); @@ -155,7 +155,7 @@ auto CPU::Debugger::function() -> void { auto text = [](u32 address) -> string { string output; output.append("\""); - for(uint n : range(256)) { + for(u32 n : range(256)) { char value = bus.read(address + n); if(!value) break; else if(value == 0x09) output.append("\\t"); diff --git a/ares/ps1/cpu/delay-slots.cpp b/ares/ps1/cpu/delay-slots.cpp index f4a13efcb0..5dd6284612 100644 --- a/ares/ps1/cpu/delay-slots.cpp +++ b/ares/ps1/cpu/delay-slots.cpp @@ -20,7 +20,7 @@ inline auto CPU::store(u32& target, u32 source) -> void { target = source; } -template +template inline auto CPU::branch(u32 address, bool take) -> void { delay.branch[N].slot = true; delay.branch[N].take = take; diff --git a/ares/ps1/cpu/disassembler.cpp b/ares/ps1/cpu/disassembler.cpp index 42fca0ac78..b88b3d312c 100644 --- a/ares/ps1/cpu/disassembler.cpp +++ b/ares/ps1/cpu/disassembler.cpp @@ -285,11 +285,11 @@ auto CPU::Disassembler::GTE() -> vector { case 0x06: return {"ctc2", rtValue(), crName()}; } if(!(instruction >> 25 & 1)) return {}; - uint lm = instruction >> 10 & 1; - uint tv = instruction >> 13 & 3; - uint mv = instruction >> 15 & 3; - uint mm = instruction >> 17 & 3; - uint sf = instruction >> 19 & 1; + u32 lm = instruction >> 10 & 1; + u32 tv = instruction >> 13 & 3; + u32 mv = instruction >> 15 & 3; + u32 mm = instruction >> 17 & 3; + u32 sf = instruction >> 19 & 1; switch(instruction & 0x3f) { case 0x00: return {"rtps", lm, sf}; //0x01 mirror? case 0x01: return {"rtps", lm, sf}; diff --git a/ares/ps1/cpu/exceptions.cpp b/ares/ps1/cpu/exceptions.cpp index d6f0a29902..205f941868 100644 --- a/ares/ps1/cpu/exceptions.cpp +++ b/ares/ps1/cpu/exceptions.cpp @@ -3,7 +3,7 @@ auto CPU::Exception::operator()() -> bool { return triggered; } -auto CPU::Exception::trigger(uint code) -> void { +auto CPU::Exception::trigger(u32 code) -> void { triggered = true; self.debugger.exception(code); @@ -43,7 +43,7 @@ auto CPU::Exception::interrupt() -> void { trigger(0); } -template +template auto CPU::Exception::address(u32 address) -> void { if constexpr(Mode == Read ) trigger(4); if constexpr(Mode == Write) trigger(5); diff --git a/ares/ps1/cpu/gte.cpp b/ares/ps1/cpu/gte.cpp index b154f3cd85..832264f159 100644 --- a/ares/ps1/cpu/gte.cpp +++ b/ares/ps1/cpu/gte.cpp @@ -1,18 +1,18 @@ auto CPU::GTE::constructTable() -> void { - for(uint n : range(256)) { + for(u32 n : range(256)) { unsignedNewtonRaphsonTable[n] = max(0, (0x40000 / (n + 0x100) + 1) / 2 - 0x101); } unsignedNewtonRaphsonTable[256] = 0; } -auto CPU::GTE::countLeadingZeroes16(u16 value) -> uint { - uint zeroes = 0; +auto CPU::GTE::countLeadingZeroes16(u16 value) -> u32 { + u32 zeroes = 0; while(!(value >> 15) && zeroes < 16) value <<= 1, zeroes++; return zeroes; } -auto CPU::GTE::countLeadingZeroes32(u32 value) -> uint { - uint zeroes = 0; +auto CPU::GTE::countLeadingZeroes32(u32 value) -> u32 { + u32 zeroes = 0; if(!(value >> 31)) value = ~value; while(value >> 31) value <<= 1, zeroes++; return zeroes; @@ -20,7 +20,7 @@ auto CPU::GTE::countLeadingZeroes32(u32 value) -> uint { // -auto CPU::GTE::getDataRegister(uint index) -> u32 { +auto CPU::GTE::getDataRegister(u32 index) -> u32 { u32 data; switch(index) { case 0: data = u16(v.a.x) << 0 | u16(v.a.y) << 16; break; @@ -64,7 +64,7 @@ auto CPU::GTE::getDataRegister(uint index) -> u32 { return data; } -auto CPU::GTE::setDataRegister(uint index, u32 data) -> void { +auto CPU::GTE::setDataRegister(u32 index, u32 data) -> void { switch(index) { case 0: v.a.x = data >> 0; v.a.y = data >> 16; break; case 1: v.a.z = data >> 0; break; @@ -114,7 +114,7 @@ auto CPU::GTE::setDataRegister(uint index, u32 data) -> void { } } -auto CPU::GTE::getControlRegister(uint index) -> u32 { +auto CPU::GTE::getControlRegister(u32 index) -> u32 { u32 data; switch(index) { case 0: data = u16(rotation.a.x) << 0 | u16(rotation.a.y) << 16; break; @@ -153,7 +153,7 @@ auto CPU::GTE::getControlRegister(uint index) -> u32 { return data; } -auto CPU::GTE::setControlRegister(uint index, u32 data) -> void { +auto CPU::GTE::setControlRegister(u32 index, u32 data) -> void { switch(index) { case 0: rotation.a.x = data >> 0; rotation.a.y = data >> 16; break; case 1: rotation.a.z = data >> 0; rotation.b.x = data >> 16; break; @@ -192,7 +192,7 @@ auto CPU::GTE::setControlRegister(uint index, u32 data) -> void { // -template +template auto CPU::GTE::checkMac(s64 value) -> s64 { static constexpr s64 min = -(s64(1) << (id == 0 ? 31 : 43)); static constexpr s64 max = +(s64(1) << (id == 0 ? 31 : 43)) - 1; @@ -211,7 +211,7 @@ auto CPU::GTE::checkMac(s64 value) -> s64 { return value; } -template +template auto CPU::GTE::extend(s64 mac) -> s64 { checkMac(mac); if constexpr(id == 1) return sclip<44>(mac); @@ -220,7 +220,7 @@ auto CPU::GTE::extend(s64 mac) -> s64 { unreachable; } -template +template auto CPU::GTE::saturateIr(s32 value, bool lm) -> s32 { static constexpr s32 min = id == 0 ? 0x0000 : -0x8000; static constexpr s32 max = id == 0 ? 0x1000 : +0x7fff; @@ -242,7 +242,7 @@ auto CPU::GTE::saturateIr(s32 value, bool lm) -> s32 { return value; } -template +template auto CPU::GTE::saturateColor(s32 value) -> u8 { if(value < 0 || value > 255) { if constexpr(id == 0) flag.r_saturated = 1; @@ -255,7 +255,7 @@ auto CPU::GTE::saturateColor(s32 value) -> u8 { // -template +template auto CPU::GTE::setMac(s64 value) -> s64 { checkMac(value); if constexpr(id == 0) { mac.t = value; return value; } @@ -264,7 +264,7 @@ auto CPU::GTE::setMac(s64 value) -> s64 { if constexpr(id == 3) { mac.z = value >> sf; return value >> sf; } } -template +template auto CPU::GTE::setIr(s32 value, bool lm) -> void { if constexpr(id == 0) ir.t = saturateIr<0>(value, lm); if constexpr(id == 1) ir.x = saturateIr<1>(value, lm); @@ -272,7 +272,7 @@ auto CPU::GTE::setIr(s32 value, bool lm) -> void { if constexpr(id == 3) ir.z = saturateIr<3>(value, lm); } -template +template auto CPU::GTE::setMacAndIr(s64 value, bool lm) -> void { setIr(setMac(value), lm); } @@ -569,7 +569,7 @@ auto CPU::GTE::MVMVA(bool lm, u8 tv, u8 mv, u8 mm, u8 sf) -> void { } //meta-instruction -template +template auto CPU::GTE::NC(const v16& vector) -> void { setMacAndIr(matrixMultiply(light, vector)); setMacAndIr(matrixMultiply(color, ir, backgroundColor)); diff --git a/ares/ps1/cpu/memory.cpp b/ares/ps1/cpu/memory.cpp index c4167861d9..4177162346 100644 --- a/ares/ps1/cpu/memory.cpp +++ b/ares/ps1/cpu/memory.cpp @@ -45,7 +45,7 @@ inline auto CPU::fetch(u32 address) -> u32 { } //read data from the bus -template +template inline auto CPU::read(u32 address) -> u32 { if constexpr(Accuracy::CPU::Breakpoints) { if(breakpoint.testData(address)) return 0; //nop @@ -165,7 +165,7 @@ inline auto CPU::read(u32 address) -> u32 { } //write data to the bus -template +template inline auto CPU::write(u32 address, u32 data) -> void { if constexpr(Accuracy::CPU::Breakpoints) { if(breakpoint.testData(address)) return; diff --git a/ares/ps1/cpu/scc.cpp b/ares/ps1/cpu/scc.cpp index 3662dd49cb..a46a51a524 100644 --- a/ares/ps1/cpu/scc.cpp +++ b/ares/ps1/cpu/scc.cpp @@ -1,5 +1,5 @@ auto CPU::getControlRegister(u8 index) -> u32 { - uint32 data = 0; + n32 data = 0; switch(index & 15) { @@ -94,7 +94,7 @@ auto CPU::getControlRegister(u8 index) -> u32 { } auto CPU::setControlRegister(u8 index, u32 value) -> void { - uint32 data = value; + n32 data = value; switch(index & 15) { diff --git a/ares/ps1/disc/cdxa.cpp b/ares/ps1/disc/cdxa.cpp index 5b09885601..a07f39e783 100644 --- a/ares/ps1/disc/cdxa.cpp +++ b/ares/ps1/disc/cdxa.cpp @@ -10,21 +10,21 @@ auto Disc::CDXA::unload() -> void { } auto Disc::CDXA::clockSector() -> void { - uint8 subMode = drive->sector.data[18]; - uint1 endOfRecord = subMode.bit(0); - uint1 video = subMode.bit(1); - uint1 audio = subMode.bit(2); - uint1 data = subMode.bit(3); - uint1 trigger = subMode.bit(4); - uint1 form2 = subMode.bit(5); - uint1 realTime = subMode.bit(6); - uint1 endOfFile = subMode.bit(7); - - uint8 codingInfo = drive->sector.data[19]; - uint1 stereo = codingInfo.bit(0); - uint16 sampleRate = codingInfo.bit(2) ? 18900 : 37800; - uint32 bitsPerSample = codingInfo.bit(4) ? 8 : 4; - uint1 emphasis = codingInfo.bit(6); + n8 subMode = drive->sector.data[18]; + n1 endOfRecord = subMode.bit(0); + n1 video = subMode.bit(1); + n1 audio = subMode.bit(2); + n1 data = subMode.bit(3); + n1 trigger = subMode.bit(4); + n1 form2 = subMode.bit(5); + n1 realTime = subMode.bit(6); + n1 endOfFile = subMode.bit(7); + + n8 codingInfo = drive->sector.data[19]; + n1 stereo = codingInfo.bit(0); + n16 sampleRate = codingInfo.bit(2) ? 18900 : 37800; + n32 bitsPerSample = codingInfo.bit(4) ? 8 : 4; + n1 emphasis = codingInfo.bit(6); if(stereo == 0 && bitsPerSample == 4) decodeADPCM<0, 0>(); if(stereo == 0 && bitsPerSample == 8) decodeADPCM<0, 1>(); @@ -65,7 +65,7 @@ auto Disc::CDXA::decodeADPCM() -> void { const u32 SamplesPerBlock = WordsPerBlock * (is8bit ? 4 : 8); s16 output[SamplesPerBlock]; - for(uint block : range(Blocks)) { + for(u32 block : range(Blocks)) { decodeBlock(output, 24 + block * BlockSize); for(auto sample : output) { if(!samples.full()) samples.write(sample); @@ -80,15 +80,15 @@ auto Disc::CDXA::decodeBlock(s16* output, u16 address) -> void { static constexpr u32 Blocks = is8bit ? 4 : 8; static constexpr u32 WordsPerBlock = 28; - for(uint block : range(Blocks)) { - u8 header = drive->sector.data[address + 4 + block]; - u8 shift = (header & 0x0f) > 12 ? 9 : (header & 0x0f); - u8 filter = (header & 0x30) >> 4; + for(u32 block : range(Blocks)) { + u8 header = drive->sector.data[address + 4 + block]; + u8 shift = (header & 0x0f) > 12 ? 9 : (header & 0x0f); + u8 filter = (header & 0x30) >> 4; s32 positive = filterPositive[filter]; s32 negative = filterNegative[filter]; u16 index = isStereo ? (block >> 1) * (WordsPerBlock << 1) + (block & 1) : block * WordsPerBlock; - for(uint word : range(WordsPerBlock)) { + for(u32 word : range(WordsPerBlock)) { u32 data = 0; data |= drive->sector.data[address + 16 + word * 4 + 0] << 0; data |= drive->sector.data[address + 16 + word * 4 + 1] << 8; diff --git a/ares/ps1/disc/command.cpp b/ares/ps1/disc/command.cpp index dcb7515e7a..7fa9585845 100644 --- a/ares/ps1/disc/command.cpp +++ b/ares/ps1/disc/command.cpp @@ -1,5 +1,5 @@ auto Disc::status() -> u8 { - uint8 data; + n8 data; data.bit(0) = ssr.error; data.bit(1) = ssr.motorOn; data.bit(2) = ssr.seekError; @@ -275,7 +275,7 @@ auto Disc::commandSetFilter() -> void { //0x0e auto Disc::commandSetMode() -> void { - uint8 data = fifo.parameter.read(0); + n8 data = fifo.parameter.read(0); drive.mode.cdda = data.bit(0); drive.mode.autoPause = data.bit(1); drive.mode.report = data.bit(2); @@ -293,10 +293,10 @@ auto Disc::commandSetMode() -> void { //0x11 auto Disc::commandGetLocationPlaying() -> void { - int lba = drive.lba.current; - int lbaTrack = 0; - int lbaTrackID = 0; - int lbaIndexID = 0; + s32 lba = drive.lba.current; + s32 lbaTrack = 0; + s32 lbaTrackID = 0; + s32 lbaIndexID = 0; if(auto trackID = session.inTrack(lba)) { lbaTrackID = *trackID; if(auto track = session.track(*trackID)) { @@ -367,7 +367,7 @@ auto Disc::commandGetFirstAndLastTrackNumbers() -> void { auto Disc::commandGetTrackStart() -> void { u8 trackID = fifo.parameter.read(0); - int lba = 0; + s32 lba = 0; if(!trackID) { lba = session.leadOut.lba; } else if(auto track = session.track(trackID)) { diff --git a/ares/ps1/disc/debugger.cpp b/ares/ps1/disc/debugger.cpp index 20b1e9c29d..e4207a1f45 100644 --- a/ares/ps1/disc/debugger.cpp +++ b/ares/ps1/disc/debugger.cpp @@ -116,7 +116,7 @@ auto Disc::Debugger::commandPrologue(u8 operation, maybe suboperation) -> vo _command = name; _command.append("("); - for(uint index : range(disc.fifo.parameter.size())) { + for(u32 index : range(disc.fifo.parameter.size())) { u8 data = disc.fifo.parameter.peek(index); _command.append("$", hex(data, 2L), ","); } @@ -129,7 +129,7 @@ auto Disc::Debugger::commandEpilogue(u8 operation, maybe suboperation) -> vo if(operation == 0x19 && !suboperation) return; _command.append(" = {"); - for(uint index : range(disc.fifo.response.size())) { + for(u32 index : range(disc.fifo.response.size())) { u8 data = disc.fifo.response.peek(index); _command.append("$", hex(data, 2L), ","); } @@ -139,7 +139,7 @@ auto Disc::Debugger::commandEpilogue(u8 operation, maybe suboperation) -> vo tracer.command->notify(_command); } -auto Disc::Debugger::read(int lba) -> void { +auto Disc::Debugger::read(s32 lba) -> void { if(!tracer.read->enabled()) return; auto [minute, second, frame] = CD::MSF::fromLBA(lba); diff --git a/ares/ps1/disc/disc.cpp b/ares/ps1/disc/disc.cpp index eed262197e..aa66c73494 100644 --- a/ares/ps1/disc/disc.cpp +++ b/ares/ps1/disc/disc.cpp @@ -68,10 +68,10 @@ auto Disc::connect() -> void { if(!fd) return disconnect(); //read TOC (table of contents) from disc lead-in - uint sectors = min(7500, fd->size() / 2448); - vector subchannel; + u32 sectors = fd->size() / 2448; + vector subchannel; subchannel.resize(sectors * 96); - for(uint sector : range(sectors)) { + for(u32 sector : range(sectors)) { fd->seek(sector * 2448 + 2352); fd->read(subchannel.data() + sector * 96, 96); } @@ -125,10 +125,10 @@ auto Disc::main() -> void { if(counter.report <= 0) { counter.report += 33'868'800 / 75; - int lba = drive.lba.current; - int lbaTrack = 0; - u8 inTrack = 0; - u8 inIndex = 0; + s32 lba = drive.lba.current; + s32 lbaTrack = 0; + u8 inTrack = 0; + u8 inIndex = 0; if(auto trackID = session.inTrack(lba)) { inTrack = *trackID; if(auto track = session.track(inTrack)) { @@ -169,7 +169,7 @@ auto Disc::main() -> void { step(128); } -auto Disc::step(uint clocks) -> void { +auto Disc::step(u32 clocks) -> void { Thread::clock += clocks; } diff --git a/ares/ps1/disc/disc.hpp b/ares/ps1/disc/disc.hpp index 9ecaeba386..c82b1300b3 100644 --- a/ares/ps1/disc/disc.hpp +++ b/ares/ps1/disc/disc.hpp @@ -10,7 +10,7 @@ struct Disc : Thread, Memory::Interface { auto load(Node::Object) -> void; auto commandPrologue(u8 operation, maybe suboperation = nothing) -> void; auto commandEpilogue(u8 operation, maybe suboperation = nothing) -> void; - auto read(int lba) -> void; + auto read(s32 lba) -> void; struct Tracer { Node::Debugger::Tracer::Notification command; @@ -36,7 +36,7 @@ struct Disc : Thread, Memory::Interface { auto disconnect() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp @@ -93,39 +93,39 @@ struct Disc : Thread, Memory::Interface { maybe cdxa; //drive.cpp - auto distance() const -> uint; + auto distance() const -> u32; auto clockSector() -> void; struct LBA { - int current; - int request; - int seeking; + s32 current; + s32 request; + s32 seeking; } lba; struct Sector { - u8 data[2448]; + u8 data[2448]; u16 offset; } sector; struct Mode { - uint1 cdda; - uint1 autoPause; - uint1 report; - uint1 xaFilter; - uint1 ignore; - uint1 sectorSize; - uint1 xaADPCM; - uint1 speed; + n1 cdda; + n1 autoPause; + n1 report; + n1 xaFilter; + n1 ignore; + n1 sectorSize; + n1 xaADPCM; + n1 speed; } mode; - uint32 seeking; + n32 seeking; } drive{*this}; struct Audio { - uint1 mute; - uint1 muteADPCM; - uint8 volume[4]; - uint8 volumeLatch[4]; + n1 mute; + n1 muteADPCM; + n8 volume[4]; + n8 volumeLatch[4]; } audio; struct CDDA { @@ -142,7 +142,7 @@ struct Disc : Thread, Memory::Interface { auto clockSector() -> void; auto clockSample() -> void; - enum class PlayMode : uint { + enum class PlayMode : u32 { Normal, FastForward, Rewind, @@ -171,8 +171,8 @@ struct Disc : Thread, Memory::Interface { template auto decodeBlock(s16* output, u16 address) -> void; struct Filter { - uint8 file; - uint8 channel; + n8 file; + n8 channel; } filter; struct Sample { @@ -197,12 +197,12 @@ struct Disc : Thread, Memory::Interface { auto poll() -> void; struct Source { - uint1 enable; - uint1 flag; + n1 enable; + n1 flag; }; - uint5 flag; - uint5 mask; + n5 flag; + n5 mask; Source ready; //INT1 Source complete; //INT2 @@ -223,18 +223,18 @@ struct Disc : Thread, Memory::Interface { } psr; struct SecondaryStatusRegister { - uint1 error; - uint1 motorOn; - uint1 seekError; - uint1 idError; - uint1 shellOpen; - uint1 reading; - uint1 seeking; - uint1 playingCDDA; + n1 error; + n1 motorOn; + n1 seekError; + n1 idError; + n1 shellOpen; + n1 reading; + n1 seeking; + n1 playingCDDA; } ssr; struct IO { - uint2 index; + n2 index; } io; struct Counter { diff --git a/ares/ps1/disc/drive.cpp b/ares/ps1/disc/drive.cpp index aa05cd08fd..1d013a1337 100644 --- a/ares/ps1/disc/drive.cpp +++ b/ares/ps1/disc/drive.cpp @@ -1,5 +1,5 @@ //computes the distance between the current LBA and seeking LBA -auto Disc::Drive::distance() const -> uint { +auto Disc::Drive::distance() const -> u32 { return 0; } @@ -16,7 +16,7 @@ auto Disc::Drive::clockSector() -> void { if(self.ssr.playingCDDA) { if(cdda->playMode == Disc::CDDA::PlayMode::FastForward) { - int end = 0; + s32 end = 0; if(auto trackID = session->inTrack(lba.current)) { if(auto track = session->track(*trackID)) { if(auto index = track->index(track->lastIndex)) { @@ -28,7 +28,7 @@ auto Disc::Drive::clockSector() -> void { lba.current = min(end, lba.current + 10); } if(cdda->playMode == Disc::CDDA::PlayMode::Rewind) { - int start = 0; + s32 start = 0; if(auto trackID = session->inTrack(lba.current)) { if(auto track = session->track(*trackID)) { if(auto index = track->index(1)) { @@ -60,13 +60,13 @@ auto Disc::Drive::clockSector() -> void { self.fifo.data.flush(); if(mode.sectorSize == 0) { - for(uint offset : range(2048)) { + for(u32 offset : range(2048)) { self.fifo.data.write(sector.data[24 + offset]); } } if(mode.sectorSize == 1) { - for(uint offset : range(2340)) { + for(u32 offset : range(2340)) { self.fifo.data.write(sector.data[12 + offset]); } } diff --git a/ares/ps1/disc/io.cpp b/ares/ps1/disc/io.cpp index 3b1da090ef..b19132ff39 100644 --- a/ares/ps1/disc/io.cpp +++ b/ares/ps1/disc/io.cpp @@ -8,7 +8,7 @@ auto Disc::readDMA() -> u32 { } auto Disc::readByte(u32 address) -> u32 { - uint8 data = 0; + n8 data = 0; if(address == 0x1f80'1800) { data.bit(0) = io.index.bit(0); @@ -45,7 +45,7 @@ auto Disc::readByte(u32 address) -> u32 { //interrupt flag if(address == 0x1f80'1803 && (io.index == 1 || io.index == 3)) { - uint3 flags = 0; + n3 flags = 0; if(irq.error.flag ) flags = 5; if(irq.end.flag ) flags = 4; if(irq.acknowledge.flag) flags = 3; @@ -64,18 +64,18 @@ auto Disc::readByte(u32 address) -> u32 { auto Disc::readHalf(u32 address) -> u32 { debug(unverified, "Disc::readHalf(", hex(address, 8L), ")"); - uint16 data = readByte(address & ~1 | 0) << 0; + n16 data = readByte(address & ~1 | 0) << 0; return data | readByte(address & ~1 | 1) << 8; } auto Disc::readWord(u32 address) -> u32 { debug(unverified, "Disc::readWord(", hex(address, 8L), ")"); - uint32 data = readHalf(address & ~3 | 0) << 0; + n32 data = readHalf(address & ~3 | 0) << 0; return data | readHalf(address & ~3 | 2) << 16; } auto Disc::writeByte(u32 address, u32 value) -> void { - uint8 data = value; + n8 data = value; if(address == 0x1f80'1800) { io.index = data.bit(0,1); diff --git a/ares/ps1/disc/serialization.cpp b/ares/ps1/disc/serialization.cpp index 3ddaba7f3a..32c7c224bb 100644 --- a/ares/ps1/disc/serialization.cpp +++ b/ares/ps1/disc/serialization.cpp @@ -21,7 +21,7 @@ auto Disc::serialize(serializer& s) -> void { s(audio.volume); s(audio.volumeLatch); - s((uint&)cdda.playMode); + s((u32&)cdda.playMode); s(cdda.sample.left); s(cdda.sample.right); diff --git a/ares/ps1/dma/channel.cpp b/ares/ps1/dma/channel.cpp index 32a0d43350..d7e40f203c 100644 --- a/ares/ps1/dma/channel.cpp +++ b/ares/ps1/dma/channel.cpp @@ -1,8 +1,8 @@ auto DMA::sortChannelsByPriority() -> void { - uint1 selected[7]; - for(uint index : range(7)) { - uint id = 8, lowest = 8; - for(uint search : range(7)) { + n1 selected[7]; + for(u32 index : range(7)) { + u32 id = 8, lowest = 8; + for(u32 search : range(7)) { if(selected[search]) continue; if(channels[search].priority < lowest) { lowest = channels[search].priority; @@ -14,7 +14,7 @@ auto DMA::sortChannelsByPriority() -> void { } } -auto DMA::Channel::step(uint clocks) -> bool { +auto DMA::Channel::step(u32 clocks) -> bool { if(!masterEnable || !counter) return false; if(counter > clocks) { @@ -137,7 +137,7 @@ auto DMA::Channel::transferChain() -> void { u32 timeout = 0x1000; do { - uint32 data = bus.read(address & 0xfffffc); + n32 data = bus.read(address & 0xfffffc); address += 4; clocks += 1; diff --git a/ares/ps1/dma/debugger.cpp b/ares/ps1/dma/debugger.cpp index c02b6413fd..f63769ccc0 100644 --- a/ares/ps1/dma/debugger.cpp +++ b/ares/ps1/dma/debugger.cpp @@ -2,7 +2,7 @@ auto DMA::Debugger::load(Node::Object parent) -> void { tracer.dma = parent->append("Transfer", "DMA"); } -auto DMA::Debugger::transfer(uint channelID) -> void { +auto DMA::Debugger::transfer(u32 channelID) -> void { if(tracer.dma->enabled()) { static const char* channelName[7] = { "MDEC", "MDEC", " GPU", " CD", " SPU", " PIO", " OTC" diff --git a/ares/ps1/dma/dma.cpp b/ares/ps1/dma/dma.cpp index f90f28a8a3..6b0fe68e54 100644 --- a/ares/ps1/dma/dma.cpp +++ b/ares/ps1/dma/dma.cpp @@ -20,19 +20,19 @@ auto DMA::unload() -> void { } auto DMA::main() -> void { - for(uint id : channelsByPriority) { + for(u32 id : channelsByPriority) { if(channels[id].step(16)) break; } step(16); } -auto DMA::step(uint clocks) -> void { +auto DMA::step(u32 clocks) -> void { Thread::clock += clocks; } auto DMA::power(bool reset) -> void { Memory::Interface::setWaitStates(3, 3, 2); - for(uint n : range(7)) { + for(u32 n : range(7)) { channels[n].priority = 1 + n; } sortChannelsByPriority(); diff --git a/ares/ps1/dma/dma.hpp b/ares/ps1/dma/dma.hpp index df7f4f419a..5f278d7c1e 100644 --- a/ares/ps1/dma/dma.hpp +++ b/ares/ps1/dma/dma.hpp @@ -4,7 +4,7 @@ struct DMA : Thread, Memory::Interface { struct Debugger { //debugger.cpp auto load(Node::Object) -> void; - auto transfer(uint channel) -> void; + auto transfer(u32 channel) -> void; struct Tracer { Node::Debugger::Tracer::Notification dma; @@ -16,7 +16,7 @@ struct DMA : Thread, Memory::Interface { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp @@ -33,8 +33,8 @@ struct DMA : Thread, Memory::Interface { //serialization.cpp auto serialize(serializer&) -> void; - enum : uint { MDECin, MDECout, GPU, CDROM, SPU, PIO, OTC }; //channel IDs - enum : uint { Waiting, Running }; //channel states + enum : u32 { MDECin, MDECout, GPU, CDROM, SPU, PIO, OTC }; //channel IDs + enum : u32 { Waiting, Running }; //channel states struct IRQ { DMA& self; @@ -43,53 +43,53 @@ struct DMA : Thread, Memory::Interface { //irq.cpp auto poll() -> void; - uint1 force; - uint1 enable; - uint1 flag; - uint6 unknown; + n1 force; + n1 enable; + n1 flag; + n6 unknown; } irq{*this}; struct Channel { - const uint id; + const u32 id; //channel.cpp - auto step(uint clocks) -> bool; + auto step(u32 clocks) -> bool; auto transferBlock() -> void; auto transferChain() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint1 masterEnable; - uint3 priority; - uint24 address; - uint16 length; - uint16 blocks; - uint1 direction; - uint1 decrement; - uint2 synchronization; + n1 masterEnable; + n3 priority; + n24 address; + n16 length; + n16 blocks; + n1 direction; + n1 decrement; + n2 synchronization; struct Chopping { - uint1 enable; - uint3 dmaWindow; - uint3 cpuWindow; + n1 enable; + n3 dmaWindow; + n3 cpuWindow; } chopping; - uint1 enable; - uint1 trigger; - uint2 unknown; + n1 enable; + n1 trigger; + n2 unknown; struct IRQ { - uint1 enable; - uint1 flag; + n1 enable; + n1 flag; } irq; struct Chain { - uint24 address; - uint8 length; + n24 address; + n8 length; } chain; - uint8 state; - int32 counter; + n8 state; + i32 counter; } channels[7] = {{0}, {1}, {2}, {3}, {4}, {5}, {6}}; - uint channelsByPriority[7]; + u32 channelsByPriority[7]; }; extern DMA dma; diff --git a/ares/ps1/dma/io.cpp b/ares/ps1/dma/io.cpp index ac36663486..6d5acfcdac 100644 --- a/ares/ps1/dma/io.cpp +++ b/ares/ps1/dma/io.cpp @@ -1,5 +1,5 @@ auto DMA::readByte(u32 address) -> u32 { - uint32 data; + n32 data; if((address & ~3) == 0x1f80'10f0) return data = readWord(address & ~3) >> 8 * (address & 3); if((address & ~3) == 0x1f80'10f4) return data = readWord(address & ~3) >> 8 * (address & 3); if((address & ~3) == 0x1f80'10f8) return data = readWord(address & ~3) >> 8 * (address & 3); @@ -16,7 +16,7 @@ auto DMA::readByte(u32 address) -> u32 { } auto DMA::readHalf(u32 address) -> u32 { - uint32 data; + n32 data; if((address & ~3) == 0x1f80'10f0) return data = readWord(address & ~3) >> 8 * (address & 3); if((address & ~3) == 0x1f80'10f4) return data = readWord(address & ~3) >> 8 * (address & 3); if((address & ~3) == 0x1f80'10f8) return data = readWord(address & ~3) >> 8 * (address & 3); @@ -31,7 +31,7 @@ auto DMA::readHalf(u32 address) -> u32 { } auto DMA::readWord(u32 address) -> u32 { - uint32 data; + n32 data; //DPCR: DMA Control if(address == 0x1f80'10f0) { @@ -118,7 +118,7 @@ auto DMA::readWord(u32 address) -> u32 { } auto DMA::writeByte(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; if((address & ~3) == 0x1f80'10f0) return writeWord(address & ~3, data << 8 * (address & 3)); if((address & ~3) == 0x1f80'10f4) return writeWord(address & ~3, data << 8 * (address & 3)); if((address & ~3) == 0x1f80'10f8) return writeWord(address & ~3, data << 8 * (address & 3)); @@ -134,7 +134,7 @@ auto DMA::writeByte(u32 address, u32 value) -> void { } auto DMA::writeHalf(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; if((address & ~3) == 0x1f80'10f0) return writeWord(address & ~3, data << 8 * (address & 3)); if((address & ~3) == 0x1f80'10f4) return writeWord(address & ~3, data << 8 * (address & 3)); if((address & ~3) == 0x1f80'10f8) return writeWord(address & ~3, data << 8 * (address & 3)); @@ -148,7 +148,7 @@ auto DMA::writeHalf(u32 address, u32 value) -> void { } auto DMA::writeWord(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; //DPCR: DMA Control if(address == 0x1f80'10f0) { diff --git a/ares/ps1/gpu/blitter.cpp b/ares/ps1/gpu/blitter.cpp index 0584720492..f22a0acf0c 100644 --- a/ares/ps1/gpu/blitter.cpp +++ b/ares/ps1/gpu/blitter.cpp @@ -16,22 +16,22 @@ auto GPU::Blitter::queue() -> void { if(height == 480) height = 448; } - int offsetX1 = 0; + s32 offsetX1 = 0; if(self.display.width == 256) offsetX1 = 0x228; if(self.display.width == 320) offsetX1 = 0x260; if(self.display.width == 368) offsetX1 = 0x260; //untested if(self.display.width == 512) offsetX1 = 0x260; if(self.display.width == 640) offsetX1 = 0x260; - int offsetY1 = 0; + s32 offsetY1 = 0; if(self.display.height == 240) offsetY1 = 0x10; if(self.display.height == 480) offsetY1 = 0x10; //target coordinates - tx = max(((int)self.io.displayRangeX1 - offsetX1) / (int)self.display.dotclock, 0); - ty = max(((int)self.io.displayRangeY1 - offsetY1) << self.display.interlace, 0); - tw = max(((int)self.io.displayRangeX2 - (int)self.io.displayRangeX1) / (int)self.display.dotclock & ~3, 0); - th = max(((int)self.io.displayRangeY2 - (int)self.io.displayRangeY1) << self.display.interlace, 0); + tx = max(((s32)self.io.displayRangeX1 - offsetX1) / (s32)self.display.dotclock, 0); + ty = max(((s32)self.io.displayRangeY1 - offsetY1) << self.display.interlace, 0); + tw = max(((s32)self.io.displayRangeX2 - (s32)self.io.displayRangeX1) / (s32)self.display.dotclock & ~3, 0); + th = max(((s32)self.io.displayRangeY2 - (s32)self.io.displayRangeY1) << self.display.interlace, 0); //ensure coordinates cannot go out of bounds of the output region if(tx > 1023) tx = 1023; @@ -75,11 +75,11 @@ auto GPU::Blitter::refresh() -> void { //15bpp if(depth == 0) { - for(uint y : range(th)) { + for(u32 y : range(th)) { if(y + ty < 0 || y + ty >= 512) continue; u32 source = (y + sy) * 1024 * 2 + sx * 2; u32 target = (y + ty) * 640 * 1 + tx * 1; - for(uint x : range(tw)) { + for(u32 x : range(tw)) { u16 data = self.vram.readHalf(source); output[target++] = 1 << 24 | data & 0x7fff; source += 2; @@ -89,11 +89,11 @@ auto GPU::Blitter::refresh() -> void { //24bpp if(depth == 1) { - for(uint y : range(th)) { + for(u32 y : range(th)) { if(y + ty < 0 || y + ty >= 512) continue; u32 source = (y + sy) * 1024 * 2 + sx * 2; u32 target = (y + ty) * 640 * 1 + tx * 1; - for(uint x : range(tw)) { + for(u32 x : range(tw)) { u32 data = self.vram.readWordUnaligned(source); output[target++] = data & 0xffffff; source += 3; diff --git a/ares/ps1/gpu/debugger.cpp b/ares/ps1/gpu/debugger.cpp index e4d27766b9..a8251a56ff 100644 --- a/ares/ps1/gpu/debugger.cpp +++ b/ares/ps1/gpu/debugger.cpp @@ -13,8 +13,8 @@ auto GPU::Debugger::load(Node::Object parent) -> void { graphics.vram15bpp->setCapture([&]() -> vector { vector output; output.resize(1024 * 512); - for(uint y : range(512)) { - for(uint x : range(1024)) { + for(u32 y : range(512)) { + for(u32 x : range(1024)) { u16 pixel = gpu.vram.readHalf(y * 2048 + x * 2); u8 r = pixel >> 0 & 31; r = r << 3 | r >> 2; u8 g = pixel >> 5 & 31; g = g << 3 | g >> 2; @@ -31,8 +31,8 @@ auto GPU::Debugger::load(Node::Object parent) -> void { graphics.vram24bpp->setCapture([&]() -> vector { vector output; output.resize(682 * 512); - for(uint y : range(512)) { - for(uint x : range(682)) { + for(u32 y : range(512)) { + for(u32 x : range(682)) { u32 pixel = gpu.vram.readWordUnaligned(y * 2048 + x * 3); u8 r = pixel >> 0; u8 g = pixel >> 8; diff --git a/ares/ps1/gpu/gp0.cpp b/ares/ps1/gpu/gp0.cpp index 22e0508154..c947d44f10 100644 --- a/ares/ps1/gpu/gp0.cpp +++ b/ares/ps1/gpu/gp0.cpp @@ -1,6 +1,6 @@ //GPUREAD auto GPU::readGP0() -> u32 { - uint32 data; + n32 data; if(io.mode == Mode::Status) { data = io.status; @@ -9,9 +9,9 @@ auto GPU::readGP0() -> u32 { if(io.mode == Mode::CopyFromVRAM) { vram.mutex.lock(); - for(uint loop : range(2)) { - uint10 x = io.copy.x + io.copy.px; - uint9 y = io.copy.y + io.copy.py; + for(u32 loop : range(2)) { + n10 x = io.copy.x + io.copy.px; + n9 y = io.copy.y + io.copy.py; data = vram2D[y][x] << 16 | data >> 16; if(++io.copy.px >= io.copy.width) { io.copy.px = 0; @@ -34,9 +34,9 @@ auto GPU::readGP0() -> u32 { auto GPU::writeGP0(u32 value, bool isThread) -> void { if(io.mode == Mode::CopyToVRAM) { vram.mutex.lock(); - for(uint loop : range(2)) { - uint10 x = io.copy.x + io.copy.px; - uint9 y = io.copy.y + io.copy.py; + for(u32 loop : range(2)) { + n10 x = io.copy.x + io.copy.px; + n9 y = io.copy.y + io.copy.py; vram2D[y][x] = value; value >>= 16; if(++io.copy.px >= io.copy.width) { @@ -55,8 +55,8 @@ auto GPU::writeGP0(u32 value, bool isThread) -> void { auto& queue = this->queue.gp0; - uint8 command = value >> 24; - uint24 data = value >> 0; + n8 command = value >> 24; + n24 data = value >> 0; if(queue.empty()) { queue.command = command; @@ -265,7 +265,7 @@ auto GPU::writeGP0(u32 value, bool isThread) -> void { || command == 0x4c || command == 0x4d || command == 0x4e || command == 0x4f) { if((value & 0xf000f000) != 0x50005000) return (void)queue.write(value); render.v0 = Vertex().setColor(queue.data[0]).setPoint(queue.data[1]); - for(uint n = 2; n < queue.length; n += 1) { + for(u32 n = 2; n < queue.length; n += 1) { render.v1 = Vertex().setColor(queue.data[0]).setPoint(queue.data[n]); renderer.queue(render); render.v0 = render.v1; @@ -288,7 +288,7 @@ auto GPU::writeGP0(u32 value, bool isThread) -> void { || command == 0x5c || command == 0x5d || command == 0x5e || command == 0x5f) { if((value & 0xf000f000) != 0x50005000) return (void)queue.write(value); render.v0 = Vertex().setColor(queue.data[0]).setPoint(queue.data[1]); - for(uint n = 2; n + 1 < queue.length; n += 2) { + for(u32 n = 2; n + 1 < queue.length; n += 2) { render.v1 = Vertex().setColor(queue.data[n + 0]).setPoint(queue.data[n + 1]); renderer.queue(render); render.v0 = render.v1; @@ -387,8 +387,8 @@ auto GPU::writeGP0(u32 value, bool isThread) -> void { u16 targetY = queue.data[2].bit(16,31); u16 width = queue.data[3].bit( 0,15); u16 height = queue.data[3].bit(16,31); - for(uint y : range(height)) { - for(uint x : range(width)) { + for(u32 y : range(height)) { + for(u32 x : range(width)) { u16 data = vram2D[y + sourceY & 511][x + sourceX & 1023]; vram2D[y + targetY & 511][x + targetX & 1023] = data; } diff --git a/ares/ps1/gpu/gp1.cpp b/ares/ps1/gpu/gp1.cpp index 00342fcad6..04359ebe22 100644 --- a/ares/ps1/gpu/gp1.cpp +++ b/ares/ps1/gpu/gp1.cpp @@ -1,6 +1,6 @@ //GPUSTAT auto GPU::readGP1() -> u32 { - uint32 data; + n32 data; data.bit( 0, 3) = io.texturePageBaseX; data.bit( 4) = io.texturePageBaseY; data.bit( 5, 6) = io.semiTransparency; @@ -32,8 +32,8 @@ auto GPU::readGP1() -> u32 { auto GPU::writeGP1(u32 value) -> void { //thread.fifo.await_empty(); - uint8 command = value >> 24; - uint24 data = value >> 0; + n8 command = value >> 24; + n24 data = value >> 0; //print("* GP1(", hex(command, 2L), ") = ", hex(data, 6L), "\n"); diff --git a/ares/ps1/gpu/gpu.cpp b/ares/ps1/gpu/gpu.cpp index 655d565ecb..ad4d8dabbd 100644 --- a/ares/ps1/gpu/gpu.cpp +++ b/ares/ps1/gpu/gpu.cpp @@ -24,7 +24,7 @@ auto GPU::load(Node::Object parent) -> void { screen = node->append("Screen", 640, 480); screen->setRefresh({&GPU::Blitter::refresh, &blitter}); - screen->colors((1 << 24) + (1 << 15), [&](uint32 color) -> uint64 { + screen->colors((1 << 24) + (1 << 15), [&](n32 color) -> n64 { if(color < (1 << 24)) { u64 a = 65535; u64 r = image::normalize(color >> 0 & 255, 8, 16); @@ -48,7 +48,7 @@ auto GPU::load(Node::Object parent) -> void { overscan->setDynamic(true); vram.allocate(1_MiB); - for(uint y : range(512)) { + for(u32 y : range(512)) { vram2D[y] = (u16*)&vram.data[y * 2048]; } @@ -132,7 +132,7 @@ auto GPU::frame() -> void { } } -auto GPU::step(uint clocks) -> void { +auto GPU::step(u32 clocks) -> void { Thread::clock += clocks; io.hcounter += clocks; io.pcounter -= clocks; diff --git a/ares/ps1/gpu/gpu.hpp b/ares/ps1/gpu/gpu.hpp index a879a249d9..cb275deb51 100644 --- a/ares/ps1/gpu/gpu.hpp +++ b/ares/ps1/gpu/gpu.hpp @@ -20,9 +20,9 @@ struct GPU : Thread, Memory::Interface { } graphics; } debugger; - auto vtotal() const -> uint { return Region::PAL() ? 314 : 263; } - auto vstart() const -> uint { return io.displayRangeY1; } - auto vend() const -> uint { return io.displayRangeY2; } + auto vtotal() const -> u32 { return Region::PAL() ? 314 : 263; } + auto vstart() const -> u32 { return io.displayRangeY1; } + auto vend() const -> u32 { return io.displayRangeY2; } auto vblank() const -> bool { return io.vcounter < vstart() || io.vcounter >= vend(); } auto interlace() const -> bool { return io.verticalResolution && io.interlace; } @@ -32,7 +32,7 @@ struct GPU : Thread, Memory::Interface { auto main() -> void; auto frame() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp @@ -71,7 +71,7 @@ struct GPU : Thread, Memory::Interface { //serialization.cpp auto serialize(serializer&) -> void; - enum class Mode : uint { + enum class Mode : u32 { Normal, Status, CopyToVRAM, @@ -79,9 +79,9 @@ struct GPU : Thread, Memory::Interface { }; struct Display { - uint dotclock; - uint width; - uint height; + u32 dotclock; + u32 width; + u32 height; bool interlace; struct Previous { s32 x; @@ -94,103 +94,103 @@ struct GPU : Thread, Memory::Interface { struct IO { Mode mode = Mode::Normal; - uint1 field; //even or odd scanline - uint16 hcounter; //horizontal counter - uint16 vcounter; //vertical counter - int32 pcounter; //pixel drawing counter + n1 field; //even or odd scanline + n16 hcounter; //horizontal counter + n16 vcounter; //vertical counter + i32 pcounter; //pixel drawing counter //GP0(a0): copy rectangle (CPU to VRAM) //GP0(c0): copy rectangle (VRAM to CPU) struct Copy { - uint16 x; - uint16 y; - uint16 width; - uint16 height; + n16 x; + n16 y; + n16 width; + n16 height; //internal: - uint16 px; - uint16 py; + n16 px; + n16 py; } copy; //GP0(e1): draw mode - uint4 texturePageBaseX; - uint1 texturePageBaseY; - uint2 semiTransparency; - uint2 textureDepth; - uint1 dithering; - uint1 drawToDisplay; - uint1 textureDisable; - uint1 textureFlipX; - uint1 textureFlipY; + n4 texturePageBaseX; + n1 texturePageBaseY; + n2 semiTransparency; + n2 textureDepth; + n1 dithering; + n1 drawToDisplay; + n1 textureDisable; + n1 textureFlipX; + n1 textureFlipY; //GP0(e2): texture window - uint5 textureWindowMaskX; - uint5 textureWindowMaskY; - uint5 textureWindowOffsetX; - uint5 textureWindowOffsetY; + n5 textureWindowMaskX; + n5 textureWindowMaskY; + n5 textureWindowOffsetX; + n5 textureWindowOffsetY; //GP0(e3): set drawing area (top left) - uint10 drawingAreaOriginX1; - uint10 drawingAreaOriginY1; + n10 drawingAreaOriginX1; + n10 drawingAreaOriginY1; //GP0(e4): set drawing area (bottom right) - uint10 drawingAreaOriginX2; - uint10 drawingAreaOriginY2; + n10 drawingAreaOriginX2; + n10 drawingAreaOriginY2; //GP0(e5): set drawing offset - int11 drawingAreaOffsetX; - int11 drawingAreaOffsetY; + i11 drawingAreaOffsetX; + i11 drawingAreaOffsetY; //GP0(e6): mask bit - uint1 forceMaskBit; - uint1 checkMaskBit; + n1 forceMaskBit; + n1 checkMaskBit; //GP1(02): acknowledge interrupt - uint1 interrupt; + n1 interrupt; //GP1(03): display disable - uint1 displayDisable; + n1 displayDisable; //GP1(04): DMA direction - uint2 dmaDirection; + n2 dmaDirection; //GP1(05): start of display area - uint10 displayStartX; - uint9 displayStartY; + n10 displayStartX; + n9 displayStartY; //GP1(06): horizontal display range - uint12 displayRangeX1; - uint12 displayRangeX2; + n12 displayRangeX1; + n12 displayRangeX2; //GP1(07): vertical display range - uint12 displayRangeY1; - uint12 displayRangeY2; + n12 displayRangeY1; + n12 displayRangeY2; //GP1(08): display mode - uint3 horizontalResolution; - uint1 verticalResolution; - uint1 videoMode; - uint1 colorDepth; //0 = 15bpp, 1 = 24bpp - uint1 interlace; - uint1 reverseFlag; + n3 horizontalResolution; + n1 verticalResolution; + n1 videoMode; + n1 colorDepth; //0 = 15bpp, 1 = 24bpp + n1 interlace; + n1 reverseFlag; //GP1(10): get GPU information - uint24 status; + n24 status; //internal: - uint6 texturePaletteX; - uint9 texturePaletteY; + n6 texturePaletteX; + n9 texturePaletteY; } io; struct Queue { auto reset() -> void { length = counterX = counterY = 0; } auto empty() const -> bool { return length == 0; } - auto write(uint32 value) -> uint8 { data[length++] = value; return length; } + auto write(n32 value) -> n8 { data[length++] = value; return length; } - uint8 command; - uint8 length; - uint32 data[256]; - uint10 counterX; - uint9 counterY; + n8 command; + n8 length; + n32 data[256]; + n10 counterX; + n9 counterY; }; struct { @@ -214,7 +214,7 @@ struct GPU : Thread, Memory::Interface { } auto to16() const -> u16 { - return {(r >> 3) << 0 | (g >> 3) << 5 | (b >> 3) << 10}; + return (r >> 3) << 0 | (g >> 3) << 5 | (b >> 3) << 10; } u8 r, g, b; @@ -277,7 +277,7 @@ struct GPU : Thread, Memory::Interface { }; //rendering flags - enum : uint { + enum : u32 { None = 0, Raw = 1 << 0, Alpha = 1 << 1, @@ -300,36 +300,36 @@ struct GPU : Thread, Memory::Interface { auto dither(Point p, Color c) const -> Color; auto modulate(Color above, Color below) const -> Color; auto alpha(Color above, Color below) const -> Color; - template auto pixel(Point, Color, Point = {}) -> void; - template auto line() -> void; - template auto triangle() -> void; - template auto quadrilateral() -> void; - template auto rectangle() -> void; - template auto fill() -> void; - template auto cost(u32 pixels) const -> u32; + template auto pixel(Point, Color, Point = {}) -> void; + template auto line() -> void; + template auto triangle() -> void; + template auto quadrilateral() -> void; + template auto rectangle() -> void; + template auto fill() -> void; + template auto cost(u32 pixels) const -> u32; auto execute() -> void; - uint command; - uint flags; + u32 command; + u32 flags; bool dithering; - uint semiTransparency; + u32 semiTransparency; bool checkMaskBit; bool forceMaskBit; - sint drawingAreaOriginX1; - sint drawingAreaOriginY1; - sint drawingAreaOriginX2; - sint drawingAreaOriginY2; - uint drawingAreaOffsetX; - uint drawingAreaOffsetY; - uint textureDepth; - uint texturePageBaseX; - uint texturePageBaseY; - uint texturePaletteX; - uint texturePaletteY; - uint texelMaskX; - uint texelMaskY; - uint texelOffsetX; - uint texelOffsetY; + s32 drawingAreaOriginX1; + s32 drawingAreaOriginY1; + s32 drawingAreaOriginX2; + s32 drawingAreaOriginY2; + u32 drawingAreaOffsetX; + u32 drawingAreaOffsetY; + u32 textureDepth; + u32 texturePageBaseX; + u32 texturePageBaseY; + u32 texturePaletteX; + u32 texturePaletteY; + u32 texelMaskX; + u32 texelMaskY; + u32 texelOffsetX; + u32 texelOffsetY; Vertex v0; Vertex v1; @@ -363,19 +363,19 @@ struct GPU : Thread, Memory::Interface { auto power() -> void; bool blank; - uint depth; - uint width; - uint height; - sint sx; - sint sy; - sint tx; - sint ty; - sint tw; - sint th; + u32 depth; + u32 width; + u32 height; + s32 sx; + s32 sy; + s32 tx; + s32 ty; + s32 tw; + s32 th; } blitter{*this}; u16* vram2D[512]; - u8 ditherTable[4][4][256]; + u8 ditherTable[4][4][256]; bool refreshed; }; diff --git a/ares/ps1/gpu/io.cpp b/ares/ps1/gpu/io.cpp index 9e9bbb696d..677c2ab233 100644 --- a/ares/ps1/gpu/io.cpp +++ b/ares/ps1/gpu/io.cpp @@ -17,7 +17,7 @@ auto GPU::readHalf(u32 address) -> u32 { } auto GPU::readWord(u32 address) -> u32 { - uint32 data; + n32 data; if(address == 0x1f80'1810) data = readGP0(); if(address == 0x1f80'1814) data = readGP1(); return data; diff --git a/ares/ps1/gpu/renderer.cpp b/ares/ps1/gpu/renderer.cpp index cd98091dc4..23bc5beceb 100644 --- a/ares/ps1/gpu/renderer.cpp +++ b/ares/ps1/gpu/renderer.cpp @@ -5,18 +5,18 @@ auto GPU::generateTables() -> void { {-3, +1, -4, +0}, {+3, -1, +2, -2}, }; - for(uint y : range(4)) { - for(uint x : range(4)) { + for(u32 y : range(4)) { + for(u32 x : range(4)) { for(s32 c : range(256)) { ditherTable[y][x][c] = uclamp<8>(c + table[y][x]); } } } - for(uint a : range(2)) { - for(uint r : range(32)) { - for(uint g : range(32)) { - for(uint b : range(32)) { + for(u32 a : range(2)) { + for(u32 r : range(32)) { + for(u32 g : range(32)) { + for(u32 b : range(32)) { Color color; color.r = r << 3 | r >> 2; color.g = g << 3 | g >> 2; @@ -104,9 +104,9 @@ auto GPU::Render::alpha(Color above, Color below) const -> Color { above.b = min(255, below.b + above.b); break; case 2: - above.r = max(0, (int)below.r - above.r); - above.g = max(0, (int)below.g - above.g); - above.b = max(0, (int)below.b - above.b); + above.r = max(0, (s32)below.r - above.r); + above.g = max(0, (s32)below.g - above.g); + above.b = max(0, (s32)below.b - above.b); break; case 3: above.r = min(255, below.r + (above.r >> 2)); @@ -117,7 +117,7 @@ auto GPU::Render::alpha(Color above, Color below) const -> Color { return above; } -template +template auto GPU::Render::pixel(Point point, Color rgb, Point uv) -> void { Color above; bool transparent; @@ -151,7 +151,7 @@ auto GPU::Render::pixel(Point point, Color rgb, Point uv) -> void { gpu.vram2D[point.y][point.x] = above.to16() | forceMaskBit << 15; } -template +template auto GPU::Render::line() -> void { v0.x += drawingAreaOffsetX, v0.y += drawingAreaOffsetY; v1.x += drawingAreaOffsetX, v1.y += drawingAreaOffsetY; @@ -189,9 +189,9 @@ auto GPU::Render::line() -> void { } } -template +template auto GPU::Render::triangle() -> void { - static constexpr uint Dithering = (( + static constexpr u32 Dithering = (( (Flags & Shade) || ((Flags & Texture) && (Flags & Alpha)) ) && !(Flags & Rectangle)) ? Dither : 0; @@ -286,7 +286,7 @@ auto GPU::Render::triangle() -> void { //io.pcounter += cost(pixels); } -template +template auto GPU::Render::quadrilateral() -> void { auto c1 = v1, c2 = v2, c3 = v3; triangle(); @@ -294,7 +294,7 @@ auto GPU::Render::quadrilateral() -> void { triangle(); } -template +template auto GPU::Render::rectangle() -> void { v1 = Vertex(v0).setPoint(v0.x + size.w, v0.y).setTexel(v0.u + size.w, v0.v); v2 = Vertex(v0).setPoint(v0.x, v0.y + size.h).setTexel(v0.u, v0.v + size.h); @@ -302,18 +302,18 @@ auto GPU::Render::rectangle() -> void { quadrilateral(); } -template +template auto GPU::Render::fill() -> void { auto color = v0.to16(); - for(uint y : range(size.h)) { - for(uint x : range(size.w)) { + for(u32 y : range(size.h)) { + for(u32 x : range(size.w)) { gpu.vram2D[y + v0.y & 511][x + v0.x & 1023] = color; } } //io.pcounter += cost(size.width * size.height); } -template +template auto GPU::Render::cost(u32 pixels) const -> u32 { //for now, do not emulate GPU overhead timing ... return 1; diff --git a/ares/ps1/gpu/serialization.cpp b/ares/ps1/gpu/serialization.cpp index 6330e25b40..b4da750d3f 100644 --- a/ares/ps1/gpu/serialization.cpp +++ b/ares/ps1/gpu/serialization.cpp @@ -12,7 +12,7 @@ auto GPU::serialize(serializer& s) -> void { s(display.previous.width); s(display.previous.height); - s((uint&)io.mode); + s((u32&)io.mode); s(io.field); s(io.hcounter); s(io.vcounter); diff --git a/ares/ps1/interrupt/interrupt.cpp b/ares/ps1/interrupt/interrupt.cpp index a458248b82..26f68d887e 100644 --- a/ares/ps1/interrupt/interrupt.cpp +++ b/ares/ps1/interrupt/interrupt.cpp @@ -32,7 +32,7 @@ auto Interrupt::poll() -> void { if(!interruptsWerePending && cpu.exception.interruptsPending()) cpu.delay.interrupt = 2; } -auto Interrupt::level(uint source) -> bool { +auto Interrupt::level(u32 source) -> bool { if(source == 0) return vblank.level(); if(source == 1) return gpu.level(); if(source == 2) return cdrom.level(); @@ -47,7 +47,7 @@ auto Interrupt::level(uint source) -> bool { return 0; } -auto Interrupt::raise(uint source) -> void { +auto Interrupt::raise(u32 source) -> void { if(source == 0 && !vblank.line) { vblank.raise(); poll(); @@ -94,7 +94,7 @@ auto Interrupt::raise(uint source) -> void { } } -auto Interrupt::lower(uint source) -> void { +auto Interrupt::lower(u32 source) -> void { if(source == 0 && vblank.line) return vblank.lower(), poll(); if(source == 1 && gpu.line) return gpu.lower(), poll(); if(source == 2 && cdrom.line) return cdrom.lower(), poll(); @@ -108,12 +108,12 @@ auto Interrupt::lower(uint source) -> void { if(source == 10 && pio.line) return pio.lower(), poll(); } -auto Interrupt::pulse(uint source) -> void { +auto Interrupt::pulse(u32 source) -> void { raise(source); lower(source); } -auto Interrupt::drive(uint source, bool line) -> void { +auto Interrupt::drive(u32 source, bool line) -> void { if(line == 0) lower(source); if(line == 1) raise(source); } diff --git a/ares/ps1/interrupt/interrupt.hpp b/ares/ps1/interrupt/interrupt.hpp index d597a92f95..e479fa0529 100644 --- a/ares/ps1/interrupt/interrupt.hpp +++ b/ares/ps1/interrupt/interrupt.hpp @@ -1,16 +1,16 @@ struct Interrupt : Memory::Interface { Node::Object node; - //irq.cpp + //interrupt.cpp auto load(Node::Object) -> void; auto unload() -> void; auto poll() -> void; - auto level(uint source) -> bool; - auto raise(uint source) -> void; - auto lower(uint source) -> void; - auto pulse(uint source) -> void; - auto drive(uint source, bool line) -> void; + auto level(u32 source) -> bool; + auto raise(u32 source) -> void; + auto lower(u32 source) -> void; + auto pulse(u32 source) -> void; + auto drive(u32 source, bool line) -> void; auto power(bool reset) -> void; //io.cpp @@ -24,7 +24,7 @@ struct Interrupt : Memory::Interface { //serialization.cpp auto serialize(serializer&) -> void; - enum : uint { Vblank, GPU, CDROM, DMA, Timer0, Timer1, Timer2, Peripheral, SIO, SPU, PIO }; + enum : u32 { Vblank, GPU, CDROM, DMA, Timer0, Timer1, Timer2, Peripheral, SIO, SPU, PIO }; struct Source { auto poll() const { return stat & mask; } @@ -33,9 +33,9 @@ struct Interrupt : Memory::Interface { auto lower() { line = 0; } auto acknowledge() { stat = 0; } - uint1 line; - uint1 stat; - uint1 mask; + n1 line; + n1 stat; + n1 mask; }; Source vblank; diff --git a/ares/ps1/interrupt/io.cpp b/ares/ps1/interrupt/io.cpp index db25e7faea..e8ebc16de0 100644 --- a/ares/ps1/interrupt/io.cpp +++ b/ares/ps1/interrupt/io.cpp @@ -7,7 +7,7 @@ auto Interrupt::readHalf(u32 address) -> u32 { } auto Interrupt::readWord(u32 address) -> u32 { - uint32 data; + n32 data; //I_STAT if(address == 0x1f80'1070) { @@ -51,7 +51,7 @@ auto Interrupt::writeHalf(u32 address, u32 data) -> void { } auto Interrupt::writeWord(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; //I_STAT if(address == 0x1f80'1070) { diff --git a/ares/ps1/mdec/decoder.cpp b/ares/ps1/mdec/decoder.cpp index b92b750981..a0360805f2 100644 --- a/ares/ps1/mdec/decoder.cpp +++ b/ares/ps1/mdec/decoder.cpp @@ -22,7 +22,7 @@ auto MDEC::decodeMacroblocks() -> void { //4-bit if(status.outputDepth == 0) { - for(uint index = 0; index < 64; index += 8) { + for(u32 index = 0; index < 64; index += 8) { u32 a = (output[index + 0] >> 4) << 0; u32 b = (output[index + 1] >> 4) << 4; u32 c = (output[index + 2] >> 4) << 8; @@ -37,7 +37,7 @@ auto MDEC::decodeMacroblocks() -> void { //8-bit if(status.outputDepth == 1) { - for(uint index = 0; index < 64; index += 4) { + for(u32 index = 0; index < 64; index += 4) { u32 a = output[index + 0] << 0; u32 b = output[index + 1] << 8; u32 c = output[index + 2] << 16; @@ -48,7 +48,7 @@ auto MDEC::decodeMacroblocks() -> void { //15-bit if(status.outputDepth == 3) { - for(uint index = 0; index < 256; index += 2) { + for(u32 index = 0; index < 256; index += 2) { u32 a = GPU::Color::to16(output[index + 0]) << 0 | status.outputMaskBit << 15; u32 b = GPU::Color::to16(output[index + 1]) << 16 | status.outputMaskBit << 31; fifo.output.write(a | b); @@ -57,9 +57,9 @@ auto MDEC::decodeMacroblocks() -> void { //24-bit if(status.outputDepth == 2) { - uint index = 0; - uint state = 0; - uint rgb = 0; + u32 index = 0; + u32 state = 0; + u32 rgb = 0; while(index < 256) { switch(state) { case 0: @@ -88,17 +88,17 @@ auto MDEC::decodeMacroblocks() -> void { } auto MDEC::decodeBlock(s16 block[64], u8 table[64]) -> bool { - for(uint n : range(64)) block[n] = 0; + for(u32 n : range(64)) block[n] = 0; maybe dct = fifo.input.read(); if(!dct) return false; //skip block padding while(!fifo.input.empty() && *dct == 0xfe00) dct = fifo.input.read(); - s32 current = (int10)*dct; //direct current + s32 current = (i10)*dct; //direct current u16 qfactor = *dct >> 10; //quantization factor s32 value = current * table[0]; - for(uint n = 0; n < 64;) { + for(u32 n = 0; n < 64;) { if(qfactor == 0) value = current << 1; value = sclamp<11>(value); @@ -110,7 +110,7 @@ auto MDEC::decodeBlock(s16 block[64], u8 table[64]) -> bool { maybe rle = fifo.input.read(); if(!rle) return false; - current = (int10)*rle; + current = (i10)*rle; n += (*rle >> 10) + 1; if(n >= 64) break; @@ -123,12 +123,12 @@ auto MDEC::decodeBlock(s16 block[64], u8 table[64]) -> bool { return true; } -template +template auto MDEC::decodeIDCT(s16 source[64], s16 target[64]) -> void { - for(uint x : range(8)) { - for(uint y : range(8)) { + for(u32 x : range(8)) { + for(u32 y : range(8)) { s32 sum = 0; - for(uint z : range(8)) { + for(u32 z : range(8)) { sum += source[y + z * 8] * block.scale[x + z * 8]; } if constexpr(Pass == 0) target[x + y * 8] = sum + 0x8000 >> 16; @@ -138,18 +138,18 @@ auto MDEC::decodeIDCT(s16 source[64], s16 target[64]) -> void { } auto MDEC::convertY(u32 output[64], s16 luma[64]) -> void { - for(uint y : range(8)) { - for(uint x : range(8)) { - s16 Y = (int10)luma[x + y * 8]; + for(u32 y : range(8)) { + for(u32 x : range(8)) { + s16 Y = (i10)luma[x + y * 8]; Y = uclamp<8>(Y + 128); output[x + y * 8] = Y; } } } -auto MDEC::convertYUV(u32 output[256], s16 luma[64], uint bx, uint by) -> void { - for(uint y : range(8)) { - for(uint x : range(8)) { +auto MDEC::convertYUV(u32 output[256], s16 luma[64], u32 bx, u32 by) -> void { + for(u32 y : range(8)) { + for(u32 x : range(8)) { s16 Y = luma[x + y * 8]; s16 Cb = block.cb[(x + bx >> 1) + (y + by >> 1) * 8]; s16 Cr = block.cr[(x + bx >> 1) + (y + by >> 1) * 8]; diff --git a/ares/ps1/mdec/io.cpp b/ares/ps1/mdec/io.cpp index 4cf4d0a5e6..78677b7b9e 100644 --- a/ares/ps1/mdec/io.cpp +++ b/ares/ps1/mdec/io.cpp @@ -17,7 +17,7 @@ auto MDEC::readHalf(u32 address) -> u32 { } auto MDEC::readWord(u32 address) -> u32 { - uint32 data; + n32 data; if(address == 0x1f80'1820) { data = fifo.output.read(data); @@ -52,7 +52,7 @@ auto MDEC::writeHalf(u32 address, u32 data) -> void { } auto MDEC::writeWord(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; if(address == 0x1f80'1820) { if(io.mode == Mode::Idle) { diff --git a/ares/ps1/mdec/mdec.hpp b/ares/ps1/mdec/mdec.hpp index c0cd7c5827..c2202854b9 100644 --- a/ares/ps1/mdec/mdec.hpp +++ b/ares/ps1/mdec/mdec.hpp @@ -12,9 +12,9 @@ struct MDEC : Thread, Memory::Interface { //decoder.cpp auto decodeMacroblocks() -> void; auto decodeBlock(s16 block[64], u8 table[64]) -> bool; - template auto decodeIDCT(s16 source[64], s16 target[64]) -> void; + template auto decodeIDCT(s16 source[64], s16 target[64]) -> void; auto convertY(u32 output[64], s16 luma[64]) -> void; - auto convertYUV(u32 output[256], s16 luma[64], uint bx, uint by) -> void; + auto convertYUV(u32 output[256], s16 luma[64], u32 bx, u32 by) -> void; //io.cpp auto readDMA() -> u32; @@ -36,28 +36,28 @@ struct MDEC : Thread, Memory::Interface { } fifo; struct Status { - uint16 remaining; - uint3 currentBlock; - uint1 outputMaskBit; - uint1 outputSigned; - uint2 outputDepth; - uint1 outputRequest; - uint1 inputRequest; - uint1 commandBusy; - uint1 inputFull; - uint1 outputEmpty; + n16 remaining; + n3 currentBlock; + n1 outputMaskBit; + n1 outputSigned; + n2 outputDepth; + n1 outputRequest; + n1 inputRequest; + n1 commandBusy; + n1 inputFull; + n1 outputEmpty; } status; - enum Mode : uint { Idle, DecodeMacroblock, SetQuantTable, SetScaleTable }; + enum Mode : u32 { Idle, DecodeMacroblock, SetQuantTable, SetScaleTable }; struct IO { - Mode mode; - uint32 offset; + Mode mode; + n32 offset; } io; struct Block { - u8 luma[64]; - u8 chroma[64]; + u8 luma[64]; + u8 chroma[64]; s16 scale[64]; s16 cr[64]; s16 cb[64]; diff --git a/ares/ps1/mdec/serialization.cpp b/ares/ps1/mdec/serialization.cpp index 6eb8d33785..f58cb01e65 100644 --- a/ares/ps1/mdec/serialization.cpp +++ b/ares/ps1/mdec/serialization.cpp @@ -15,7 +15,7 @@ auto MDEC::serialize(serializer& s) -> void { s(status.inputFull); s(status.outputEmpty); - s((uint&)io.mode); + s((u32&)io.mode); s(io.offset); s(block.luma); diff --git a/ares/ps1/memory/bus.hpp b/ares/ps1/memory/bus.hpp index d23f026e75..2f780b583a 100644 --- a/ares/ps1/memory/bus.hpp +++ b/ares/ps1/memory/bus.hpp @@ -22,7 +22,7 @@ inline auto Bus::mmio(u32 address) -> Memory::Interface& { return unmapped; } -template +template inline auto Bus::read(u32 address) -> u32 { address &= 0x1fff'ffff; if(address <= 0x007f'ffff) return cpu.ram.read(address); @@ -30,7 +30,7 @@ inline auto Bus::read(u32 address) -> u32 { return mmio(address).read(address); } -template +template inline auto Bus::write(u32 address, u32 data) -> void { address &= 0x1fff'ffff; if(address <= 0x007f'ffff) { diff --git a/ares/ps1/memory/interface.hpp b/ares/ps1/memory/interface.hpp index cda2c3bfea..367b61f025 100644 --- a/ares/ps1/memory/interface.hpp +++ b/ares/ps1/memory/interface.hpp @@ -1,20 +1,20 @@ struct Interface { virtual ~Interface() = default; - template auto wait() const -> uint { + template auto wait() const -> u32 { if constexpr(Size == Byte) return waitStates.byte; if constexpr(Size == Half) return waitStates.half; if constexpr(Size == Word) return waitStates.word; } - template auto read(u32 address) -> u32 { + template auto read(u32 address) -> u32 { if constexpr(Size == Byte) return readByte(address); if constexpr(Size == Half) return readHalf(address); if constexpr(Size == Word) return readWord(address); unreachable; } - template auto write(u32 address, u32 data) -> void { + template auto write(u32 address, u32 data) -> void { if constexpr(Size == Byte) return writeByte(address, data); if constexpr(Size == Half) return writeHalf(address, data); if constexpr(Size == Word) return writeWord(address, data); @@ -27,7 +27,7 @@ struct Interface { virtual auto writeHalf(u32 address, u32 data) -> void = 0; virtual auto writeWord(u32 address, u32 data) -> void = 0; - auto setWaitStates(uint byte, uint half, uint word) -> void { + auto setWaitStates(u32 byte, u32 half, u32 word) -> void { waitStates.byte = byte; waitStates.half = half; waitStates.word = word; @@ -35,9 +35,9 @@ struct Interface { //additional clock cycles required to access memory struct WaitStates { - uint byte = 0; - uint half = 0; - uint word = 0; + u32 byte = 0; + u32 half = 0; + u32 word = 0; } waitStates; std::mutex mutex; diff --git a/ares/ps1/memory/io.cpp b/ares/ps1/memory/io.cpp index 1213783373..56ea1e94d8 100644 --- a/ares/ps1/memory/io.cpp +++ b/ares/ps1/memory/io.cpp @@ -2,21 +2,21 @@ //$fffe:0130 CACHE_CTRL auto MemoryControl::readByte(u32 address) -> u32 { - uint32 data; + n32 data; if((address & ~3) == 0x1f80'1060) data = readWord(address & ~3) >> 8 * (address & 3); if(address == 0xfffe'0130) data = readWord(address); //must be word-aligned return data; } auto MemoryControl::readHalf(u32 address) -> u32 { - uint32 data; + n32 data; if((address & ~3) == 0x1f80'1060) data = readWord(address & ~3) >> 8 * (address & 3); if(address == 0xfffe'0130) data = readWord(address); //must be word-aligned return data; } auto MemoryControl::readWord(u32 address) -> u32 { - uint32 data; + n32 data; if(address == 0x1f80'1060) { data = ram.value; @@ -58,7 +58,7 @@ auto MemoryControl::writeHalf(u32 address, u32 data) -> void { } auto MemoryControl::writeWord(u32 address, u32 value) -> void { - uint32 data = value; + n32 data = value; if(address == 0x1f80'1060) { ram.value = data; diff --git a/ares/ps1/memory/memory.hpp b/ares/ps1/memory/memory.hpp index 0cadda917f..d566b969cc 100644 --- a/ares/ps1/memory/memory.hpp +++ b/ares/ps1/memory/memory.hpp @@ -9,8 +9,8 @@ namespace Memory { struct Bus { //bus.hpp auto mmio(u32 address) -> Memory::Interface&; - template auto read(u32 address) -> u32; - template auto write(u32 address, u32 data) -> void; + template auto read(u32 address) -> u32; + template auto write(u32 address, u32 data) -> void; }; struct MemoryControl : Memory::Interface { @@ -33,32 +33,32 @@ struct MemoryControl : Memory::Interface { auto serialize(serializer&) -> void; struct RAM { - uint32 value; - uint1 delay; //1 = add one cycle on simultaneous code+data fetches - uint3 window; //size and mirroring/access control + n32 value; + n1 delay; //1 = add one cycle on simultaneous code+data fetches + n3 window; //size and mirroring/access control } ram; struct Cache { - uint1 lock; //not emulated - uint1 invalidate; //not emulated - uint1 tagTest; - uint1 scratchpadEnable; - uint2 dataSize; //not emulated - uint1 dataEnable; - uint2 codeSize; //not emulated - uint1 codeEnable; - uint1 interruptPolarity; //not emulated - uint1 readPriority; //not emulated - uint1 noWaitState; //not emulated - uint1 busGrant; //not emulated - uint1 loadScheduling; //not emulated - uint1 noStreaming; //not emulated - uint14 reserved; //not used + n1 lock; //not emulated + n1 invalidate; //not emulated + n1 tagTest; + n1 scratchpadEnable; + n2 dataSize; //not emulated + n1 dataEnable; + n2 codeSize; //not emulated + n1 codeEnable; + n1 interruptPolarity; //not emulated + n1 readPriority; //not emulated + n1 noWaitState; //not emulated + n1 busGrant; //not emulated + n1 loadScheduling; //not emulated + n1 noStreaming; //not emulated + n14 reserved; //not used } cache; }; struct MemoryExpansion : Memory::Interface { - MemoryExpansion(uint byte, uint half, uint word) { + MemoryExpansion(u32 byte, u32 half, u32 word) { Memory::Interface::setWaitStates(byte, half, word); } diff --git a/ares/ps1/peripheral/digital-gamepad/digital-gamepad.cpp b/ares/ps1/peripheral/digital-gamepad/digital-gamepad.cpp index 2310614c25..ae723a70cb 100644 --- a/ares/ps1/peripheral/digital-gamepad/digital-gamepad.cpp +++ b/ares/ps1/peripheral/digital-gamepad/digital-gamepad.cpp @@ -26,8 +26,8 @@ auto DigitalGamepad::acknowledge() -> bool { } auto DigitalGamepad::bus(u8 data) -> u8 { - uint8 input = data; - uint8 output = 0xff; + n8 input = data; + n8 output = 0xff; switch(state) { diff --git a/ares/ps1/peripheral/digital-gamepad/digital-gamepad.hpp b/ares/ps1/peripheral/digital-gamepad/digital-gamepad.hpp index 3d15d86672..383236bf54 100644 --- a/ares/ps1/peripheral/digital-gamepad/digital-gamepad.hpp +++ b/ares/ps1/peripheral/digital-gamepad/digital-gamepad.hpp @@ -19,7 +19,7 @@ struct DigitalGamepad : PeripheralDevice { auto acknowledge() -> bool override; auto bus(u8 data) -> u8 override; - enum class State : uint { + enum class State : u32 { Idle, IDLower, IDUpper, diff --git a/ares/ps1/peripheral/io.cpp b/ares/ps1/peripheral/io.cpp index 8edfbd348b..b88f41058c 100644 --- a/ares/ps1/peripheral/io.cpp +++ b/ares/ps1/peripheral/io.cpp @@ -39,7 +39,7 @@ auto Peripheral::transmit(u8 data) -> void { } auto Peripheral::readByte(u32 address) -> u32 { - uint8 data; + n8 data; //JOY_RX_DATA if(address == 0x1f80'1040) { @@ -50,7 +50,7 @@ auto Peripheral::readByte(u32 address) -> u32 { } auto Peripheral::readHalf(u32 address) -> u32 { - uint16 data; + n16 data; //JOY_RX_DATA if(address == 0x1f80'1040) { @@ -105,7 +105,7 @@ auto Peripheral::readHalf(u32 address) -> u32 { } auto Peripheral::readWord(u32 address) -> u32 { - uint32 data; + n32 data; //JOY_RX_DATA if(address == 0x1f80'1040) { @@ -130,7 +130,7 @@ auto Peripheral::readWord(u32 address) -> u32 { } auto Peripheral::writeByte(u32 address, u32 value) -> void { - uint8 data = value; + n8 data = value; //JOY_TX_DATA if(address == 0x1f80'1040) { @@ -139,7 +139,7 @@ auto Peripheral::writeByte(u32 address, u32 value) -> void { } auto Peripheral::writeHalf(u32 address, u32 value) -> void { - uint16 data = value; + n16 data = value; //JOY_TX_DATA if(address == 0x1f80'1040) { diff --git a/ares/ps1/peripheral/memory-card/memory-card.cpp b/ares/ps1/peripheral/memory-card/memory-card.cpp index db1bc9b1c2..e9f3f9f778 100644 --- a/ares/ps1/peripheral/memory-card/memory-card.cpp +++ b/ares/ps1/peripheral/memory-card/memory-card.cpp @@ -27,8 +27,8 @@ auto MemoryCard::acknowledge() -> bool { } auto MemoryCard::bus(u8 data) -> u8 { - uint8 input = data; - uint8 output = 0xff; + n8 input = data; + n8 output = 0xff; if(state == State::Idle) { command = Command::None; @@ -69,15 +69,15 @@ auto MemoryCard::bus(u8 data) -> u8 { } auto MemoryCard::identify(u8 data) -> u8 { - uint8 input = data; - uint8 output = 0xff; + n8 input = data; + n8 output = 0xff; command = Command::None; return output; } auto MemoryCard::read(u8 data) -> u8 { - uint8 input = data; - uint8 output = 0xff; + n8 input = data; + n8 output = 0xff; switch(phase++) { case 2: return 0x5a; //ID lower @@ -100,8 +100,8 @@ auto MemoryCard::read(u8 data) -> u8 { } auto MemoryCard::write(u8 data) -> u8 { - uint8 input = data; - uint8 output = 0xff; + n8 input = data; + n8 output = 0xff; switch(phase++) { case 2: return 0x5a; //ID lower diff --git a/ares/ps1/peripheral/memory-card/memory-card.hpp b/ares/ps1/peripheral/memory-card/memory-card.hpp index ab58536075..1356c95bb4 100644 --- a/ares/ps1/peripheral/memory-card/memory-card.hpp +++ b/ares/ps1/peripheral/memory-card/memory-card.hpp @@ -11,13 +11,13 @@ struct MemoryCard : PeripheralDevice { auto read(u8 data) -> u8; auto write(u8 data) -> u8; - enum class State : uint { + enum class State : u32 { Idle, Select, Active, } state = State::Idle; - enum class Command : uint { + enum class Command : u32 { None, Identify, Read, @@ -31,8 +31,8 @@ struct MemoryCard : PeripheralDevice { BitField<8,4> unknown{&value}; } flag; - u8 phase = 0; - u8 checksum = 0; - u8 response = 0; + u8 phase = 0; + u8 checksum = 0; + u8 response = 0; u16 address = 0; }; diff --git a/ares/ps1/peripheral/peripheral.cpp b/ares/ps1/peripheral/peripheral.cpp index 67e3099c21..3267c398a4 100644 --- a/ares/ps1/peripheral/peripheral.cpp +++ b/ares/ps1/peripheral/peripheral.cpp @@ -32,7 +32,7 @@ auto Peripheral::main() -> void { step(8); } -auto Peripheral::step(uint clocks) -> void { +auto Peripheral::step(u32 clocks) -> void { Thread::clock += clocks; } diff --git a/ares/ps1/peripheral/peripheral.hpp b/ares/ps1/peripheral/peripheral.hpp index 67ba75b203..7b3abca26c 100644 --- a/ares/ps1/peripheral/peripheral.hpp +++ b/ares/ps1/peripheral/peripheral.hpp @@ -15,7 +15,7 @@ struct Peripheral : Thread, Memory::Interface { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; //io.cpp @@ -33,48 +33,48 @@ struct Peripheral : Thread, Memory::Interface { struct IO { //JOY_RX_DATA - uint64 receiveData; - uint8 receiveSize; + n64 receiveData; + n8 receiveSize; //JOY_TX_DATA - uint8 transmitData; + n8 transmitData; //JOY_STAT - uint1 transmitStarted; - uint1 transmitFinished; - uint1 parityError; - uint1 interruptRequest; + n1 transmitStarted; + n1 transmitFinished; + n1 parityError; + n1 interruptRequest; //JOY_MODE - uint2 baudrateReloadFactor; - uint2 characterLength; - uint1 parityEnable; - uint1 parityType; - uint2 unknownMode_6_7; - uint1 clockOutputPolarity; - uint7 unknownMode_9_15; + n2 baudrateReloadFactor; + n2 characterLength; + n1 parityEnable; + n1 parityType; + n2 unknownMode_6_7; + n1 clockOutputPolarity; + n7 unknownMode_9_15; //JOY_CTRL - uint1 transmitEnable; - uint1 joyOutput; - uint1 receiveEnable; - uint1 unknownCtrl_3; - uint1 acknowledge; - uint1 unknownCtrl_5; - uint1 reset; - uint1 unknownCtrl_7; - uint2 receiveInterruptMode; - uint1 transmitInterruptEnable; - uint1 receiveInterruptEnable; - uint1 acknowledgeInterruptEnable; - uint1 slotNumber; - uint2 unknownCtrl_14_15; + n1 transmitEnable; + n1 joyOutput; + n1 receiveEnable; + n1 unknownCtrl_3; + n1 acknowledge; + n1 unknownCtrl_5; + n1 reset; + n1 unknownCtrl_7; + n2 receiveInterruptMode; + n1 transmitInterruptEnable; + n1 receiveInterruptEnable; + n1 acknowledgeInterruptEnable; + n1 slotNumber; + n2 unknownCtrl_14_15; //JOY_BAUD - uint16 baudrateReloadValue; + n16 baudrateReloadValue; //internal - int32 counter; + i32 counter; } io; }; diff --git a/ares/ps1/ps1.hpp b/ares/ps1/ps1.hpp index 608c63a28a..4c5a440910 100644 --- a/ares/ps1/ps1.hpp +++ b/ares/ps1/ps1.hpp @@ -6,10 +6,11 @@ #include namespace ares::PlayStation { + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; enum : bool { Read = 0, Write = 1 }; - enum : uint { Byte = 1, Half = 2, Word = 4 }; + enum : u32 { Byte = 1, Half = 2, Word = 4 }; struct Region { inline static auto NTSCJ() -> bool; diff --git a/ares/ps1/spu/adpcm.cpp b/ares/ps1/spu/adpcm.cpp index c32f71c732..21cb1fbdd5 100644 --- a/ares/ps1/spu/adpcm.cpp +++ b/ares/ps1/spu/adpcm.cpp @@ -1,7 +1,7 @@ auto SPU::Voice::readBlock() -> void { - uint19 address = adpcm.currentAddress; + n19 address = adpcm.currentAddress; - uint16 header = self.readRAM(address); + n16 header = self.readRAM(address); block.shift = header.bit(0,3) > 12 ? 9 : header.bit(0,3); block.filter = header.bit(4,6) > 4 ? 4 : header.bit(4,6); block.loopEnd = header.bit( 8); @@ -9,8 +9,8 @@ auto SPU::Voice::readBlock() -> void { block.loopStart = header.bit(10); address += 2; - for(uint word : range(7)) { - uint16 data = self.readRAM(address); + for(u32 word : range(7)) { + n16 data = self.readRAM(address); block.brr[word << 2 | 0] = data >> 0 & 15; block.brr[word << 2 | 1] = data >> 4 & 15; block.brr[word << 2 | 2] = data >> 8 & 15; @@ -29,7 +29,7 @@ auto SPU::Voice::decodeBlock() -> void { adpcm.previousSamples[2] = adpcm.currentSamples[27]; s16 lastSamples[2] = {adpcm.lastSamples[0], adpcm.lastSamples[1]}; - for(uint nibble : range(28)) { + for(u32 nibble : range(28)) { s32 sample = s16(block.brr[nibble] << 12) >> block.shift; sample += lastSamples[0] * positive[block.filter] >> 6; sample += lastSamples[1] * negative[block.filter] >> 6; diff --git a/ares/ps1/spu/capture.cpp b/ares/ps1/spu/capture.cpp index 42788cf874..b0d50de4d9 100644 --- a/ares/ps1/spu/capture.cpp +++ b/ares/ps1/spu/capture.cpp @@ -1,4 +1,4 @@ -auto SPU::captureVolume(uint channel, s16 volume) -> void { +auto SPU::captureVolume(u32 channel, s16 volume) -> void { u16 address = channel * 0x400 + capture.address; writeRAM(address, volume); } diff --git a/ares/ps1/spu/fifo.cpp b/ares/ps1/spu/fifo.cpp index 58098d96ba..cd4d6b229f 100644 --- a/ares/ps1/spu/fifo.cpp +++ b/ares/ps1/spu/fifo.cpp @@ -1,6 +1,6 @@ auto SPU::fifoReadBlock() -> void { if(transfer.type == 2) { - for(uint from : range(8)) { + for(u32 from : range(8)) { u16 data = readRAM(transfer.current); fifo.write(data); transfer.current += 2; @@ -8,30 +8,30 @@ auto SPU::fifoReadBlock() -> void { } if(transfer.type == 3) { - for(uint from : range(4)) { + for(u32 from : range(4)) { u16 data = readRAM(transfer.current); - for(uint to : range(2)) fifo.write(data); + for(u32 to : range(2)) fifo.write(data); transfer.current += 4; } } if(transfer.type == 4) { - for(uint from : range(2)) { + for(u32 from : range(2)) { u16 data = readRAM(transfer.current); - for(uint to : range(4)) fifo.write(data); + for(u32 to : range(4)) fifo.write(data); transfer.current += 8; } } if(transfer.type == 5) { u16 data = readRAM(transfer.current); - for(uint to : range(8)) fifo.write(data); + for(u32 to : range(8)) fifo.write(data); transfer.current += 16; } if(transfer.type <= 1 || transfer.type >= 6) { u16 data = readRAM(transfer.current + 14); - for(uint to : range(8)) fifo.write(data); + for(u32 to : range(8)) fifo.write(data); transfer.current += 16; } } @@ -41,15 +41,15 @@ auto SPU::fifoWriteBlock() -> void { for(auto& half : data) half = fifo.read(0); if(transfer.type == 2) { - for(uint from : range(8)) { + for(u32 from : range(8)) { writeRAM(transfer.current, data[from]); transfer.current += 2; } } if(transfer.type == 3) { - for(uint from : range(4)) { - for(uint to : range(2)) { + for(u32 from : range(4)) { + for(u32 to : range(2)) { writeRAM(transfer.current, data[from * 2]); transfer.current += 2; } @@ -57,8 +57,8 @@ auto SPU::fifoWriteBlock() -> void { } if(transfer.type == 4) { - for(uint from : range(2)) { - for(uint to : range(4)) { + for(u32 from : range(2)) { + for(u32 to : range(4)) { writeRAM(transfer.current, data[from * 4]); transfer.current += 2; } @@ -66,14 +66,14 @@ auto SPU::fifoWriteBlock() -> void { } if(transfer.type == 5) { - for(uint to : range(8)) { + for(u32 to : range(8)) { writeRAM(transfer.current, data[0]); transfer.current += 2; } } if(transfer.type <= 1 || transfer.type >= 6) { - for(uint to : range(8)) { + for(u32 to : range(8)) { writeRAM(transfer.current, data[7]); transfer.current += 2; } diff --git a/ares/ps1/spu/gaussian.cpp b/ares/ps1/spu/gaussian.cpp index aa9da21de8..182ea19fa2 100644 --- a/ares/ps1/spu/gaussian.cpp +++ b/ares/ps1/spu/gaussian.cpp @@ -1,25 +1,25 @@ auto SPU::gaussianConstructTable() -> void { fesetround(FE_TONEAREST); - double table[512]; - for(uint n : range(512)) { - double k = 0.5 + n; - double s = (sin(Math::Pi * k * 2.048 / 1024)); - double t = (cos(Math::Pi * k * 2.000 / 1023) - 1) * 0.50; - double u = (cos(Math::Pi * k * 4.000 / 1023) - 1) * 0.08; - double r = s * (t + u + 1.0) / k; + f64 table[512]; + for(u32 n : range(512)) { + f64 k = 0.5 + n; + f64 s = (sin(Math::Pi * k * 2.048 / 1024)); + f64 t = (cos(Math::Pi * k * 2.000 / 1023) - 1) * 0.50; + f64 u = (cos(Math::Pi * k * 4.000 / 1023) - 1) * 0.08; + f64 r = s * (t + u + 1.0) / k; table[511 - n] = r; } - double sum = 0.0; - for(uint n : range(512)) sum += table[n]; - double scale = 0x7f80 * 128 / sum; - for(uint n : range(512)) table[n] *= scale; - for(uint phase : range(128)) { - double sum = 0.0; + f64 sum = 0.0; + for(u32 n : range(512)) sum += table[n]; + f64 scale = 0x7f80 * 128 / sum; + for(u32 n : range(512)) table[n] *= scale; + for(u32 phase : range(128)) { + f64 sum = 0.0; sum += table[phase + 0]; sum += table[phase + 256]; sum += table[511 - phase]; sum += table[255 - phase]; - double diff = (sum - 0x7f80) / 4; + f64 diff = (sum - 0x7f80) / 4; gaussianTable[phase + 0] = nearbyint(table[phase + 0] - diff); gaussianTable[phase + 256] = nearbyint(table[phase + 256] - diff); gaussianTable[511 - phase] = nearbyint(table[511 - phase] - diff); diff --git a/ares/ps1/spu/io.cpp b/ares/ps1/spu/io.cpp index d4698beefd..1ef218bb9a 100644 --- a/ares/ps1/spu/io.cpp +++ b/ares/ps1/spu/io.cpp @@ -16,7 +16,7 @@ auto SPU::writeRAM(u32 address, u16 data) -> void { auto SPU::readDMA() -> u32 { if(fifo.empty()) fifoReadBlock(); - uint32 data = fifo.read(0) << 0; + n32 data = fifo.read(0) << 0; return data | fifo.read(0) << 16; } @@ -27,12 +27,12 @@ auto SPU::writeDMA(u32 data) -> void { } auto SPU::readByte(u32 address) -> u32 { - uint16 data = readHalf(address & ~1); + n16 data = readHalf(address & ~1); return data >> 8 * (address & 1) & 0xff; } auto SPU::readHalf(u32 address) -> u32 { - uint16 data = 0; + n16 data = 0; u8 v = address >> 4 & 31; @@ -110,42 +110,42 @@ auto SPU::readHalf(u32 address) -> u32 { //KON if(address == 0x1f80'1d88) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].kon; } } //KOFF if(address == 0x1f80'1d8c) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].koff; } } //PMON if(address == 0x1f80'1d90) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].pmon; } } //NON if(address == 0x1f80'1d94) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].non; } } //EON if(address == 0x1f80'1d98) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].eon; } } //ENDX if(address == 0x1f80'1d9c) { - for(uint v : range(24)) { + for(u32 v : range(24)) { data.bit(v) = voice[v].endx; } } @@ -413,7 +413,7 @@ auto SPU::readHalf(u32 address) -> u32 { } auto SPU::readWord(u32 address) -> u32 { - uint32 data = readHalf(address & ~3 | 0) << 0; + n32 data = readHalf(address & ~3 | 0) << 0; return data | readHalf(address & ~3 | 2) << 16; } @@ -423,7 +423,7 @@ auto SPU::writeByte(u32 address, u32 value) -> void { } auto SPU::writeHalf(u32 address, u32 value) -> void { - uint16 data = value; + n16 data = value; u8 v = address >> 4 & 31; @@ -534,42 +534,42 @@ auto SPU::writeHalf(u32 address, u32 value) -> void { //KON if(address == 0x1f80'1d88) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].kon = data.bit(v); } } //KOFF if(address == 0x1f80'1d8c) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].koff = data.bit(v); } } //PMON if(address == 0x1f80'1d90) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].pmon = data.bit(v); } } //NON if(address == 0x1f80'1d94) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].non = data.bit(v); } } //EON if(address == 0x1f80'1d98) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].eon = data.bit(v); } } //ENDX if(address == 0x1f80'1d9c) { - for(uint v : range(24)) { + for(u32 v : range(24)) { voice[v].endx = data.bit(v); } } diff --git a/ares/ps1/spu/reverb.cpp b/ares/ps1/spu/reverb.cpp index 5f2d994999..fa46532bd5 100644 --- a/ares/ps1/spu/reverb.cpp +++ b/ares/ps1/spu/reverb.cpp @@ -68,7 +68,7 @@ auto SPU::Reverb::iiasm(s16 sample) -> s32 { } template -auto SPU::Reverb::r2244(const int16* source) -> s32 { +auto SPU::Reverb::r2244(const i16* source) -> s32 { s32 output = 0; if(phase) { output = source[9]; @@ -79,7 +79,7 @@ auto SPU::Reverb::r2244(const int16* source) -> s32 { return output; } -auto SPU::Reverb::r4422(const int16* source) -> s32 { +auto SPU::Reverb::r4422(const i16* source) -> s32 { s32 output = 0; for(u32 n : range(20)) output += coefficients[n] * source[n * 2]; output += 0x4000 * source[19]; diff --git a/ares/ps1/spu/serialization.cpp b/ares/ps1/spu/serialization.cpp index 38bb1fb3b1..3c4e4447e1 100644 --- a/ares/ps1/spu/serialization.cpp +++ b/ares/ps1/spu/serialization.cpp @@ -128,7 +128,7 @@ auto SPU::serialize(serializer& s) -> void { s(v.release.exponential); s(v.release.rate); - s((uint&)v.adsr.phase); + s((u32&)v.adsr.phase); s(v.adsr.volume); s(v.adsr.lastVolume); s(v.adsr.target); diff --git a/ares/ps1/spu/spu.cpp b/ares/ps1/spu/spu.cpp index 96c2e585b5..aa5f97a691 100644 --- a/ares/ps1/spu/spu.cpp +++ b/ares/ps1/spu/spu.cpp @@ -91,7 +91,7 @@ auto SPU::sample() -> void { stream->frame(lsum / 32768.0, rsum / 32768.0); } -auto SPU::step(uint clocks) -> void { +auto SPU::step(u32 clocks) -> void { Thread::clock += clocks; } diff --git a/ares/ps1/spu/spu.hpp b/ares/ps1/spu/spu.hpp index 3b2881af8b..84b56cae8b 100644 --- a/ares/ps1/spu/spu.hpp +++ b/ares/ps1/spu/spu.hpp @@ -20,7 +20,7 @@ struct SPU : Thread, Memory::Interface { auto main() -> void; auto sample() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power(bool reset) -> void; @@ -41,7 +41,7 @@ struct SPU : Thread, Memory::Interface { auto fifoWriteBlock() -> void; //capture.cpp - auto captureVolume(uint channel, s16 volume) -> void; + auto captureVolume(u32 channel, s16 volume) -> void; //adsr.cpp auto adsrConstructTable() -> void; @@ -53,8 +53,8 @@ struct SPU : Thread, Memory::Interface { auto serialize(serializer&) -> void; struct Master { - uint1 enable; - uint1 unmute; + n1 enable; + n1 unmute; } master; struct Noise { @@ -64,11 +64,11 @@ struct SPU : Thread, Memory::Interface { //noise.cpp auto update() -> void; - uint2 step; - uint4 shift; + n2 step; + n4 shift; //internal: - uint32 level; - uint32 count; + n32 level; + n32 count; } noise{*this}; struct ADSREntry { @@ -78,18 +78,18 @@ struct SPU : Thread, Memory::Interface { } adsrEntries[2][128]; struct Transfer { - uint2 mode; - uint3 type; - uint16 address; - uint19 current; - uint1 unknown_0; - uint12 unknown_4_15; + n2 mode; + n3 type; + n16 address; + n19 current; + n1 unknown_0; + n12 unknown_4_15; } transfer; struct IRQ { - uint1 enable; - uint1 flag; - uint16 address; + n1 enable; + n1 flag; + n16 address; } irq; struct Envelope { @@ -97,10 +97,10 @@ struct SPU : Thread, Memory::Interface { auto reset(u8 rate, bool decreasing, bool exponential) -> void; auto tick(s32 level) -> s16; - int32 counter; - uint7 rate; - uint1 decreasing; - uint1 exponential; + i32 counter; + n7 rate; + n1 decreasing; + n1 exponential; } envelope; struct VolumeSweep : Envelope { @@ -108,27 +108,27 @@ struct SPU : Thread, Memory::Interface { auto reset() -> void; auto tick() -> void; - uint1 active; - uint1 sweep; - uint1 negative; - int15 level; - int16 current; + n1 active; + n1 sweep; + n1 negative; + i15 level; + i16 current; } volume[2]; struct CDAudio { - uint1 enable; - uint1 reverb; - uint16 volume[2]; + n1 enable; + n1 reverb; + n16 volume[2]; } cdaudio; struct External { - uint1 enable; - uint1 reverb; - uint16 volume[2]; + n1 enable; + n1 reverb; + n16 volume[2]; } external; struct Current { - uint16 volume[2]; + n16 volume[2]; } current; struct Reverb { @@ -139,59 +139,59 @@ struct SPU : Thread, Memory::Interface { auto process(s16 linput, s16 rinput) -> std::pair; auto compute() -> void; auto iiasm(s16 sample) -> s32; - template auto r2244(const int16* source) -> s32; - auto r4422(const int16* source) -> s32; + template auto r2244(const i16* source) -> s32; + auto r4422(const i16* source) -> s32; auto address(u32 address) -> u32; auto read(u32 address, s32 offset = 0) -> s16; auto write(u32 address, s16 data) -> void; - uint1 enable; - - uint16 vLOUT; - uint16 vROUT; - uint16 mBASE; - - uint16 FB_SRC_A; - uint16 FB_SRC_B; - int16 IIR_ALPHA; - int16 ACC_COEF_A; - int16 ACC_COEF_B; - int16 ACC_COEF_C; - int16 ACC_COEF_D; - int16 IIR_COEF; - int16 FB_ALPHA; - int16 FB_X; - uint16 IIR_DEST_A0; - uint16 IIR_DEST_A1; - uint16 ACC_SRC_A0; - uint16 ACC_SRC_A1; - uint16 ACC_SRC_B0; - uint16 ACC_SRC_B1; - uint16 IIR_SRC_A0; - uint16 IIR_SRC_A1; - uint16 IIR_DEST_B0; - uint16 IIR_DEST_B1; - uint16 ACC_SRC_C0; - uint16 ACC_SRC_C1; - uint16 ACC_SRC_D0; - uint16 ACC_SRC_D1; - uint16 IIR_SRC_B1; //misordered - uint16 IIR_SRC_B0; //misordered - uint16 MIX_DEST_A0; - uint16 MIX_DEST_A1; - uint16 MIX_DEST_B0; - uint16 MIX_DEST_B1; - int16 IN_COEF_L; - int16 IN_COEF_R; + n1 enable; + + n16 vLOUT; + n16 vROUT; + n16 mBASE; + + n16 FB_SRC_A; + n16 FB_SRC_B; + i16 IIR_ALPHA; + i16 ACC_COEF_A; + i16 ACC_COEF_B; + i16 ACC_COEF_C; + i16 ACC_COEF_D; + i16 IIR_COEF; + i16 FB_ALPHA; + i16 FB_X; + n16 IIR_DEST_A0; + n16 IIR_DEST_A1; + n16 ACC_SRC_A0; + n16 ACC_SRC_A1; + n16 ACC_SRC_B0; + n16 ACC_SRC_B1; + n16 IIR_SRC_A0; + n16 IIR_SRC_A1; + n16 IIR_DEST_B0; + n16 IIR_DEST_B1; + n16 ACC_SRC_C0; + n16 ACC_SRC_C1; + n16 ACC_SRC_D0; + n16 ACC_SRC_D1; + n16 IIR_SRC_B1; //misordered + n16 IIR_SRC_B0; //misordered + n16 MIX_DEST_A0; + n16 MIX_DEST_A1; + n16 MIX_DEST_B0; + n16 MIX_DEST_B1; + i16 IN_COEF_L; + i16 IN_COEF_R; //internal: - int16 lastInput[2]; - int32 lastOutput[2]; - int16 downsampleBuffer[2][128]; - int16 upsampleBuffer[2][64]; - uint6 resamplePosition; - uint18 baseAddress; - uint18 currentAddress; + i16 lastInput[2]; + i32 lastOutput[2]; + i16 downsampleBuffer[2][128]; + i16 upsampleBuffer[2][64]; + n6 resamplePosition; + n18 baseAddress; + n18 currentAddress; static constexpr s16 coefficients[20] = { -1, +2, -10, +35, -103, +266, -616, +1332, -2960, +10246, @@ -201,8 +201,8 @@ struct SPU : Thread, Memory::Interface { struct Voice { SPU& self; - const uint id; - Voice(SPU& self, uint id) : self(self), id(id) {} + const u32 id; + Voice(SPU& self, u32 id) : self(self), id(id) {} //voice.app auto sample(s32 modulation) -> std::pair; @@ -222,76 +222,76 @@ struct SPU : Thread, Memory::Interface { auto gaussianInterpolate() const -> s32; struct ADPCM { - uint19 startAddress; - uint19 repeatAddress; - uint16 sampleRate; + n19 startAddress; + n19 repeatAddress; + n16 sampleRate; //internal: - uint19 currentAddress; - uint1 hasSamples; - uint1 ignoreLoopAddress; - int16 lastSamples[2]; - int16 previousSamples[3]; - int16 currentSamples[28]; + n19 currentAddress; + n1 hasSamples; + n1 ignoreLoopAddress; + i16 lastSamples[2]; + i16 previousSamples[3]; + i16 currentSamples[28]; } adpcm; struct Block { //header - uint4 shift; - uint3 filter; + n4 shift; + n3 filter; //flags - uint1 loopEnd; - uint1 loopRepeat; - uint1 loopStart; + n1 loopEnd; + n1 loopRepeat; + n1 loopStart; //samples - uint4 brr[28]; + n4 brr[28]; } block; struct Attack { - uint7 rate; - uint1 exponential; + n7 rate; + n1 exponential; } attack; struct Decay { - uint4 rate; + n4 rate; } decay; struct Sustain { - uint4 level; - uint1 exponential; - uint1 decrease; - uint7 rate; - uint1 unknown; + n4 level; + n1 exponential; + n1 decrease; + n7 rate; + n1 unknown; } sustain; struct Release { - uint1 exponential; - uint5 rate; + n1 exponential; + n5 rate; } release; struct ADSR { - enum class Phase : uint { Off, Attack, Decay, Sustain, Release }; + enum class Phase : u32 { Off, Attack, Decay, Sustain, Release }; Phase phase = Phase::Off; - int16 volume; + i16 volume; //internal: - int32 lastVolume; - int16 target; + i32 lastVolume; + i16 target; } adsr; struct Current { - uint16 volume[2]; + n16 volume[2]; } current; VolumeSweep volume[2]; Envelope envelope; - uint32 counter; - uint1 pmon; - uint1 non; - uint1 eon; - uint1 kon; - uint1 koff; - uint1 endx; + n32 counter; + n1 pmon; + n1 non; + n1 eon; + n1 kon; + n1 koff; + n1 endx; } voice[24] = { {*this, 0}, {*this, 1}, {*this, 2}, {*this, 3}, {*this, 4}, {*this, 5}, {*this, 6}, {*this, 7}, @@ -302,7 +302,7 @@ struct SPU : Thread, Memory::Interface { }; struct Capture { - uint10 address; + n10 address; } capture; queue fifo; diff --git a/ares/ps1/system/serialization.cpp b/ares/ps1/system/serialization.cpp index 0eb662f06c..8fd0615af7 100644 --- a/ares/ps1/system/serialization.cpp +++ b/ares/ps1/system/serialization.cpp @@ -1,7 +1,7 @@ auto System::serialize(bool synchronize) -> serializer { serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -16,7 +16,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/ps1/system/system.cpp b/ares/ps1/system/system.cpp index cb41f84f9f..6b2145f4e2 100644 --- a/ares/ps1/system/system.cpp +++ b/ares/ps1/system/system.cpp @@ -2,7 +2,16 @@ namespace ares::PlayStation { +auto enumerate() -> vector { + return { + "[Sony] PlayStation (NTSC-J)", + "[Sony] PlayStation (NTSC-U)", + "[Sony] PlayStation (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -26,8 +35,20 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("PlayStation")) { + information.name = "PlayStation"; + } + if(name.find("NTSC-J")) { + information.region = Region::NTSCJ; + } + if(name.find("NTSC-U")) { + information.region = Region::NTSCU; + } + if(name.find("PAL")) { + information.region = Region::PAL; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -37,17 +58,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC-J → NTSC-U → PAL"); - regionNode->setAllowedValues({ - "NTSC-J → NTSC-U → PAL", - "NTSC-U → NTSC-J → PAL", - "PAL → NTSC-J → NTSC-U", - "PAL → NTSC-U → NTSC-J", - "NTSC-J", - "NTSC-U", - "PAL" - }); - fastBoot = node->append("Fast Boot", false); memory.load(node); @@ -85,7 +95,6 @@ auto System::unload() -> void { dma.unload(); timer.unload(); fastBoot.reset(); - regionNode.reset(); node.reset(); } @@ -96,23 +105,6 @@ auto System::save() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC-J") { - information.region = Region::NTSCJ; - } - if(region == "NTSC-U") { - information.region = Region::NTSCU; - } - if(region == "PAL") { - information.region = Region::PAL; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == disc.region()) setRegion(have); - } - bios.allocate(512_KiB); bios.setWaitStates(6, 12, 24); if(auto fp = platform->open(node, "bios.rom", File::Read, File::Required)) { diff --git a/ares/ps1/system/system.hpp b/ares/ps1/system/system.hpp index 9440b1a708..9e320239d0 100644 --- a/ares/ps1/system/system.hpp +++ b/ares/ps1/system/system.hpp @@ -1,11 +1,10 @@ struct System { Node::System node; - Node::Setting::String regionNode; Node::Setting::Boolean fastBoot; - enum class Region : uint { NTSCJ, NTSCU, PAL }; + enum class Region : u32 { NTSCJ, NTSCU, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto region() const -> Region { return information.region; } //system.cpp @@ -22,6 +21,7 @@ struct System { private: struct Information { + string name = "PlayStation"; Region region = Region::NTSCJ; } information; diff --git a/ares/ps1/timer/io.cpp b/ares/ps1/timer/io.cpp index 4c75a789d7..82887420ea 100644 --- a/ares/ps1/timer/io.cpp +++ b/ares/ps1/timer/io.cpp @@ -7,8 +7,8 @@ auto Timer::readHalf(u32 address) -> u32 { } auto Timer::readWord(u32 address) -> u32 { - uint32 data; - uint c = address >> 4 & 3; + n32 data; + u32 c = address >> 4 & 3; if((address & 0xffff'ffcf) == 0x1f80'1100 && c <= 2) { data.bit(0,15) = timers[c].counter; @@ -48,8 +48,8 @@ auto Timer::writeHalf(u32 address, u32 data) -> void { } auto Timer::writeWord(u32 address, u32 value) -> void { - uint32 data = value; - uint c = address >> 4 & 3; + n32 data = value; + u32 c = address >> 4 & 3; if((address & 0xffff'ffcf) == 0x1f80'1100 && c <= 2) { timers[c].reset(); diff --git a/ares/ps1/timer/timer.cpp b/ares/ps1/timer/timer.cpp index ae0a64e9d0..ee731737ed 100644 --- a/ares/ps1/timer/timer.cpp +++ b/ares/ps1/timer/timer.cpp @@ -14,7 +14,7 @@ auto Timer::unload() -> void { node.reset(); } -auto Timer::step(uint clocks) -> void { +auto Timer::step(u32 clocks) -> void { counter.dotclock += clocks; counter.divclock += clocks; @@ -82,7 +82,7 @@ auto Timer::power(bool reset) -> void { } } -auto Timer::Source::step(uint clocks) -> void { +auto Timer::Source::step(u32 clocks) -> void { if(synchronize && paused) return; while(clocks--) { diff --git a/ares/ps1/timer/timer.hpp b/ares/ps1/timer/timer.hpp index 5eed775ce6..6f6e96f3c4 100644 --- a/ares/ps1/timer/timer.hpp +++ b/ares/ps1/timer/timer.hpp @@ -5,7 +5,7 @@ struct Timer : Memory::Interface { auto load(Node::Object) -> void; auto unload() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto hsync(bool line) -> void; auto vsync(bool line) -> void; auto power(bool reset) -> void; @@ -28,33 +28,33 @@ struct Timer : Memory::Interface { struct Source { Timer& self; - const uint id; - Source(Timer& self, uint id) : self(self), id(id) {} + const u32 id; + Source(Timer& self, u32 id) : self(self), id(id) {} //timer.cpp - auto step(uint clocks = 1) -> void; + auto step(u32 clocks = 1) -> void; auto irq() -> void; auto reset() -> void; - uint16 counter; - uint16 target; - uint1 synchronize; - uint2 mode; - uint1 resetMode; - uint1 irqOnTarget; - uint1 irqOnSaturate; - uint1 irqRepeat; - uint1 irqMode; - uint1 clock; - uint1 divider; - uint1 irqLine; //0 = active - uint1 reachedTarget; - uint1 reachedSaturate; - uint3 unknown; + n16 counter; + n16 target; + n1 synchronize; + n2 mode; + n1 resetMode; + n1 irqOnTarget; + n1 irqOnSaturate; + n1 irqRepeat; + n1 irqMode; + n1 clock; + n1 divider; + n1 irqLine; //0 = active + n1 reachedTarget; + n1 reachedSaturate; + n3 unknown; //internal: - uint1 paused; - uint1 irqTriggered; + n1 paused; + n1 irqTriggered; } timers[3] = {{*this, 0}, {*this, 1}, {*this, 2}}; }; diff --git a/ares/sfc/cartridge/slot.cpp b/ares/sfc/cartridge/slot.cpp index 733eb3ab47..71c4d875fc 100644 --- a/ares/sfc/cartridge/slot.cpp +++ b/ares/sfc/cartridge/slot.cpp @@ -14,5 +14,5 @@ auto CartridgeSlot::load(Node::Object parent) -> void { auto CartridgeSlot::unload() -> void { cartridge.disconnect(); - port = {}; + port.reset(); } diff --git a/ares/sfc/controller/controller.cpp b/ares/sfc/controller/controller.cpp index d8042bbe4c..288f3b89d4 100644 --- a/ares/sfc/controller/controller.cpp +++ b/ares/sfc/controller/controller.cpp @@ -18,7 +18,7 @@ auto Controller::iobit() -> bool { return 1; } -auto Controller::iobit(bool data) -> void { +auto Controller::iobit(n1 data) -> void { if(this == controllerPort1.device.data()) bus.write(0x4201, cpu.pio() & ~0x40 | data << 6); if(this == controllerPort2.device.data()) bus.write(0x4201, cpu.pio() & ~0x80 | data << 7); } diff --git a/ares/sfc/controller/controller.hpp b/ares/sfc/controller/controller.hpp index 9aaaff34a9..80d1ee7ca7 100644 --- a/ares/sfc/controller/controller.hpp +++ b/ares/sfc/controller/controller.hpp @@ -17,9 +17,9 @@ struct Controller { virtual ~Controller() = default; auto iobit() -> bool; - auto iobit(bool data) -> void; - virtual auto data() -> uint2 { return 0; } - virtual auto latch(bool data) -> void {} + auto iobit(n1 data) -> void; + virtual auto data() -> n2 { return 0; } + virtual auto latch(n1 data) -> void {} }; #include "port.hpp" diff --git a/ares/sfc/controller/gamepad/gamepad.cpp b/ares/sfc/controller/gamepad/gamepad.cpp index fedc55af6a..26209290d6 100644 --- a/ares/sfc/controller/gamepad/gamepad.cpp +++ b/ares/sfc/controller/gamepad/gamepad.cpp @@ -15,7 +15,7 @@ Gamepad::Gamepad(Node::Port parent) { start = node->append("Start"); } -auto Gamepad::data() -> uint2 { +auto Gamepad::data() -> n2 { if(latched == 1) { platform->input(b); return b->value(); @@ -46,7 +46,7 @@ auto Gamepad::data() -> uint2 { return 1; } -auto Gamepad::latch(bool data) -> void { +auto Gamepad::latch(n1 data) -> void { if(latched == data) return; latched = data; counter = 0; diff --git a/ares/sfc/controller/gamepad/gamepad.hpp b/ares/sfc/controller/gamepad/gamepad.hpp index 74be35823d..bb5620faea 100644 --- a/ares/sfc/controller/gamepad/gamepad.hpp +++ b/ares/sfc/controller/gamepad/gamepad.hpp @@ -14,17 +14,17 @@ struct Gamepad : Controller { Gamepad(Node::Port); - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = 0; - uint counter = 0; + n1 latched; + n8 counter; - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + n1 yHold; + n1 upLatch; + n1 downLatch; + n1 xHold; + n1 leftLatch; + n1 rightLatch; }; diff --git a/ares/sfc/controller/justifier/justifier.cpp b/ares/sfc/controller/justifier/justifier.cpp index 544d000c26..d9910ff4e3 100644 --- a/ares/sfc/controller/justifier/justifier.cpp +++ b/ares/sfc/controller/justifier/justifier.cpp @@ -20,14 +20,14 @@ Justifier::~Justifier() { } auto Justifier::main() -> void { - uint next = cpu.vcounter() * 1364 + cpu.hcounter(); + u32 next = cpu.vcounter() * 1364 + cpu.hcounter(); - int px = active == 0 ? (int)x->value() : -1; - int py = active == 0 ? (int)y->value() : -1; + s32 px = active == 0 ? (s32)x->value() : -1; + s32 py = active == 0 ? (s32)y->value() : -1; bool offscreen = px < 0 || py < 0 || px >= 256 || py >= ppu.vdisp(); if(!offscreen) { - uint target = py * 1364 + (px + 24) * 4; + u32 target = py * 1364 + (px + 24) * 4; if(next >= target && previous < target) { //CRT raster detected, strobe iobit to latch counters iobit(0); @@ -38,8 +38,8 @@ auto Justifier::main() -> void { if(next < previous) { platform->input(x); platform->input(y); - int nx = x->value() + cx; - int ny = y->value() + cy; + s32 nx = x->value() + cx; + s32 ny = y->value() + cy; cx = max(-16, min(256 + 16, nx)); cy = max(-16, min(240 + 16, ny)); sprite->setPosition(cx * 2 - 16, cy * 2 -16); @@ -51,7 +51,7 @@ auto Justifier::main() -> void { synchronize(cpu); } -auto Justifier::data() -> uint2 { +auto Justifier::data() -> n2 { if(counter == 0) { platform->input(trigger); platform->input(start); @@ -99,7 +99,7 @@ auto Justifier::data() -> uint2 { return 1; } -auto Justifier::latch(bool data) -> void { +auto Justifier::latch(n1 data) -> void { if(latched != data) { latched = data; counter = 0; diff --git a/ares/sfc/controller/justifier/justifier.hpp b/ares/sfc/controller/justifier/justifier.hpp index 653f905f90..a57e647dae 100644 --- a/ares/sfc/controller/justifier/justifier.hpp +++ b/ares/sfc/controller/justifier/justifier.hpp @@ -9,15 +9,15 @@ struct Justifier : Controller, Thread { ~Justifier(); auto main() -> void; - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - int cx = 256 / 2; - int cy = 240 / 2; + i32 cx = 256 / 2; + i32 cy = 240 / 2; - bool active = 0; //0 = player 1; 1 = player 2 (disconnected) - uint latched = 0; - uint counter = 0; - uint previous = 0; + n1 active; //0 = player 1; 1 = player 2 (disconnected) + n32 latched; + n32 counter; + n32 previous; }; diff --git a/ares/sfc/controller/justifiers/justifiers.cpp b/ares/sfc/controller/justifiers/justifiers.cpp index 79e913b8f7..9f7364ebc8 100644 --- a/ares/sfc/controller/justifiers/justifiers.cpp +++ b/ares/sfc/controller/justifiers/justifiers.cpp @@ -30,14 +30,14 @@ Justifiers::~Justifiers() { } auto Justifiers::main() -> void { - uint next = cpu.vcounter() * 1364 + cpu.hcounter(); + u32 next = cpu.vcounter() * 1364 + cpu.hcounter(); - int px = active == 0 ? x1->value() : x2->value(); - int py = active == 0 ? y1->value() : y2->value(); + s32 px = active == 0 ? x1->value() : x2->value(); + s32 py = active == 0 ? y1->value() : y2->value(); bool offscreen = px < 0 || py < 0 || px >= 256 || py >= ppu.vdisp(); if(!offscreen) { - uint target = py * 1364 + (px + 24) * 4; + u32 target = py * 1364 + (px + 24) * 4; if(next >= target && previous < target) { //CRT raster detected, strobe iobit to latch counters iobit(0); @@ -48,8 +48,8 @@ auto Justifiers::main() -> void { if(next < previous) { platform->input(x1); platform->input(y1); - int nx1 = x1->value() + cx1; - int ny1 = y1->value() + cy1; + s32 nx1 = x1->value() + cx1; + s32 ny1 = y1->value() + cy1; cx1 = max(-16, min(256 + 16, nx1)); cy1 = max(-16, min(240 + 16, ny1)); sprite1->setPosition(cx1 * 2 - 16, cy1 * 2 - 16); @@ -57,8 +57,8 @@ auto Justifiers::main() -> void { platform->input(x2); platform->input(y2); - int nx2 = x2->value() + cx2; - int ny2 = y2->value() + cy2; + s32 nx2 = x2->value() + cx2; + s32 ny2 = y2->value() + cy2; cx2 = max(-16, min(256 + 16, nx2)); cy2 = max(-16, min(240 + 16, ny2)); sprite2->setPosition(cx2 * 2 - 16, cy2 * 2 - 16); @@ -70,7 +70,7 @@ auto Justifiers::main() -> void { synchronize(cpu); } -auto Justifiers::data() -> uint2 { +auto Justifiers::data() -> n2 { if(counter == 0) { platform->input(trigger1); platform->input(start1); @@ -121,7 +121,7 @@ auto Justifiers::data() -> uint2 { return 1; } -auto Justifiers::latch(bool data) -> void { +auto Justifiers::latch(n1 data) -> void { if(latched != data) { latched = data; counter = 0; diff --git a/ares/sfc/controller/justifiers/justifiers.hpp b/ares/sfc/controller/justifiers/justifiers.hpp index 38ceff428d..929a232cf3 100644 --- a/ares/sfc/controller/justifiers/justifiers.hpp +++ b/ares/sfc/controller/justifiers/justifiers.hpp @@ -14,17 +14,17 @@ struct Justifiers : Controller, Thread { ~Justifiers(); auto main() -> void; - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - int cx1 = 256 / 2 - 16; - int cy1 = 240 / 2; - int cx2 = 256 / 2 + 16; - int cy2 = 240 / 2; + i32 cx1 = 256 / 2 - 16; + i32 cy1 = 240 / 2; + i32 cx2 = 256 / 2 + 16; + i32 cy2 = 240 / 2; - bool active = 0; //0 = player 1; 1 = player 2 - bool latched = 0; - uint counter = 0; - uint previous = 0; + n1 active; //0 = player 1; 1 = player 2 + n1 latched; + n32 counter; + n32 previous; }; diff --git a/ares/sfc/controller/mouse/mouse.cpp b/ares/sfc/controller/mouse/mouse.cpp index 789af8f52c..06ab3d9082 100644 --- a/ares/sfc/controller/mouse/mouse.cpp +++ b/ares/sfc/controller/mouse/mouse.cpp @@ -7,7 +7,7 @@ Mouse::Mouse(Node::Port parent) { right = node->append("Right"); } -auto Mouse::data() -> uint2 { +auto Mouse::data() -> n2 { if(latched == 1) { speed = (speed + 1) % 3; return 0; @@ -56,7 +56,7 @@ auto Mouse::data() -> uint2 { return 1; } -auto Mouse::latch(bool data) -> void { +auto Mouse::latch(n1 data) -> void { if(latched == data) return; latched = data; counter = 0; @@ -75,11 +75,11 @@ auto Mouse::latch(bool data) -> void { if(cx < 0) cx = -cx; //abs(position_x) if(cy < 0) cy = -cy; //abs(position_y) - double multiplier = 1.0; + f64 multiplier = 1.0; if(speed == 1) multiplier = 1.5; if(speed == 2) multiplier = 2.0; - cx = (double)cx * multiplier; - cy = (double)cy * multiplier; + cx = (f64)cx * multiplier; + cy = (f64)cy * multiplier; cx = min(127, cx); cy = min(127, cy); diff --git a/ares/sfc/controller/mouse/mouse.hpp b/ares/sfc/controller/mouse/mouse.hpp index ef3ae9e7d6..496a32ea9c 100644 --- a/ares/sfc/controller/mouse/mouse.hpp +++ b/ares/sfc/controller/mouse/mouse.hpp @@ -6,16 +6,16 @@ struct Mouse : Controller { Mouse(Node::Port); - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = 0; - uint counter = 0; + n1 latched; + n32 counter; - uint2 speed; //0 = slow, 1 = normal, 2 = fast - int32 cx; //x-coordinate - int32 cy; //y-coordinate - uint1 dx; //x-direction - uint1 dy; //y-direction + n2 speed; //0 = slow, 1 = normal, 2 = fast + i32 cx; //x-coordinate + i32 cy; //y-coordinate + n1 dx; //x-direction + n1 dy; //y-direction }; diff --git a/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.cpp b/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.cpp index 5b6b1a94e6..13858db605 100644 --- a/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.cpp +++ b/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.cpp @@ -30,7 +30,7 @@ NTTDataKeypad::NTTDataKeypad(Node::Port parent) { end = node->append("End"); } -auto NTTDataKeypad::data() -> uint2 { +auto NTTDataKeypad::data() -> n2 { if(latched == 1) { platform->input(b); return b->value(); @@ -77,7 +77,7 @@ auto NTTDataKeypad::data() -> uint2 { return 1; //unverified (likely correct) } -auto NTTDataKeypad::latch(bool data) -> void { +auto NTTDataKeypad::latch(n1 data) -> void { if(latched == data) return; latched = data; counter = 0; diff --git a/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.hpp b/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.hpp index 5aa99cf75a..3db4659172 100644 --- a/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.hpp +++ b/ares/sfc/controller/ntt-data-keypad/ntt-data-keypad.hpp @@ -29,17 +29,17 @@ struct NTTDataKeypad : Controller { NTTDataKeypad(Node::Port); - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = 0; - uint counter = 0; + n1 latched; + n8 counter; - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + n1 yHold; + n1 upLatch; + n1 downLatch; + n1 xHold; + n1 leftLatch; + n1 rightLatch; }; diff --git a/ares/sfc/controller/port.hpp b/ares/sfc/controller/port.hpp index fbce81d08d..3cd626093e 100644 --- a/ares/sfc/controller/port.hpp +++ b/ares/sfc/controller/port.hpp @@ -8,9 +8,9 @@ struct ControllerPort { auto allocate(string name) -> Node::Peripheral; auto iobit() -> bool { if(device) return device->iobit(); return 0; } - auto iobit(bool data) -> void { if(device) return device->iobit(data); } - auto data() -> uint2 { if(device) return device->data(); return 0; } - auto latch(bool data) -> void { if(device) return device->latch(data); } + auto iobit(n1 data) -> void { if(device) return device->iobit(data); } + auto data() -> n2 { if(device) return device->data(); return 0; } + auto latch(n1 data) -> void { if(device) return device->latch(data); } auto serialize(serializer&) -> void; diff --git a/ares/sfc/controller/super-multitap/super-multitap.cpp b/ares/sfc/controller/super-multitap/super-multitap.cpp index 6bcb738b4f..35ed21c85d 100644 --- a/ares/sfc/controller/super-multitap/super-multitap.cpp +++ b/ares/sfc/controller/super-multitap/super-multitap.cpp @@ -12,7 +12,7 @@ port4{"Controller Port 4"} port4.load(node); } -auto SuperMultitap::data() -> uint2 { +auto SuperMultitap::data() -> n2 { if(latched) return 2; //Super Multitap device detection if(iobit()) { @@ -22,7 +22,7 @@ auto SuperMultitap::data() -> uint2 { } } -auto SuperMultitap::latch(bool data) -> void { +auto SuperMultitap::latch(n1 data) -> void { latched = data; port1.latch(data); port2.latch(data); diff --git a/ares/sfc/controller/super-multitap/super-multitap.hpp b/ares/sfc/controller/super-multitap/super-multitap.hpp index a0262a6a9e..e57cdaec47 100644 --- a/ares/sfc/controller/super-multitap/super-multitap.hpp +++ b/ares/sfc/controller/super-multitap/super-multitap.hpp @@ -6,9 +6,9 @@ struct SuperMultitap : Controller { SuperMultitap(Node::Port); - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = false; + n1 latched; }; diff --git a/ares/sfc/controller/super-scope/super-scope.cpp b/ares/sfc/controller/super-scope/super-scope.cpp index a1e219c71f..c057e50241 100644 --- a/ares/sfc/controller/super-scope/super-scope.cpp +++ b/ares/sfc/controller/super-scope/super-scope.cpp @@ -34,10 +34,10 @@ SuperScope::~SuperScope() { } auto SuperScope::main() -> void { - uint next = cpu.vcounter() * 1364 + cpu.hcounter(); + u32 next = cpu.vcounter() * 1364 + cpu.hcounter(); if(!offscreen) { - uint target = cy * 1364 + (cx + 24) * 4; + u32 target = cy * 1364 + (cx + 24) * 4; if(next >= target && previous < target) { //CRT raster detected, strobe iobit to latch counters iobit(0); @@ -49,8 +49,8 @@ auto SuperScope::main() -> void { //Vcounter wrapped back to zero; update cursor coordinates for start of new frame platform->input(x); platform->input(y); - int nx = x->value() + cx; - int ny = y->value() + cy; + s32 nx = x->value() + cx; + s32 ny = y->value() + cy; cx = max(-16, min(256 + 16, nx)); cy = max(-16, min(240 + 16, ny)); offscreen = (cx < 0 || cy < 0 || cx >= 256 || cy >= ppu.vdisp()); @@ -63,7 +63,7 @@ auto SuperScope::main() -> void { synchronize(cpu); } -auto SuperScope::data() -> uint2 { +auto SuperScope::data() -> n2 { if(counter == 0) { //turbo is a switch; toggle is edge sensitive platform->input(turbo); @@ -121,7 +121,7 @@ auto SuperScope::data() -> uint2 { return 1; } -auto SuperScope::latch(bool data) -> void { +auto SuperScope::latch(n1 data) -> void { if(latched != data) { latched = data; counter = 0; diff --git a/ares/sfc/controller/super-scope/super-scope.hpp b/ares/sfc/controller/super-scope/super-scope.hpp index 8d56c4c16a..5299701f65 100644 --- a/ares/sfc/controller/super-scope/super-scope.hpp +++ b/ares/sfc/controller/super-scope/super-scope.hpp @@ -11,22 +11,22 @@ struct SuperScope : Controller, Thread { ~SuperScope(); auto main() -> void; - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = 0; - uint counter = 0; + n1 latched; + n32 counter; - int cx = 256 / 2; - int cy = 240 / 2; - bool triggerValue = 0; - bool turboEdge = 0; - bool pauseEdge = 0; + i32 cx = 256 / 2; + i32 cy = 240 / 2; + n1 triggerValue; + n1 turboEdge; + n1 pauseEdge; - bool offscreen = 0; - bool turboOld = 0; - bool triggerLock = 0; - bool pauseLock = 0; - uint previous = 0; + n1 offscreen; + n1 turboOld; + n1 triggerLock; + n1 pauseLock; + n32 previous; }; diff --git a/ares/sfc/controller/twin-tap/twin-tap.cpp b/ares/sfc/controller/twin-tap/twin-tap.cpp index 86711a0e2c..375953d926 100644 --- a/ares/sfc/controller/twin-tap/twin-tap.cpp +++ b/ares/sfc/controller/twin-tap/twin-tap.cpp @@ -5,7 +5,7 @@ TwinTap::TwinTap(Node::Port parent) { two = node->append("2"); } -auto TwinTap::data() -> uint2 { +auto TwinTap::data() -> n2 { if(latched == 1) { platform->input(two); return two->value(); //unconfirmed @@ -21,7 +21,7 @@ auto TwinTap::data() -> uint2 { } //unconfirmed -auto TwinTap::latch(bool data) -> void { +auto TwinTap::latch(n1 data) -> void { if(latched == data) return; latched = data; counter = 0; diff --git a/ares/sfc/controller/twin-tap/twin-tap.hpp b/ares/sfc/controller/twin-tap/twin-tap.hpp index 80070616aa..09573f35e5 100644 --- a/ares/sfc/controller/twin-tap/twin-tap.hpp +++ b/ares/sfc/controller/twin-tap/twin-tap.hpp @@ -4,10 +4,10 @@ struct TwinTap : Controller { TwinTap(Node::Port); - auto data() -> uint2; - auto latch(bool data) -> void; + auto data() -> n2; + auto latch(n1 data) -> void; private: - bool latched = 0; - uint counter = 0; + n1 latched; + n8 counter; }; diff --git a/ares/sfc/coprocessor/armdsp/armdsp.cpp b/ares/sfc/coprocessor/armdsp/armdsp.cpp index 119e1e0111..176bb84c87 100644 --- a/ares/sfc/coprocessor/armdsp/armdsp.cpp +++ b/ares/sfc/coprocessor/armdsp/armdsp.cpp @@ -38,7 +38,7 @@ auto ARMDSP::main() -> void { instruction(); } -auto ARMDSP::step(uint clocks) -> void { +auto ARMDSP::step(u32 clocks) -> void { if(bridge.timer && --bridge.timer == 0); Thread::step(clocks); Thread::synchronize(cpu); diff --git a/ares/sfc/coprocessor/armdsp/armdsp.hpp b/ares/sfc/coprocessor/armdsp/armdsp.hpp index a8dd4165e9..f33730cb0b 100644 --- a/ares/sfc/coprocessor/armdsp/armdsp.hpp +++ b/ares/sfc/coprocessor/armdsp/armdsp.hpp @@ -6,7 +6,7 @@ struct ARMDSP : ARM7TDMI, Thread { Node::Object node; - uint Frequency; + n32 Frequency; struct Debugger { //debugger.cpp @@ -24,42 +24,42 @@ struct ARMDSP : ARM7TDMI, Thread { auto boot() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto power() -> void; auto reset() -> void; //soft reset //memory.cpp auto sleep() -> void override; - auto get(uint mode, uint32 address) -> uint32 override; - auto set(uint mode, uint32 address, uint32 word) -> void override; + auto get(u32 mode, n32 address) -> n32 override; + auto set(u32 mode, n32 address, n32 word) -> void override; //io.cpp - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; //serialization.cpp - auto firmware() const -> vector; + auto firmware() const -> vector; auto serialize(serializer&) -> void; - uint8 programROM[128 * 1024]; - uint8 dataROM[32 * 1024]; - uint8 programRAM[16 * 1024]; + n8 programROM[128_KiB]; + n8 dataROM[32_KiB]; + n8 programRAM[16_KiB]; struct Bridge { struct Buffer { - bool ready; - uint8 data; + n1 ready; + n8 data; }; Buffer cputoarm; Buffer armtocpu; - uint32 timer; - uint32 timerlatch; - bool reset; - bool ready; - bool signal; + n32 timer; + n32 timerlatch; + n1 reset; + n1 ready; + n1 signal; - auto status() const -> uint8 { - uint8 data; + auto status() const -> n8 { + n8 data; data.bit(0) = armtocpu.ready; data.bit(2) = signal; data.bit(3) = cputoarm.ready; diff --git a/ares/sfc/coprocessor/armdsp/io.cpp b/ares/sfc/coprocessor/armdsp/io.cpp index 5399266b2f..318ca2a2ad 100644 --- a/ares/sfc/coprocessor/armdsp/io.cpp +++ b/ares/sfc/coprocessor/armdsp/io.cpp @@ -2,10 +2,10 @@ //3800-3807 mirrored throughout //a0 ignored -auto ARMDSP::read(uint24 address, uint8) -> uint8 { +auto ARMDSP::read(n24 address, n8) -> n8 { cpu.synchronize(*this); - uint8 data = 0x00; + n8 data = 0x00; address &= 0xff06; if(address == 0x3800) { @@ -26,7 +26,7 @@ auto ARMDSP::read(uint24 address, uint8) -> uint8 { return data; } -auto ARMDSP::write(uint24 address, uint8 data) -> void { +auto ARMDSP::write(n24 address, n8 data) -> void { cpu.synchronize(*this); address &= 0xff06; diff --git a/ares/sfc/coprocessor/armdsp/memory.cpp b/ares/sfc/coprocessor/armdsp/memory.cpp index e5a9a7211f..8b2b0d5899 100644 --- a/ares/sfc/coprocessor/armdsp/memory.cpp +++ b/ares/sfc/coprocessor/armdsp/memory.cpp @@ -5,10 +5,10 @@ auto ARMDSP::sleep() -> void { step(1); } -auto ARMDSP::get(uint mode, uint32 address) -> uint32 { +auto ARMDSP::get(u32 mode, n32 address) -> n32 { step(1); - static auto memory = [&](const uint8* memory, uint mode, uint32 address) -> uint32 { + static auto memory = [&](const n8* memory, u32 mode, n32 address) -> n32 { if(mode & Word) { memory += address & ~3; return memory[0] << 0 | memory[1] << 8 | memory[2] << 16 | memory[3] << 24; @@ -46,10 +46,10 @@ auto ARMDSP::get(uint mode, uint32 address) -> uint32 { return 0; } -auto ARMDSP::set(uint mode, uint32 address, uint32 word) -> void { +auto ARMDSP::set(u32 mode, n32 address, n32 word) -> void { step(1); - static auto memory = [](uint8* memory, uint mode, uint32 address, uint32 word) { + static auto memory = [](n8* memory, u32 mode, n32 address, n32 word) { if(mode & Word) { memory += address & ~3; *memory++ = word >> 0; diff --git a/ares/sfc/coprocessor/armdsp/serialization.cpp b/ares/sfc/coprocessor/armdsp/serialization.cpp index e95eba0bad..22ef674ad8 100644 --- a/ares/sfc/coprocessor/armdsp/serialization.cpp +++ b/ares/sfc/coprocessor/armdsp/serialization.cpp @@ -1,16 +1,16 @@ -auto ARMDSP::firmware() const -> vector { - vector buffer; +auto ARMDSP::firmware() const -> vector { + vector buffer; if(!cartridge.has.ARMDSP) return buffer; - buffer.reserve(128 * 1024 + 32 * 1024); - for(uint n : range(128 * 1024)) buffer.append(programROM[n]); - for(uint n : range( 32 * 1024)) buffer.append(dataROM[n]); + buffer.reserve(128_KiB + 32_KiB); + for(u32 n : range(128_KiB)) buffer.append(programROM[n]); + for(u32 n : range( 32_KiB)) buffer.append(dataROM[n]); return buffer; } auto ARMDSP::serialize(serializer& s) -> void { ARM7TDMI::serialize(s); Thread::serialize(s); - s(array_span{programRAM, 16 * 1024}); + s(array_span{programRAM, 16_KiB}); s(bridge.cputoarm.ready); s(bridge.cputoarm.data); s(bridge.armtocpu.ready); diff --git a/ares/sfc/coprocessor/competition/competition.cpp b/ares/sfc/coprocessor/competition/competition.cpp index 61f363f154..cb00c96fb1 100644 --- a/ares/sfc/coprocessor/competition/competition.cpp +++ b/ares/sfc/coprocessor/competition/competition.cpp @@ -47,9 +47,9 @@ auto Competition::power() -> void { scoreSecondsRemaining = 0; } -auto Competition::mcuRead(uint24 address, uint8 data) -> uint8 { +auto Competition::mcuRead(n24 address, n8 data) -> n8 { if(board == Board::CampusChallenge92) { - uint id = 0; + u32 id = 0; if(select == 0x09) id = 1; if(select == 0x05) id = 2; if(select == 0x03) id = 3; @@ -62,7 +62,7 @@ auto Competition::mcuRead(uint24 address, uint8 data) -> uint8 { } if(board == Board::PowerFest94) { - uint id = 0; + u32 id = 0; if(select == 0x09) id = 1; if(select == 0x0c) id = 2; if(select == 0x0a) id = 3; @@ -83,17 +83,17 @@ auto Competition::mcuRead(uint24 address, uint8 data) -> uint8 { return data; } -auto Competition::mcuWrite(uint24 address, uint8 data) -> void { +auto Competition::mcuWrite(n24 address, n8 data) -> void { } -auto Competition::read(uint24 address, uint8 data) -> uint8 { +auto Competition::read(n24 address, n8 data) -> n8 { if(address == 0x106000 || address == 0xc00000) { return status; } return data; } -auto Competition::write(uint24 address, uint8 data) -> void { +auto Competition::write(n24 address, n8 data) -> void { if(address == 0x206000 || address == 0xe00000) { select = data; if(timer && data == 0x09) { diff --git a/ares/sfc/coprocessor/competition/competition.hpp b/ares/sfc/coprocessor/competition/competition.hpp index 0be2209754..d9537b7a24 100644 --- a/ares/sfc/coprocessor/competition/competition.hpp +++ b/ares/sfc/coprocessor/competition/competition.hpp @@ -19,11 +19,11 @@ struct Competition : Thread { auto unload() -> void; auto power() -> void; - auto mcuRead(uint24 address, uint8) -> uint8; - auto mcuWrite(uint24 address, uint8) -> void; + auto mcuRead(n24 address, n8) -> n8; + auto mcuWrite(n24 address, n8) -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -31,18 +31,18 @@ struct Competition : Thread { public: ReadableMemory rom[4]; - enum class Board : uint { Unknown, CampusChallenge92, PowerFest94 } board; - uint timer; + enum class Board : u32 { Unknown, CampusChallenge92, PowerFest94 } board; + u32 timer; private: - uint8 status; - uint8 select; + n8 status; + n8 select; - bool timerActive; - bool scoreActive; + n1 timerActive; + n1 scoreActive; - uint timerSecondsRemaining; - uint scoreSecondsRemaining; + u32 timerSecondsRemaining; + u32 scoreSecondsRemaining; }; extern Competition competition; diff --git a/ares/sfc/coprocessor/dip/dip.cpp b/ares/sfc/coprocessor/dip/dip.cpp index 89abdc24be..531421e1ca 100644 --- a/ares/sfc/coprocessor/dip/dip.cpp +++ b/ares/sfc/coprocessor/dip/dip.cpp @@ -7,9 +7,9 @@ DIP dip; auto DIP::power() -> void { } -auto DIP::read(uint24, uint8) -> uint8 { +auto DIP::read(n24, n8) -> n8 { return value; } -auto DIP::write(uint24, uint8) -> void { +auto DIP::write(n24, n8) -> void { } diff --git a/ares/sfc/coprocessor/dip/dip.hpp b/ares/sfc/coprocessor/dip/dip.hpp index f09fa08814..6529e0e9d0 100644 --- a/ares/sfc/coprocessor/dip/dip.hpp +++ b/ares/sfc/coprocessor/dip/dip.hpp @@ -2,13 +2,13 @@ struct DIP { //dip.cpp auto power() -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8 value = 0x00; + n8 value = 0x00; }; extern DIP dip; diff --git a/ares/sfc/coprocessor/epsonrtc/epsonrtc.cpp b/ares/sfc/coprocessor/epsonrtc/epsonrtc.cpp index 8f0181f413..ebdc22e34b 100644 --- a/ares/sfc/coprocessor/epsonrtc/epsonrtc.cpp +++ b/ares/sfc/coprocessor/epsonrtc/epsonrtc.cpp @@ -87,19 +87,19 @@ auto EpsonRTC::power() -> void { holdtick = 0; } -auto EpsonRTC::synchronize(uint64 timestamp) -> void { +auto EpsonRTC::synchronize(n64 timestamp) -> void { time_t systime = timestamp; tm* timeinfo = localtime(&systime); - uint second = min(59, timeinfo->tm_sec); + u32 second = min(59, timeinfo->tm_sec); secondlo = second % 10; secondhi = second / 10; - uint minute = timeinfo->tm_min; + u32 minute = timeinfo->tm_min; minutelo = minute % 10; minutehi = minute / 10; - uint hour = timeinfo->tm_hour; + u32 hour = timeinfo->tm_hour; if(atime) { hourlo = hour % 10; hourhi = hour / 10; @@ -111,15 +111,15 @@ auto EpsonRTC::synchronize(uint64 timestamp) -> void { hourhi = hour / 10; } - uint day = timeinfo->tm_mday; + u32 day = timeinfo->tm_mday; daylo = day % 10; dayhi = day / 10; - uint month = 1 + timeinfo->tm_mon; + u32 month = 1 + timeinfo->tm_mon; monthlo = month % 10; monthhi = month / 10; - uint year = timeinfo->tm_year % 100; + u32 year = timeinfo->tm_year % 100; yearlo = year % 10; yearhi = year / 10; @@ -128,7 +128,7 @@ auto EpsonRTC::synchronize(uint64 timestamp) -> void { resync = true; //alert program that time has changed } -auto EpsonRTC::read(uint24 address, uint8 data) -> uint8 { +auto EpsonRTC::read(n24 address, n8 data) -> n8 { cpu.synchronize(*this); address &= 3; @@ -153,7 +153,7 @@ auto EpsonRTC::read(uint24 address, uint8 data) -> uint8 { return data; } -auto EpsonRTC::write(uint24 address, uint8 data) -> void { +auto EpsonRTC::write(n24 address, n8 data) -> void { cpu.synchronize(*this); address &= 3, data &= 15; diff --git a/ares/sfc/coprocessor/epsonrtc/epsonrtc.hpp b/ares/sfc/coprocessor/epsonrtc/epsonrtc.hpp index 8ddf633c57..920d601ac7 100644 --- a/ares/sfc/coprocessor/epsonrtc/epsonrtc.hpp +++ b/ares/sfc/coprocessor/epsonrtc/epsonrtc.hpp @@ -11,73 +11,73 @@ struct EpsonRTC : Thread { auto initialize() -> void; auto unload() -> void; auto power() -> void; - auto synchronize(uint64 timestamp) -> void; + auto synchronize(n64 timestamp) -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; - uint21 clocks; - uint seconds; + n21 clocks; + n32 seconds; - uint2 chipselect; - enum class State : uint { Mode, Seek, Read, Write } state; - uint4 mdr; - uint4 offset; - uint wait; - uint1 ready; - uint1 holdtick; + n2 chipselect; + enum class State : u32 { Mode, Seek, Read, Write } state; + n4 mdr; + n4 offset; + u32 wait; + n1 ready; + n1 holdtick; - uint4 secondlo; - uint3 secondhi; - uint1 batteryfailure; + n4 secondlo; + n3 secondhi; + n1 batteryfailure; - uint4 minutelo; - uint3 minutehi; - uint1 resync; + n4 minutelo; + n3 minutehi; + n1 resync; - uint4 hourlo; - uint2 hourhi; - uint1 meridian; + n4 hourlo; + n2 hourhi; + n1 meridian; - uint4 daylo; - uint2 dayhi; - uint1 dayram; + n4 daylo; + n2 dayhi; + n1 dayram; - uint4 monthlo; - uint1 monthhi; - uint2 monthram; + n4 monthlo; + n1 monthhi; + n2 monthram; - uint4 yearlo; - uint4 yearhi; + n4 yearlo; + n4 yearhi; - uint3 weekday; + n3 weekday; - uint1 hold; - uint1 calendar; - uint1 irqflag; - uint1 roundseconds; + n1 hold; + n1 calendar; + n1 irqflag; + n1 roundseconds; - uint1 irqmask; - uint1 irqduty; - uint2 irqperiod; + n1 irqmask; + n1 irqduty; + n2 irqperiod; - uint1 pause; - uint1 stop; - uint1 atime; //astronomical time (24-hour mode) - uint1 test; + n1 pause; + n1 stop; + n1 atime; //astronomical time (24-hour mode) + n1 test; //memory.cpp auto rtcReset() -> void; - auto rtcRead(uint4 address) -> uint4; - auto rtcWrite(uint4 address, uint4 data) -> void; + auto rtcRead(n4 address) -> n4; + auto rtcWrite(n4 address, n4 data) -> void; - auto load(const uint8* data) -> void; - auto save(uint8* data) -> void; + auto load(const n8* data) -> void; + auto save(n8* data) -> void; //time.cpp - auto irq(uint2 period) -> void; + auto irq(n2 period) -> void; auto duty() -> void; auto roundSeconds() -> void; auto tick() -> void; diff --git a/ares/sfc/coprocessor/epsonrtc/memory.cpp b/ares/sfc/coprocessor/epsonrtc/memory.cpp index 3555592a26..e98ddb58e2 100644 --- a/ares/sfc/coprocessor/epsonrtc/memory.cpp +++ b/ares/sfc/coprocessor/epsonrtc/memory.cpp @@ -7,7 +7,7 @@ auto EpsonRTC::rtcReset() -> void { test = 0; } -auto EpsonRTC::rtcRead(uint4 address) -> uint4 { +auto EpsonRTC::rtcRead(n4 address) -> n4 { switch(address) { default: case 0: return secondlo; case 1: return secondhi | batteryfailure << 3; @@ -23,7 +23,7 @@ auto EpsonRTC::rtcRead(uint4 address) -> uint4 { case 11: return yearhi; case 12: return weekday | resync << 3; case 13: { - uint1 readflag = irqflag & !irqmask; + n1 readflag = irqflag & !irqmask; irqflag = 0; return hold | calendar << 1 | readflag << 2 | roundseconds << 3; } @@ -32,7 +32,7 @@ auto EpsonRTC::rtcRead(uint4 address) -> uint4 { } } -auto EpsonRTC::rtcWrite(uint4 address, uint4 data) -> void { +auto EpsonRTC::rtcWrite(n4 address, n4 data) -> void { switch(address) { case 0: secondlo = data; @@ -110,7 +110,7 @@ auto EpsonRTC::rtcWrite(uint4 address, uint4 data) -> void { } } -auto EpsonRTC::load(const uint8* data) -> void { +auto EpsonRTC::load(const n8* data) -> void { secondlo = data[0] >> 0; secondhi = data[0] >> 4; batteryfailure = data[0] >> 7; @@ -150,19 +150,19 @@ auto EpsonRTC::load(const uint8* data) -> void { atime = data[7] >> 6; test = data[7] >> 7; - uint64 timestamp = 0; + n64 timestamp = 0; for(auto byte : range(8)) { timestamp |= data[8 + byte] << (byte * 8); } - uint64 diff = (uint64)time(0) - timestamp; + n64 diff = (n64)time(0) - timestamp; while(diff >= 60 * 60 * 24) { tickDay(); diff -= 60 * 60 * 24; } while(diff >= 60 * 60) { tickHour(); diff -= 60 * 60; } while(diff >= 60) { tickMinute(); diff -= 60; } while(diff--) tickSecond(); } -auto EpsonRTC::save(uint8* data) -> void { +auto EpsonRTC::save(n8* data) -> void { data[0] = secondlo << 0 | secondhi << 4 | batteryfailure << 7; data[1] = minutelo << 0 | minutehi << 4 | resync << 7; data[2] = hourlo << 0 | hourhi << 4 | meridian << 6 | resync << 7; @@ -172,7 +172,7 @@ auto EpsonRTC::save(uint8* data) -> void { data[6] = weekday << 0 | resync << 3 | hold << 4 | calendar << 5 | irqflag << 6 | roundseconds << 7; data[7] = irqmask << 0 | irqduty << 1 | irqperiod << 2 | pause << 4 | stop << 5 | atime << 6 | test << 7; - uint64 timestamp = (uint64)time(0); + n64 timestamp = (n64)time(0); for(auto byte : range(8)) { data[8 + byte] = timestamp; timestamp >>= 8; diff --git a/ares/sfc/coprocessor/epsonrtc/serialization.cpp b/ares/sfc/coprocessor/epsonrtc/serialization.cpp index ffbae8fdd5..2525da8a02 100644 --- a/ares/sfc/coprocessor/epsonrtc/serialization.cpp +++ b/ares/sfc/coprocessor/epsonrtc/serialization.cpp @@ -5,7 +5,7 @@ auto EpsonRTC::serialize(serializer& s) -> void { s(seconds); s(chipselect); - s((uint&)state); + s((u32&)state); s(mdr); s(offset); s(wait); diff --git a/ares/sfc/coprocessor/epsonrtc/time.cpp b/ares/sfc/coprocessor/epsonrtc/time.cpp index 08c13a49f4..125d88fb85 100644 --- a/ares/sfc/coprocessor/epsonrtc/time.cpp +++ b/ares/sfc/coprocessor/epsonrtc/time.cpp @@ -1,4 +1,4 @@ -auto EpsonRTC::irq(uint2 period) -> void { +auto EpsonRTC::irq(n2 period) -> void { if(stop || pause) return; if(period == irqperiod) irqflag = 1; @@ -109,12 +109,12 @@ auto EpsonRTC::tickDay() -> void { weekday = (weekday + 1) + (weekday == 6); //January - December = 0x01 - 0x09; 0x10 - 0x12 - static const uint daysinmonth[32] = { + static constexpr u32 daysinmonth[32] = { 30, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, }; - uint days = daysinmonth[monthhi << 4 | monthlo]; + u32 days = daysinmonth[monthhi << 4 | monthlo]; if(days == 28) { //add one day for leap years if((yearhi & 1) == 0 && ((yearlo - 0) & 3) == 0) days++; diff --git a/ares/sfc/coprocessor/hitachidsp/hitachidsp.cpp b/ares/sfc/coprocessor/hitachidsp/hitachidsp.cpp index f906c20d23..1ec9944112 100644 --- a/ares/sfc/coprocessor/hitachidsp/hitachidsp.cpp +++ b/ares/sfc/coprocessor/hitachidsp/hitachidsp.cpp @@ -19,7 +19,7 @@ auto HitachiDSP::unload() -> void { Thread::destroy(); } -auto HitachiDSP::step(uint clocks) -> void { +auto HitachiDSP::step(u32 clocks) -> void { HG51B::step(clocks); Thread::step(clocks); Thread::synchronize(cpu); diff --git a/ares/sfc/coprocessor/hitachidsp/hitachidsp.hpp b/ares/sfc/coprocessor/hitachidsp/hitachidsp.hpp index 22b04fb70f..ad4324697f 100644 --- a/ares/sfc/coprocessor/hitachidsp/hitachidsp.hpp +++ b/ares/sfc/coprocessor/hitachidsp/hitachidsp.hpp @@ -17,44 +17,44 @@ struct HitachiDSP : HG51B, Thread { auto load(Node::Object) -> void; auto unload() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto halt() -> void override; auto power() -> void; - auto isROM(uint24 address) -> bool override; - auto isRAM(uint24 address) -> bool override; + auto isROM(n24 address) -> bool override; + auto isRAM(n24 address) -> bool override; //HG51B read/write - auto read(uint24 address) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto read(n24 address) -> n8 override; + auto write(n24 address, n8 data) -> void override; //CPU ROM read/write - auto addressROM(uint24 address) const -> maybe; - auto readROM(uint24 address, uint8 data = 0) -> uint8; - auto writeROM(uint24 address, uint8 data) -> void; + auto addressROM(n24 address) const -> maybe; + auto readROM(n24 address, n8 data = 0) -> n8; + auto writeROM(n24 address, n8 data) -> void; //CPU RAM read/write - auto addressRAM(uint24 address) const -> maybe; - auto readRAM(uint24 address, uint8 data = 0) -> uint8; - auto writeRAM(uint24 address, uint8 data) -> void; + auto addressRAM(n24 address) const -> maybe; + auto readRAM(n24 address, n8 data = 0) -> n8; + auto writeRAM(n24 address, n8 data) -> void; //HG51B data RAM read/write - auto addressDRAM(uint24 address) const -> maybe; - auto readDRAM(uint24 address, uint8 data = 0) -> uint8; - auto writeDRAM(uint24 address, uint8 data) -> void; + auto addressDRAM(n24 address) const -> maybe; + auto readDRAM(n24 address, n8 data = 0) -> n8; + auto writeDRAM(n24 address, n8 data) -> void; //CPU IO read/write - auto addressIO(uint24 address) const -> maybe; - auto readIO(uint24 address, uint8 data = 0) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto addressIO(n24 address) const -> maybe; + auto readIO(n24 address, n8 data = 0) -> n8; + auto writeIO(n24 address, n8 data) -> void; - auto firmware() const -> vector; + auto firmware() const -> vector; auto serialize(serializer&) -> void; - uint Frequency; - uint Roms; - bool Mapping; + n32 Frequency; + n32 Roms; + n1 Mapping; }; extern HitachiDSP hitachidsp; diff --git a/ares/sfc/coprocessor/hitachidsp/memory.cpp b/ares/sfc/coprocessor/hitachidsp/memory.cpp index 0e8c9e4042..3aea4d1027 100644 --- a/ares/sfc/coprocessor/hitachidsp/memory.cpp +++ b/ares/sfc/coprocessor/hitachidsp/memory.cpp @@ -1,12 +1,12 @@ -auto HitachiDSP::isROM(uint24 address) -> bool { +auto HitachiDSP::isROM(n24 address) -> bool { return (bool)addressROM(address); } -auto HitachiDSP::isRAM(uint24 address) -> bool { +auto HitachiDSP::isRAM(n24 address) -> bool { return (bool)addressRAM(address); } -auto HitachiDSP::read(uint24 address) -> uint8 { +auto HitachiDSP::read(n24 address) -> n8 { if(auto linear = addressROM (address)) return readROM (*linear); if(auto linear = addressRAM (address)) return readRAM (*linear); if(auto linear = addressDRAM(address)) return readDRAM(*linear); @@ -14,7 +14,7 @@ auto HitachiDSP::read(uint24 address) -> uint8 { return 0x00; } -auto HitachiDSP::write(uint24 address, uint8 data) -> void { +auto HitachiDSP::write(n24 address, n8 data) -> void { if(auto linear = addressROM (address)) return writeROM (*linear, data); if(auto linear = addressRAM (address)) return writeRAM (*linear, data); if(auto linear = addressDRAM(address)) return writeDRAM(*linear, data); @@ -23,7 +23,7 @@ auto HitachiDSP::write(uint24 address, uint8 data) -> void { // -auto HitachiDSP::addressROM(uint24 address) const -> maybe { +auto HitachiDSP::addressROM(n24 address) const -> maybe { if(Mapping == 0) { //00-3f,80-bf:8000-ffff; c0-ff:0000-ffff if((address & 0x408000) == 0x008000 || (address & 0xc00000) == 0xc00000) { @@ -39,7 +39,7 @@ auto HitachiDSP::addressROM(uint24 address) const -> maybe { return {}; } -auto HitachiDSP::readROM(uint24 address, uint8 data) -> uint8 { +auto HitachiDSP::readROM(n24 address, n8 data) -> n8 { if(hitachidsp.active() || !busy()) { address = bus.mirror(address, rom.size()); //if(Roms == 2 && mmio.r1f52 == 1 && address >= (bit::round(rom.size()) >> 1)) return 0x00; @@ -51,12 +51,12 @@ auto HitachiDSP::readROM(uint24 address, uint8 data) -> uint8 { return data; } -auto HitachiDSP::writeROM(uint24 address, uint8 data) -> void { +auto HitachiDSP::writeROM(n24 address, n8 data) -> void { } // -auto HitachiDSP::addressRAM(uint24 address) const -> maybe { +auto HitachiDSP::addressRAM(n24 address) const -> maybe { if(Mapping == 0) { //70-77:0000-7fff if((address & 0xf88000) == 0x700000) { @@ -73,19 +73,19 @@ auto HitachiDSP::addressRAM(uint24 address) const -> maybe { return {}; } -auto HitachiDSP::readRAM(uint24 address, uint8 data) -> uint8 { +auto HitachiDSP::readRAM(n24 address, n8 data) -> n8 { if(ram.size() == 0) return 0x00; //not open bus return ram.read(bus.mirror(address, ram.size()), data); } -auto HitachiDSP::writeRAM(uint24 address, uint8 data) -> void { +auto HitachiDSP::writeRAM(n24 address, n8 data) -> void { if(ram.size() == 0) return; return ram.write(bus.mirror(address, ram.size()), data); } // -auto HitachiDSP::addressDRAM(uint24 address) const -> maybe { +auto HitachiDSP::addressDRAM(n24 address) const -> maybe { if(Mapping == 0) { //00-3f,80-bf:6000-6bff,7000-7bff if((address & 0x40e000) == 0x006000 && (address & 0x0c00) != 0x0c00) { @@ -100,13 +100,13 @@ auto HitachiDSP::addressDRAM(uint24 address) const -> maybe { return {}; } -auto HitachiDSP::readDRAM(uint24 address, uint8 data) -> uint8 { +auto HitachiDSP::readDRAM(n24 address, n8 data) -> n8 { address &= 0xfff; if(address >= 0xc00) return data; return dataRAM[address]; } -auto HitachiDSP::writeDRAM(uint24 address, uint8 data) -> void { +auto HitachiDSP::writeDRAM(n24 address, n8 data) -> void { address &= 0xfff; if(address >= 0xc00) return; dataRAM[address] = data; @@ -114,7 +114,7 @@ auto HitachiDSP::writeDRAM(uint24 address, uint8 data) -> void { // -auto HitachiDSP::addressIO(uint24 address) const -> maybe { +auto HitachiDSP::addressIO(n24 address) const -> maybe { if(Mapping == 0) { //00-3f,80-bf:6c00-6fff,7c00-7fff if((address & 0x40ec00) == 0x006c00) { @@ -129,7 +129,7 @@ auto HitachiDSP::addressIO(uint24 address) const -> maybe { return {}; } -auto HitachiDSP::readIO(uint24 address, uint8 data) -> uint8 { +auto HitachiDSP::readIO(n24 address, n8 data) -> n8 { address = 0x7c00 | (address & 0x03ff); //IO @@ -180,7 +180,7 @@ auto HitachiDSP::readIO(uint24 address, uint8 data) -> uint8 { return 0x00; } -auto HitachiDSP::writeIO(uint24 address, uint8 data) -> void { +auto HitachiDSP::writeIO(n24 address, n8 data) -> void { address = 0x7c00 | (address & 0x03ff); //IO diff --git a/ares/sfc/coprocessor/hitachidsp/serialization.cpp b/ares/sfc/coprocessor/hitachidsp/serialization.cpp index 56fd8ee418..5bcb1854ca 100644 --- a/ares/sfc/coprocessor/hitachidsp/serialization.cpp +++ b/ares/sfc/coprocessor/hitachidsp/serialization.cpp @@ -1,8 +1,8 @@ -auto HitachiDSP::firmware() const -> vector { - vector buffer; +auto HitachiDSP::firmware() const -> vector { + vector buffer; if(!cartridge.has.HitachiDSP) return buffer; - buffer.reserve(1024 * 3); - for(uint n : range(1024)) { + buffer.reserve(3_KiB); + for(u32 n : range(1024)) { buffer.append(dataROM[n] >> 0); buffer.append(dataROM[n] >> 8); buffer.append(dataROM[n] >> 16); diff --git a/ares/sfc/coprocessor/icd/icd.cpp b/ares/sfc/coprocessor/icd/icd.cpp index d1bc68b446..683ed609e2 100644 --- a/ares/sfc/coprocessor/icd/icd.cpp +++ b/ares/sfc/coprocessor/icd/icd.cpp @@ -6,14 +6,14 @@ ICD icd; #include "io.cpp" #include "serialization.cpp" -auto ICD::clockFrequency() const -> double { - return Frequency ? Frequency : system.cpuFrequency(); +auto ICD::clockFrequency() const -> f64 { + return Frequency ? Frequency : (n32)system.cpuFrequency(); } auto ICD::load(Node::Peripheral parent) -> void { node = parent->append("Super Game Boy"); GameBoy::superGameBoy = this; - GameBoy::system.load(node, "Super Game Boy"); + GameBoy::system.load(node, "[Nintendo] Super Game Boy"); GameBoy::cpu.version->setValue(!Frequency ? "SGB-CPU 01" : "CPU SGB2"); GameBoy::cpu.version->setLatch(); } diff --git a/ares/sfc/coprocessor/icd/icd.hpp b/ares/sfc/coprocessor/icd/icd.hpp index 4d734332d9..6f5ecf9bf9 100644 --- a/ares/sfc/coprocessor/icd/icd.hpp +++ b/ares/sfc/coprocessor/icd/icd.hpp @@ -4,7 +4,7 @@ struct ICD : Platform, GameBoy::SuperGameBoyInterface, Thread { Node::System node; //icd.cpp - auto clockFrequency() const -> double; + auto clockFrequency() const -> f64; auto load(Node::Peripheral) -> void; auto unload() -> void; @@ -15,52 +15,52 @@ struct ICD : Platform, GameBoy::SuperGameBoyInterface, Thread { //interface.cpp auto ppuHreset() -> void override; auto ppuVreset() -> void override; - auto ppuWrite(uint2 color) -> void override; - auto joypWrite(uint1 p14, uint1 p15) -> void override; + auto ppuWrite(n2 color) -> void override; + auto joypWrite(n1 p14, n1 p15) -> void override; //io.cpp - auto readIO(uint24 address, uint8 data) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto readIO(n24 address, n8 data) -> n8; + auto writeIO(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint Revision = 0; - uint Frequency = 0; + n32 Revision = 0; + n32 Frequency = 0; private: struct Packet { - auto operator[](uint4 address) -> uint8& { return data[address]; } - uint8 data[16]; + auto operator[](n4 address) -> n8& { return data[address]; } + n8 data[16]; }; Packet packet[64]; - uint7 packetSize; + n7 packetSize; - uint2 joypID; - uint1 joypLock; - uint1 pulseLock; - uint1 strobeLock; - uint1 packetLock; + n2 joypID; + n1 joypLock; + n1 pulseLock; + n1 strobeLock; + n1 packetLock; Packet joypPacket; - uint4 packetOffset; - uint8 bitData; - uint3 bitOffset; - - uint8 output[4 * 512]; - uint2 readBank; - uint9 readAddress; - uint2 writeBank; - - uint8 r6003; //control port - uint8 r6004; //joypad 1 - uint8 r6005; //joypad 2 - uint8 r6006; //joypad 3 - uint8 r6007; //joypad 4 - uint8 r7000[16]; //JOYP packet data - uint8 mltReq; //number of active joypads - - uint8 hcounter; - uint8 vcounter; + n4 packetOffset; + n8 bitData; + n3 bitOffset; + + n8 output[4 * 512]; + n2 readBank; + n9 readAddress; + n2 writeBank; + + n8 r6003; //control port + n8 r6004; //joypad 1 + n8 r6005; //joypad 2 + n8 r6006; //joypad 3 + n8 r6007; //joypad 4 + n8 r7000[16]; //JOYP packet data + n8 mltReq; //number of active joypads + + n8 hcounter; + n8 vcounter; }; #else @@ -78,13 +78,13 @@ struct ICD : Thread { auto disconnect() -> void {} auto power(bool reset = false) -> void {} - auto readIO(uint24, uint8) -> uint8 { return 0; } - auto writeIO(uint24, uint8) -> void { return; } + auto readIO(n24, n8) -> n8 { return 0; } + auto writeIO(n24, n8) -> void { return; } auto serialize(serializer&) -> void {} - uint Revision = 0; - uint Frequency = 0; + n32 Revision = 0; + n32 Frequency = 0; }; #endif diff --git a/ares/sfc/coprocessor/icd/interface.cpp b/ares/sfc/coprocessor/icd/interface.cpp index ca3abe0c7d..ad7a931102 100644 --- a/ares/sfc/coprocessor/icd/interface.cpp +++ b/ares/sfc/coprocessor/icd/interface.cpp @@ -1,7 +1,7 @@ auto ICD::ppuHreset() -> void { hcounter = 0; vcounter++; - if((uint3)vcounter == 0) writeBank++; + if((n3)vcounter == 0) writeBank++; } auto ICD::ppuVreset() -> void { @@ -9,17 +9,17 @@ auto ICD::ppuVreset() -> void { vcounter = 0; } -auto ICD::ppuWrite(uint2 color) -> void { - auto x = (uint8)hcounter++; - auto y = (uint3)vcounter; +auto ICD::ppuWrite(n2 color) -> void { + auto x = (n8)hcounter++; + auto y = (n3)vcounter; if(x >= 160) return; //unverified behavior - uint11 address = writeBank * 512 + y * 2 + x / 8 * 16; + n11 address = writeBank * 512 + y * 2 + x / 8 * 16; output[address + 0] = output[address + 0] << 1 | color.bit(0); output[address + 1] = output[address + 1] << 1 | color.bit(1); } -auto ICD::joypWrite(uint1 p14, uint1 p15) -> void { +auto ICD::joypWrite(n1 p14, n1 p15) -> void { //joypad handling if(p14 == 1 && p15 == 1) { if(joypLock == 0) { @@ -32,13 +32,13 @@ auto ICD::joypWrite(uint1 p14, uint1 p15) -> void { } } - uint8 joypad; + n8 joypad; if(joypID == 0) joypad = r6004; if(joypID == 1) joypad = r6005; if(joypID == 2) joypad = r6006; if(joypID == 3) joypad = r6007; - uint4 input = 0xf; + n4 input = 0xf; if(p14 == 1 && p15 == 1) input -= joypID; if(p14 == 0) input &= joypad.bit(0,3); //d-pad if(p15 == 0) input &= joypad.bit(4,7); //buttons diff --git a/ares/sfc/coprocessor/icd/io.cpp b/ares/sfc/coprocessor/icd/io.cpp index a1d69f0fb1..fb55dc4231 100644 --- a/ares/sfc/coprocessor/icd/io.cpp +++ b/ares/sfc/coprocessor/icd/io.cpp @@ -1,4 +1,4 @@ -auto ICD::readIO(uint24 address, uint8 data) -> uint8 { +auto ICD::readIO(n24 address, n8 data) -> n8 { address &= 0x40ffff; //LY counter @@ -36,7 +36,7 @@ auto ICD::readIO(uint24 address, uint8 data) -> uint8 { return 0x00; } -auto ICD::writeIO(uint24 address, uint8 data) -> void { +auto ICD::writeIO(n24 address, n8 data) -> void { address &= 0xffff; //VRAM port diff --git a/ares/sfc/coprocessor/icd/serialization.cpp b/ares/sfc/coprocessor/icd/serialization.cpp index 2c17f4946e..075d48a0a9 100644 --- a/ares/sfc/coprocessor/icd/serialization.cpp +++ b/ares/sfc/coprocessor/icd/serialization.cpp @@ -2,7 +2,7 @@ auto ICD::serialize(serializer& s) -> void { Thread::serialize(s); GameBoy::system.serialize(s, scheduler.getSynchronize()); - for(uint n : range(64)) s(packet[n].data); + for(u32 n : range(64)) s(packet[n].data); s(packetSize); s(joypID); diff --git a/ares/sfc/coprocessor/mcc/mcc.cpp b/ares/sfc/coprocessor/mcc/mcc.cpp index d9203104c2..ae8f39c6ec 100644 --- a/ares/sfc/coprocessor/mcc/mcc.cpp +++ b/ares/sfc/coprocessor/mcc/mcc.cpp @@ -28,7 +28,7 @@ auto MCC::commit() -> void { bsmemory.writable(r.externallyWritable); } -auto MCC::read(uint24 address, uint8 data) -> uint8 { +auto MCC::read(n24 address, n8 data) -> n8 { if((address & 0xf0f000) == 0x005000) { //$00-0f:5000-5fff switch(address.bit(16,19)) { case 0: return irq.flag << 7; @@ -53,7 +53,7 @@ auto MCC::read(uint24 address, uint8 data) -> uint8 { return data; } -auto MCC::write(uint24 address, uint8 data) -> void { +auto MCC::write(n24 address, n8 data) -> void { if((address & 0xf0f000) == 0x005000) { //$00-0f:5000-5fff switch(address.bit(16,19)) { case 1: irq.enable = data.bit(7); break; @@ -74,15 +74,15 @@ auto MCC::write(uint24 address, uint8 data) -> void { } } -auto MCC::mcuRead(uint24 address, uint8 data) -> uint8 { +auto MCC::mcuRead(n24 address, n8 data) -> n8 { return mcuAccess(0, address, data); } -auto MCC::mcuWrite(uint24 address, uint8 data) -> void { +auto MCC::mcuWrite(n24 address, n8 data) -> void { return mcuAccess(1, address, data), void(); } -auto MCC::mcuAccess(bool mode, uint24 address, uint8 data) -> uint8 { +auto MCC::mcuAccess(bool mode, n24 address, n8 data) -> n8 { //[[ROM]] if(r.romEnableLo) { @@ -223,27 +223,27 @@ auto MCC::mcuAccess(bool mode, uint24 address, uint8 data) -> uint8 { } //size: 0x100000 -auto MCC::romAccess(bool mode, uint24 address, uint8 data) -> uint8 { +auto MCC::romAccess(bool mode, n24 address, n8 data) -> n8 { address = bus.mirror(address, rom.size()); if(mode == 0) return rom.read(address); return data; } //size: 0x80000 -auto MCC::psramAccess(bool mode, uint24 address, uint8 data) -> uint8 { +auto MCC::psramAccess(bool mode, n24 address, n8 data) -> n8 { address = bus.mirror(address, psram.size()); if(mode == 0) return psram.read(address); return psram.write(address, data), data; } //size: 0x100000 (?) -auto MCC::exAccess(bool mode, uint24 address, uint8 data) -> uint8 { +auto MCC::exAccess(bool mode, n24 address, n8 data) -> n8 { //not physically present on BSC-1A5B9P-01 return data; } //size: 0x100000, 0x200000, 0x400000 -auto MCC::bsAccess(bool mode, uint24 address, uint8 data) -> uint8 { +auto MCC::bsAccess(bool mode, n24 address, n8 data) -> n8 { address = bus.mirror(address, bsmemory.size()); if(mode == 0) return bsmemory.read(address, data); if(!r.internallyWritable) return data; diff --git a/ares/sfc/coprocessor/mcc/mcc.hpp b/ares/sfc/coprocessor/mcc/mcc.hpp index 6b79b28d61..8bdb6f90c5 100644 --- a/ares/sfc/coprocessor/mcc/mcc.hpp +++ b/ares/sfc/coprocessor/mcc/mcc.hpp @@ -10,39 +10,39 @@ struct MCC { auto power() -> void; auto commit() -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; - auto mcuRead(uint24 address, uint8 data) -> uint8; - auto mcuWrite(uint24 address, uint8 data) -> void; + auto mcuRead(n24 address, n8 data) -> n8; + auto mcuWrite(n24 address, n8 data) -> void; - auto mcuAccess(bool mode, uint24 address, uint8 data) -> uint8; - auto romAccess(bool mode, uint24 address, uint8 data) -> uint8; - auto psramAccess(bool mode, uint24 address, uint8 data) -> uint8; - auto exAccess(bool mode, uint24 address, uint8 data) -> uint8; - auto bsAccess(bool mode, uint24 address, uint8 data) -> uint8; + auto mcuAccess(bool mode, n24 address, n8 data) -> n8; + auto romAccess(bool mode, n24 address, n8 data) -> n8; + auto psramAccess(bool mode, n24 address, n8 data) -> n8; + auto exAccess(bool mode, n24 address, n8 data) -> n8; + auto bsAccess(bool mode, n24 address, n8 data) -> n8; //serialization.cpp auto serialize(serializer&) -> void; private: struct IRQ { - uint1 flag; //bit 0 - uint1 enable; //bit 1 + n1 flag; //bit 0 + n1 enable; //bit 1 } irq; struct Registers { - uint1 mapping; //bit 2 (0 = ignore A15; 1 = use A15) - uint1 psramEnableLo; //bit 3 - uint1 psramEnableHi; //bit 4 - uint2 psramMapping; //bits 5-6 - uint1 romEnableLo; //bit 7 - uint1 romEnableHi; //bit 8 - uint1 exEnableLo; //bit 9 - uint1 exEnableHi; //bit 10 - uint1 exMapping; //bit 11 - uint1 internallyWritable; //bit 12 (1 = MCC allows writes to BS Memory Cassette) - uint1 externallyWritable; //bit 13 (1 = BS Memory Cassette allows writes to flash memory) + n1 mapping; //bit 2 (0 = ignore A15; 1 = use A15) + n1 psramEnableLo; //bit 3 + n1 psramEnableHi; //bit 4 + n2 psramMapping; //bits 5-6 + n1 romEnableLo; //bit 7 + n1 romEnableHi; //bit 8 + n1 exEnableLo; //bit 9 + n1 exEnableHi; //bit 10 + n1 exMapping; //bit 11 + n1 internallyWritable; //bit 12 (1 = MCC allows writes to BS Memory Cassette) + n1 externallyWritable; //bit 13 (1 = BS Memory Cassette allows writes to flash memory) } r, w; //bit 14 = commit diff --git a/ares/sfc/coprocessor/msu1/msu1.cpp b/ares/sfc/coprocessor/msu1/msu1.cpp index d974a3f24f..884b0ad005 100644 --- a/ares/sfc/coprocessor/msu1/msu1.cpp +++ b/ares/sfc/coprocessor/msu1/msu1.cpp @@ -17,8 +17,8 @@ auto MSU1::unload() -> void { } auto MSU1::main() -> void { - double left = 0.0; - double right = 0.0; + f64 left = 0.0; + f64 right = 0.0; if(io.audioPlay) { if(audioFile) { @@ -31,8 +31,8 @@ auto MSU1::main() -> void { } } else { io.audioPlayOffset += 4; - left = (double)(int16)audioFile->readl(2) / 32768.0 * (double)io.audioVolume / 255.0; - right = (double)(int16)audioFile->readl(2) / 32768.0 * (double)io.audioVolume / 255.0; + left = (f64)(s16)audioFile->readl(2) / 32768.0 * (f64)io.audioVolume / 255.0; + right = (f64)(s16)audioFile->readl(2) / 32768.0 * (f64)io.audioVolume / 255.0; if(dsp.mute()) left = 0, right = 0; } } else { @@ -84,7 +84,7 @@ auto MSU1::audioOpen() -> void { string name = {"msu1/track-", io.audioTrack, ".pcm"}; if(audioFile = platform->open(cartridge.node, name, File::Read)) { if(audioFile->size() >= 8) { - uint32 header = audioFile->readm(4); + n32 header = audioFile->readm(4); if(header == 0x4d535531) { //"MSU1" io.audioLoopOffset = 8 + audioFile->readl(4) * 4; if(io.audioLoopOffset > audioFile->size()) io.audioLoopOffset = 8; @@ -98,7 +98,7 @@ auto MSU1::audioOpen() -> void { io.audioError = true; } -auto MSU1::readIO(uint24 address, uint8 data) -> uint8 { +auto MSU1::readIO(n24 address, n8 data) -> n8 { cpu.synchronize(*this); switch(0x2000 | address & 7) { @@ -127,7 +127,7 @@ auto MSU1::readIO(uint24 address, uint8 data) -> uint8 { return data; //unreachable } -auto MSU1::writeIO(uint24 address, uint8 data) -> void { +auto MSU1::writeIO(n24 address, n8 data) -> void { cpu.synchronize(*this); switch(0x2000 | address & 7) { diff --git a/ares/sfc/coprocessor/msu1/msu1.hpp b/ares/sfc/coprocessor/msu1/msu1.hpp index 18e24f8363..ac1813a999 100644 --- a/ares/sfc/coprocessor/msu1/msu1.hpp +++ b/ares/sfc/coprocessor/msu1/msu1.hpp @@ -12,13 +12,13 @@ struct MSU1 : Thread { auto dataOpen() -> void; auto audioOpen() -> void; - auto readIO(uint24 address, uint8 data) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto readIO(n24 address, n8 data) -> n8; + auto writeIO(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; private: - enum Flag : uint { + enum Flag : u32 { Revision = 0x02, //max: 0x07 AudioError = 0x08, AudioPlaying = 0x10, @@ -28,23 +28,23 @@ struct MSU1 : Thread { }; struct IO { - uint32 dataSeekOffset; - uint32 dataReadOffset; + n32 dataSeekOffset; + n32 dataReadOffset; - uint32 audioPlayOffset; - uint32 audioLoopOffset; + n32 audioPlayOffset; + n32 audioLoopOffset; - uint16 audioTrack; - uint8 audioVolume; + n16 audioTrack; + n8 audioVolume; - uint32 audioResumeTrack; - uint32 audioResumeOffset; + n32 audioResumeTrack; + n32 audioResumeOffset; - boolean audioError; - boolean audioPlay; - boolean audioRepeat; - boolean audioBusy; - boolean dataBusy; + n1 audioError; + n1 audioPlay; + n1 audioRepeat; + n1 audioBusy; + n1 dataBusy; } io; }; diff --git a/ares/sfc/coprocessor/necdsp/memory.cpp b/ares/sfc/coprocessor/necdsp/memory.cpp index 03cdc67eed..9cfa353433 100644 --- a/ares/sfc/coprocessor/necdsp/memory.cpp +++ b/ares/sfc/coprocessor/necdsp/memory.cpp @@ -1,4 +1,4 @@ -auto NECDSP::read(uint24 address, uint8) -> uint8 { +auto NECDSP::read(n24 address, n8) -> n8 { cpu.synchronize(*this); if(address.bit(0)) { return uPD96050::readSR(); @@ -7,7 +7,7 @@ auto NECDSP::read(uint24 address, uint8) -> uint8 { } } -auto NECDSP::write(uint24 address, uint8 data) -> void { +auto NECDSP::write(n24 address, n8 data) -> void { cpu.synchronize(*this); if(address.bit(0)) { return uPD96050::writeSR(data); @@ -16,12 +16,12 @@ auto NECDSP::write(uint24 address, uint8 data) -> void { } } -auto NECDSP::readRAM(uint24 address, uint8) -> uint8 { +auto NECDSP::readRAM(n24 address, n8) -> n8 { cpu.synchronize(*this); return uPD96050::readDP(address); } -auto NECDSP::writeRAM(uint24 address, uint8 data) -> void { +auto NECDSP::writeRAM(n24 address, n8 data) -> void { cpu.synchronize(*this); return uPD96050::writeDP(address, data); } diff --git a/ares/sfc/coprocessor/necdsp/necdsp.hpp b/ares/sfc/coprocessor/necdsp/necdsp.hpp index 3cd61dc742..7739fcc5dc 100644 --- a/ares/sfc/coprocessor/necdsp/necdsp.hpp +++ b/ares/sfc/coprocessor/necdsp/necdsp.hpp @@ -1,6 +1,6 @@ struct NECDSP : uPD96050, Thread { Node::Object node; - uint Frequency = 0; + n32 Frequency = 0; struct Debugger { //debugger.cpp @@ -20,13 +20,13 @@ struct NECDSP : uPD96050, Thread { auto power() -> void; //memory.cpp - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; - auto readRAM(uint24 address, uint8 data) -> uint8; - auto writeRAM(uint24 address, uint8 data) -> void; + auto readRAM(n24 address, n8 data) -> n8; + auto writeRAM(n24 address, n8 data) -> void; - auto firmware() const -> vector; + auto firmware() const -> vector; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/sfc/coprocessor/necdsp/serialization.cpp b/ares/sfc/coprocessor/necdsp/serialization.cpp index 24a8f58467..92a7a2df6c 100644 --- a/ares/sfc/coprocessor/necdsp/serialization.cpp +++ b/ares/sfc/coprocessor/necdsp/serialization.cpp @@ -1,17 +1,17 @@ -auto NECDSP::firmware() const -> vector { - vector buffer; +auto NECDSP::firmware() const -> vector { + vector buffer; if(!cartridge.has.NECDSP) return buffer; - uint plength = 2048, dlength = 1024; + u32 plength = 2048, dlength = 1024; if(revision == Revision::uPD96050) plength = 16384, dlength = 2048; buffer.reserve(plength * 3 + dlength * 2); - for(uint n : range(plength)) { + for(u32 n : range(plength)) { buffer.append(programROM[n] >> 0); buffer.append(programROM[n] >> 8); buffer.append(programROM[n] >> 16); } - for(uint n : range(dlength)) { + for(u32 n : range(dlength)) { buffer.append(dataROM[n] >> 0); buffer.append(dataROM[n] >> 8); } diff --git a/ares/sfc/coprocessor/obc1/obc1.cpp b/ares/sfc/coprocessor/obc1/obc1.cpp index 1c8868d7b8..c8402ebfd0 100644 --- a/ares/sfc/coprocessor/obc1/obc1.cpp +++ b/ares/sfc/coprocessor/obc1/obc1.cpp @@ -11,7 +11,7 @@ auto OBC1::power() -> void { status.shift = (ramRead(0x1ff6) & 3) << 1; } -auto OBC1::read(uint24 address, uint8) -> uint8 { +auto OBC1::read(n24 address, n8) -> n8 { address &= 0x1fff; switch(address) { @@ -25,7 +25,7 @@ auto OBC1::read(uint24 address, uint8) -> uint8 { return ramRead(address); } -auto OBC1::write(uint24 address, uint8 data) -> void { +auto OBC1::write(n24 address, n8 data) -> void { address &= 0x1fff; switch(address) { @@ -34,7 +34,7 @@ auto OBC1::write(uint24 address, uint8 data) -> void { case 0x1ff2: ramWrite(status.baseptr + (status.address << 2) + 2, data); return; case 0x1ff3: ramWrite(status.baseptr + (status.address << 2) + 3, data); return; case 0x1ff4: { - uint8 temp = ramRead(status.baseptr + (status.address >> 2) + 0x200); + n8 temp = ramRead(status.baseptr + (status.address >> 2) + 0x200); temp = (temp & ~(3 << status.shift)) | ((data & 3) << status.shift); ramWrite(status.baseptr + (status.address >> 2) + 0x200, temp); } return; @@ -55,10 +55,10 @@ auto OBC1::write(uint24 address, uint8 data) -> void { return ramWrite(address, data); } -auto OBC1::ramRead(uint address) -> uint8 { - return ram.read(address & 0x1fff); +auto OBC1::ramRead(n13 address) -> n8 { + return ram.read(address); } -auto OBC1::ramWrite(uint address, uint8 data) -> void { - ram.write(address & 0x1fff, data); +auto OBC1::ramWrite(n13 address, n8 data) -> void { + ram.write(address, data); } diff --git a/ares/sfc/coprocessor/obc1/obc1.hpp b/ares/sfc/coprocessor/obc1/obc1.hpp index b75941d89c..f0f5b0c131 100644 --- a/ares/sfc/coprocessor/obc1/obc1.hpp +++ b/ares/sfc/coprocessor/obc1/obc1.hpp @@ -2,21 +2,21 @@ struct OBC1 { auto unload() -> void; auto power() -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; WritableMemory ram; private: - auto ramRead(uint address) -> uint8; - auto ramWrite(uint address, uint8 data) -> void; + auto ramRead(n13 address) -> n8; + auto ramWrite(n13 address, n8 data) -> void; struct { - uint16 address; - uint16 baseptr; - uint16 shift; + n16 address; + n16 baseptr; + n16 shift; } status; }; diff --git a/ares/sfc/coprocessor/sa1/bwram.cpp b/ares/sfc/coprocessor/sa1/bwram.cpp index cc0c2cb6da..81408981df 100644 --- a/ares/sfc/coprocessor/sa1/bwram.cpp +++ b/ares/sfc/coprocessor/sa1/bwram.cpp @@ -4,13 +4,13 @@ inline auto SA1::BWRAM::conflict() const -> bool { return false; } -inline auto SA1::BWRAM::read(uint24 address, uint8 data) -> uint8 { +inline auto SA1::BWRAM::read(n24 address, n8 data) -> n8 { if(!size()) return data; address = bus.mirror(address, size()); return WritableMemory::read(address, data); } -inline auto SA1::BWRAM::write(uint24 address, uint8 data) -> void { +inline auto SA1::BWRAM::write(n24 address, n8 data) -> void { if(!size()) return; address = bus.mirror(address, size()); return WritableMemory::write(address, data); @@ -19,7 +19,7 @@ inline auto SA1::BWRAM::write(uint24 address, uint8 data) -> void { //note: addresses are translated prior to invoking this function: //00-3f,80-bf:6000-7fff size=0x2000 => 00:0000-1fff //40-4f:0000-ffff => untranslated -auto SA1::BWRAM::readCPU(uint24 address, uint8 data) -> uint8 { +auto SA1::BWRAM::readCPU(n24 address, n8 data) -> n8 { cpu.synchronize(sa1); if(address < 0x2000) { //$00-3f,80-bf:6000-7fff @@ -30,18 +30,18 @@ auto SA1::BWRAM::readCPU(uint24 address, uint8 data) -> uint8 { return read(address, data); } -auto SA1::BWRAM::writeCPU(uint24 address, uint8 data) -> void { +auto SA1::BWRAM::writeCPU(n24 address, n8 data) -> void { cpu.synchronize(sa1); if(address < 0x2000) { //$00-3f,80-bf:6000-7fff address = sa1.io.sbm * 0x2000 + (address & 0x1fff); } - if(!sa1.io.swen && (uint18)address < 0x100 << sa1.io.bwp) return; + if(!sa1.io.swen && (n18)address < 0x100 << sa1.io.bwp) return; return write(address, data); } -auto SA1::BWRAM::readSA1(uint24 address, uint8 data) -> uint8 { +auto SA1::BWRAM::readSA1(n24 address, n8 data) -> n8 { if(sa1.io.sw46 == 0) { //$40-43:0000-ffff x 32 projection address = (sa1.io.cbm & 0x1f) * 0x2000 + (address & 0x1fff); @@ -58,7 +58,7 @@ auto SA1::BWRAM::readSA1(uint24 address, uint8 data) -> uint8 { //* CWEN = 00 (writes disabled) //KDL3 proceeds to write to 4001ax and 40032x which must succeed. -auto SA1::BWRAM::writeSA1(uint24 address, uint8 data) -> void { +auto SA1::BWRAM::writeSA1(n24 address, n8 data) -> void { if(sa1.io.sw46 == 0) { //$40-43:0000-ffff x 32 projection address = (sa1.io.cbm & 0x1f) * 0x2000 + (address & 0x1fff); @@ -70,18 +70,18 @@ auto SA1::BWRAM::writeSA1(uint24 address, uint8 data) -> void { } } -auto SA1::BWRAM::readLinear(uint24 address, uint8 data) -> uint8 { +auto SA1::BWRAM::readLinear(n24 address, n8 data) -> n8 { return read(address, data); } -auto SA1::BWRAM::writeLinear(uint24 address, uint8 data) -> void { +auto SA1::BWRAM::writeLinear(n24 address, n8 data) -> void { return write(address, data); } -auto SA1::BWRAM::readBitmap(uint20 address, uint8 data) -> uint8 { +auto SA1::BWRAM::readBitmap(n20 address, n8 data) -> n8 { if(sa1.io.bbf == 0) { //4bpp - uint shift = address & 1; + u32 shift = address & 1; address >>= 1; switch(shift) { case 0: return read(address).bit(0,3); @@ -89,7 +89,7 @@ auto SA1::BWRAM::readBitmap(uint20 address, uint8 data) -> uint8 { } } else { //2bpp - uint shift = address & 3; + u32 shift = address & 3; address >>= 2; switch(shift) { case 0: return read(address).bit(0,1); @@ -101,10 +101,10 @@ auto SA1::BWRAM::readBitmap(uint20 address, uint8 data) -> uint8 { unreachable; } -auto SA1::BWRAM::writeBitmap(uint20 address, uint8 data) -> void { +auto SA1::BWRAM::writeBitmap(n20 address, n8 data) -> void { if(sa1.io.bbf == 0) { //4bpp - uint shift = address & 1; + u32 shift = address & 1; address >>= 1; switch(shift) { case 0: data = read(address) & 0xf0 | data.bit(0,3) << 0; break; @@ -112,7 +112,7 @@ auto SA1::BWRAM::writeBitmap(uint20 address, uint8 data) -> void { } } else { //2bpp - uint shift = address & 3; + u32 shift = address & 3; address >>= 2; switch(shift) { case 0: data = read(address) & 0xfc | data.bit(0,1) << 0; break; diff --git a/ares/sfc/coprocessor/sa1/dma.cpp b/ares/sfc/coprocessor/sa1/dma.cpp index 9c689fa538..72649760c5 100644 --- a/ares/sfc/coprocessor/sa1/dma.cpp +++ b/ares/sfc/coprocessor/sa1/dma.cpp @@ -1,9 +1,9 @@ //direct data transfer auto SA1::dmaNormal() -> void { while(io.dtc--) { - uint8 data = r.mdr; - uint24 source = io.dsa++; - uint16 target = io.dda++; + n8 data = r.mdr; + n24 source = io.dsa++; + n16 target = io.dda++; if(io.sd == DMA::SourceROM && io.dd == DMA::DestBWRAM) { step(); @@ -61,29 +61,29 @@ auto SA1::dmaCC1() -> void { //works for 2bpp, 4bpp and 8bpp modes //type-1 character conversion -auto SA1::dmaCC1Read(uint address) -> uint8 { +auto SA1::dmaCC1Read(n24 address) -> n8 { //16 bytes/char (2bpp); 32 bytes/char (4bpp); 64 bytes/char (8bpp) - uint charmask = (1 << (6 - io.dmacb)) - 1; + u32 charmask = (1 << (6 - io.dmacb)) - 1; if((address & charmask) == 0) { //buffer next character to I-RAM - uint bpp = 2 << (2 - io.dmacb); - uint bpl = (8 << io.dmasize) >> io.dmacb; - uint bwmask = bwram.size() - 1; - uint tile = ((address - io.dsa) & bwmask) >> (6 - io.dmacb); - uint ty = (tile >> io.dmasize); - uint tx = tile & ((1 << io.dmasize) - 1); - uint bwaddr = io.dsa + ty * 8 * bpl + tx * bpp; - - for(uint y : range(8)) { - uint64 data = 0; - for(uint byte : range(bpp)) { - data |= (uint64)bwram.read((bwaddr + byte) & bwmask) << (byte << 3); + u32 bpp = 2 << (2 - io.dmacb); + u32 bpl = (8 << io.dmasize) >> io.dmacb; + u32 bwmask = bwram.size() - 1; + u32 tile = ((address - io.dsa) & bwmask) >> (6 - io.dmacb); + u32 ty = (tile >> io.dmasize); + u32 tx = tile & ((1 << io.dmasize) - 1); + u32 bwaddr = io.dsa + ty * 8 * bpl + tx * bpp; + + for(u32 y : range(8)) { + u64 data = 0; + for(u32 byte : range(bpp)) { + data |= (u64)bwram.read((bwaddr + byte) & bwmask) << (byte << 3); } bwaddr += bpl; - uint8 out[] = {0, 0, 0, 0, 0, 0, 0, 0}; - for(uint x : range(8)) { + u8 out[] = {0, 0, 0, 0, 0, 0, 0, 0}; + for(u32 x : range(8)) { out[0] |= (data & 1) << 7 - x; data >>= 1; out[1] |= (data & 1) << 7 - x; data >>= 1; if(io.dmacb == 2) continue; @@ -96,8 +96,8 @@ auto SA1::dmaCC1Read(uint address) -> uint8 { out[7] |= (data & 1) << 7 - x; data >>= 1; } - for(uint byte : range(bpp)) { - uint p = io.dda + (y << 1) + ((byte & 6) << 3) + (byte & 1); + for(u32 byte : range(bpp)) { + u32 p = io.dda + (y << 1) + ((byte & 6) << 3) + (byte & 1); iram.write(p & 0x07ff, out[byte]); } } @@ -109,16 +109,16 @@ auto SA1::dmaCC1Read(uint address) -> uint8 { //type-2 character conversion auto SA1::dmaCC2() -> void { //select register file index (0-7 or 8-15) - const uint8* brf = &io.brf[(dma.line & 1) << 3]; - uint bpp = 2 << (2 - io.dmacb); - uint address = io.dda & 0x07ff; + const n8* brf = &io.brf[(dma.line & 1) << 3]; + u32 bpp = 2 << (2 - io.dmacb); + u32 address = io.dda & 0x07ff; address &= ~((1 << (7 - io.dmacb)) - 1); address += (dma.line & 8) * bpp; address += (dma.line & 7) * 2; - for(uint byte : range(bpp)) { - uint8 output = 0; - for(uint bit : range(8)) { + for(u32 byte : range(bpp)) { + u8 output = 0; + for(u32 bit : range(8)) { output |= ((brf[bit] >> byte) & 1) << (7 - bit); } iram.write(address + ((byte & 6) << 3) + (byte & 1), output); diff --git a/ares/sfc/coprocessor/sa1/io.cpp b/ares/sfc/coprocessor/sa1/io.cpp index 7c7ae41129..0a6120b674 100644 --- a/ares/sfc/coprocessor/sa1/io.cpp +++ b/ares/sfc/coprocessor/sa1/io.cpp @@ -1,4 +1,4 @@ -auto SA1::readIOCPU(uint24 address, uint8 data) -> uint8 { +auto SA1::readIOCPU(n24 address, n8 data) -> n8 { cpu.synchronize(sa1); switch(0x2200 | address.bit(0,8)) { @@ -21,7 +21,7 @@ auto SA1::readIOCPU(uint24 address, uint8 data) -> uint8 { return data; } -auto SA1::readIOSA1(uint24 address, uint8 data) -> uint8 { +auto SA1::readIOSA1(n24 address, n8 data) -> n8 { synchronize(cpu); switch(0x2200 | address.bit(0,8)) { @@ -61,7 +61,7 @@ auto SA1::readIOSA1(uint24 address, uint8 data) -> uint8 { //(VDPL) variable-length data read port low case 0x230c: { - uint24 data; + n24 data; data.byte(0) = readVBR(io.va + 0); data.byte(1) = readVBR(io.va + 1); data.byte(2) = readVBR(io.va + 2); @@ -72,7 +72,7 @@ auto SA1::readIOSA1(uint24 address, uint8 data) -> uint8 { //(VDPH) variable-length data read port high case 0x230d: { - uint24 data; + n24 data; data.byte(0) = readVBR(io.va + 0); data.byte(1) = readVBR(io.va + 1); data.byte(2) = readVBR(io.va + 2); @@ -93,7 +93,7 @@ auto SA1::readIOSA1(uint24 address, uint8 data) -> uint8 { return 0xff; //unverified } -auto SA1::writeIOCPU(uint24 address, uint8 data) -> void { +auto SA1::writeIOCPU(n24 address, n8 data) -> void { cpu.synchronize(sa1); switch(0x2200 | address.bit(0,8)) { @@ -216,7 +216,7 @@ auto SA1::writeIOCPU(uint24 address, uint8 data) -> void { } } -auto SA1::writeIOSA1(uint24 address, uint8 data) -> void { +auto SA1::writeIOSA1(n24 address, n8 data) -> void { synchronize(cpu); switch(0x2200 | address.bit(0,8)) { @@ -390,17 +390,17 @@ auto SA1::writeIOSA1(uint24 address, uint8 data) -> void { if(io.acm == 0) { if(io.md == 0) { //signed multiplication - io.mr = uint32((int16)io.ma * (int16)io.mb); + io.mr = n32((i16)io.ma * (i16)io.mb); io.mb = 0; } else { //unsigned division if(io.mb == 0) { io.mr = 0; } else { - int16 dividend = io.ma; - uint16 divisor = io.mb; - uint16 remainder = dividend >= 0 ? uint16(dividend % divisor) : uint16((dividend % divisor + divisor) % divisor); - uint16 quotient = (dividend - remainder) / divisor; + i16 dividend = io.ma; + n16 divisor = io.mb; + n16 remainder = dividend >= 0 ? n16(dividend % divisor) : n16((dividend % divisor + divisor) % divisor); + n16 quotient = (dividend - remainder) / divisor; io.mr = remainder << 16 | quotient; } io.ma = 0; @@ -408,9 +408,9 @@ auto SA1::writeIOSA1(uint24 address, uint8 data) -> void { } } else { //sigma (accumulative multiplication) - io.mr += (int16)io.ma * (int16)io.mb; + io.mr += (i16)io.ma * (i16)io.mb; io.overflow = io.mr >> 40; - io.mr = (uint40)io.mr; + io.mr = (n40)io.mr; io.mb = 0; } return; @@ -438,7 +438,7 @@ auto SA1::writeIOSA1(uint24 address, uint8 data) -> void { } } -auto SA1::writeIOShared(uint24 address, uint8 data) -> void { +auto SA1::writeIOShared(n24 address, n8 data) -> void { switch(0x2200 | address.bit(0,8)) { //(CDMA) character conversion DMA parameters diff --git a/ares/sfc/coprocessor/sa1/iram.cpp b/ares/sfc/coprocessor/sa1/iram.cpp index 397b8e9256..74cee0ffcf 100644 --- a/ares/sfc/coprocessor/sa1/iram.cpp +++ b/ares/sfc/coprocessor/sa1/iram.cpp @@ -3,34 +3,34 @@ inline auto SA1::IRAM::conflict() const -> bool { return false; } -inline auto SA1::IRAM::read(uint24 address, uint8 data) -> uint8 { +inline auto SA1::IRAM::read(n24 address, n8 data) -> n8 { if(!size()) return data; address = bus.mirror(address, size()); return WritableMemory::read(address, data); } -inline auto SA1::IRAM::write(uint24 address, uint8 data) -> void { +inline auto SA1::IRAM::write(n24 address, n8 data) -> void { if(!size()) return; address = bus.mirror(address, size()); return WritableMemory::write(address, data); } -auto SA1::IRAM::readCPU(uint24 address, uint8 data) -> uint8 { +auto SA1::IRAM::readCPU(n24 address, n8 data) -> n8 { cpu.synchronize(sa1); return read(address, data); } -auto SA1::IRAM::writeCPU(uint24 address, uint8 data) -> void { +auto SA1::IRAM::writeCPU(n24 address, n8 data) -> void { cpu.synchronize(sa1); if(!sa1.io.siwp.bit(address.bit(8,10))) return; return write(address, data); } -auto SA1::IRAM::readSA1(uint24 address, uint8 data) -> uint8 { +auto SA1::IRAM::readSA1(n24 address, n8 data) -> n8 { return read(address, data); } -auto SA1::IRAM::writeSA1(uint24 address, uint8 data) -> void { +auto SA1::IRAM::writeSA1(n24 address, n8 data) -> void { if(!sa1.io.ciwp.bit(address.bit(8,10))) return; return write(address, data); } diff --git a/ares/sfc/coprocessor/sa1/memory.cpp b/ares/sfc/coprocessor/sa1/memory.cpp index dc3a8b3ccf..40e63b9d8c 100644 --- a/ares/sfc/coprocessor/sa1/memory.cpp +++ b/ares/sfc/coprocessor/sa1/memory.cpp @@ -18,9 +18,9 @@ inline auto SA1::idleBranch() -> void { if(r.pc.d & 1) idleJump(); } -auto SA1::read(uint24 address) -> uint8 { +auto SA1::read(n24 address) -> n8 { r.mar = address; - uint8 data = r.mdr; + n8 data = r.mdr; if((address & 0x40fe00) == 0x002200 //00-3f,80-bf:2200-23ff ) { @@ -62,7 +62,7 @@ auto SA1::read(uint24 address) -> uint8 { return data; } -auto SA1::write(uint24 address, uint8 data) -> void { +auto SA1::write(n24 address, n8 data) -> void { r.mar = address; r.mdr = data; @@ -110,7 +110,7 @@ auto SA1::write(uint24 address, uint8 data) -> void { //this is used both to keep VBR-reads from accessing MMIO registers, and //to avoid syncing the S-CPU and SA-1*; as both chips are able to access //these ports. -auto SA1::readVBR(uint24 address, uint8 data) -> uint8 { +auto SA1::readVBR(n24 address, n8 data) -> n8 { if((address & 0x408000) == 0x008000 //00-3f,80-bf:8000-ffff || (address & 0xc00000) == 0xc00000 //c0-ff:0000-ffff ) { @@ -132,8 +132,8 @@ auto SA1::readVBR(uint24 address, uint8 data) -> uint8 { return 0xff; } -auto SA1::readDisassembler(uint24 address) -> uint8 { - uint8 data = r.mdr; +auto SA1::readDisassembler(n24 address) -> n8 { + n8 data = r.mdr; if((address & 0x40fe00) == 0x002200 //00-3f,80-bf:2200-23ff ) { diff --git a/ares/sfc/coprocessor/sa1/rom.cpp b/ares/sfc/coprocessor/sa1/rom.cpp index f846330710..c6276b1b7c 100644 --- a/ares/sfc/coprocessor/sa1/rom.cpp +++ b/ares/sfc/coprocessor/sa1/rom.cpp @@ -4,18 +4,18 @@ inline auto SA1::ROM::conflict() const -> bool { return false; } -inline auto SA1::ROM::read(uint24 address, uint8 data) -> uint8 { +inline auto SA1::ROM::read(n24 address, n8 data) -> n8 { address = bus.mirror(address, size()); return ReadableMemory::read(address, data); } -inline auto SA1::ROM::write(uint24 address, uint8 data) -> void { +inline auto SA1::ROM::write(n24 address, n8 data) -> void { } //note: addresses are translated prior to invoking this function: //00-3f,80-bf:8000-ffff mask=0x408000 => 00-3f:0000-ffff //c0-ff:0000-ffff => untranslated -auto SA1::ROM::readCPU(uint24 address, uint8 data) -> uint8 { +auto SA1::ROM::readCPU(n24 address, n8 data) -> n8 { //reset vector overrides if((address & 0xffffe0) == 0x007fe0) { //00:ffe0-ffef if(address == 0x7fea && sa1.io.cpu_nvsw) return sa1.io.snv >> 0; @@ -24,7 +24,7 @@ auto SA1::ROM::readCPU(uint24 address, uint8 data) -> uint8 { if(address == 0x7fef && sa1.io.cpu_ivsw) return sa1.io.siv >> 8; } - static auto read = [](uint address) { + static auto read = [](n24 address) { if((address & 0x400000) && bsmemory.size()) return bsmemory.read(address, 0x00); return sa1.rom.read(address); }; @@ -55,15 +55,15 @@ auto SA1::ROM::readCPU(uint24 address, uint8 data) -> uint8 { return data; //unreachable } -auto SA1::ROM::writeCPU(uint24 address, uint8 data) -> void { +auto SA1::ROM::writeCPU(n24 address, n8 data) -> void { } -auto SA1::ROM::readSA1(uint24 address, uint8 data) -> uint8 { +auto SA1::ROM::readSA1(n24 address, n8 data) -> n8 { if((address & 0x408000) == 0x008000) { address = (address & 0x800000) >> 2 | (address & 0x3f0000) >> 1 | address & 0x007fff; } return readCPU(address, data); } -auto SA1::ROM::writeSA1(uint24 address, uint8 data) -> void { +auto SA1::ROM::writeSA1(n24 address, n8 data) -> void { } diff --git a/ares/sfc/coprocessor/sa1/sa1.cpp b/ares/sfc/coprocessor/sa1/sa1.cpp index 36d8fbd66e..2e71ac2789 100644 --- a/ares/sfc/coprocessor/sa1/sa1.cpp +++ b/ares/sfc/coprocessor/sa1/sa1.cpp @@ -136,7 +136,7 @@ auto SA1::power() -> void { cpu.coprocessors.append(this); bwram.dma = false; - for(uint address : range(iram.size())) { + for(u32 address : range(iram.size())) { iram.write(address, 0x00); } diff --git a/ares/sfc/coprocessor/sa1/sa1.hpp b/ares/sfc/coprocessor/sa1/sa1.hpp index 93b09de5f1..c01ffa20e3 100644 --- a/ares/sfc/coprocessor/sa1/sa1.hpp +++ b/ares/sfc/coprocessor/sa1/sa1.hpp @@ -32,32 +32,32 @@ struct SA1 : WDC65816, Thread { //dma.cpp struct DMA { - enum CDEN : uint { DmaNormal = 0, DmaCharConversion = 1 }; - enum SD : uint { SourceROM = 0, SourceBWRAM = 1, SourceIRAM = 2 }; - enum DD : uint { DestIRAM = 0, DestBWRAM = 1 }; - uint line; + enum CDEN : u32 { DmaNormal = 0, DmaCharConversion = 1 }; + enum SD : u32 { SourceROM = 0, SourceBWRAM = 1, SourceIRAM = 2 }; + enum DD : u32 { DestIRAM = 0, DestBWRAM = 1 }; + u32 line; }; auto dmaNormal() -> void; auto dmaCC1() -> void; - auto dmaCC1Read(uint address) -> uint8; + auto dmaCC1Read(n24 address) -> n8; auto dmaCC2() -> void; //memory.cpp auto idle() -> void override; auto idleJump() -> void override; auto idleBranch() -> void override; - auto read(uint24 address) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; - auto readVBR(uint24 address, uint8 data = 0) -> uint8; - auto readDisassembler(uint24 address) -> uint8 override; + auto read(n24 address) -> n8 override; + auto write(n24 address, n8 data) -> void override; + auto readVBR(n24 address, n8 data = 0) -> n8; + auto readDisassembler(n24 address) -> n8 override; //io.cpp - auto readIOCPU(uint24 address, uint8 data) -> uint8; - auto readIOSA1(uint24 address, uint8 data) -> uint8; - auto writeIOCPU(uint24 address, uint8 data) -> void; - auto writeIOSA1(uint24 address, uint8 data) -> void; - auto writeIOShared(uint24 address, uint8 data) -> void; + auto readIOCPU(n24 address, n8 data) -> n8; + auto readIOSA1(n24 address, n8 data) -> n8; + auto writeIOCPU(n24 address, n8 data) -> void; + auto writeIOSA1(n24 address, n8 data) -> void; + auto writeIOShared(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -66,34 +66,34 @@ struct SA1 : WDC65816, Thread { //rom.cpp auto conflict() const -> bool; - auto read(uint24 address, uint8 data = 0) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto read(n24 address, n8 data = 0) -> n8 override; + auto write(n24 address, n8 data) -> void override; - auto readCPU(uint24 address, uint8 data = 0) -> uint8; - auto writeCPU(uint24 address, uint8 data) -> void; + auto readCPU(n24 address, n8 data = 0) -> n8; + auto writeCPU(n24 address, n8 data) -> void; - auto readSA1(uint24 address, uint8 data = 0) -> uint8; - auto writeSA1(uint24 address, uint8 data) -> void; + auto readSA1(n24 address, n8 data = 0) -> n8; + auto writeSA1(n24 address, n8 data) -> void; } rom; struct BWRAM : WritableMemory { //bwram.cpp auto conflict() const -> bool; - auto read(uint24 address, uint8 data = 0) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto read(n24 address, n8 data = 0) -> n8 override; + auto write(n24 address, n8 data) -> void override; - auto readCPU(uint24 address, uint8 data = 0) -> uint8; - auto writeCPU(uint24 address, uint8 data) -> void; + auto readCPU(n24 address, n8 data = 0) -> n8; + auto writeCPU(n24 address, n8 data) -> void; - auto readSA1(uint24 address, uint8 data = 0) -> uint8; - auto writeSA1(uint24 address, uint8 data) -> void; + auto readSA1(n24 address, n8 data = 0) -> n8; + auto writeSA1(n24 address, n8 data) -> void; - auto readLinear(uint24 address, uint8 data = 0) -> uint8; - auto writeLinear(uint24 address, uint8 data) -> void; + auto readLinear(n24 address, n8 data = 0) -> n8; + auto writeLinear(n24 address, n8 data) -> void; - auto readBitmap(uint20 address, uint8 data = 0) -> uint8; - auto writeBitmap(uint20 address, uint8 data) -> void; + auto readBitmap(n20 address, n8 data = 0) -> n8; + auto writeBitmap(n20 address, n8 data) -> void; bool dma; } bwram; @@ -102,27 +102,27 @@ struct SA1 : WDC65816, Thread { //iram.cpp auto conflict() const -> bool; - auto read(uint24 address, uint8 data = 0) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto read(n24 address, n8 data = 0) -> n8 override; + auto write(n24 address, n8 data) -> void override; - auto readCPU(uint24 address, uint8 data) -> uint8; - auto writeCPU(uint24 address, uint8 data) -> void; + auto readCPU(n24 address, n8 data) -> n8; + auto writeCPU(n24 address, n8 data) -> void; - auto readSA1(uint24 address, uint8 data = 0) -> uint8; - auto writeSA1(uint24 address, uint8 data) -> void; + auto readSA1(n24 address, n8 data = 0) -> n8; + auto writeSA1(n24 address, n8 data) -> void; } iram; private: DMA dma; struct Status { - uint8 counter; + n8 counter; bool interruptPending; - uint16 scanlines; - uint16 vcounter; - uint16 hcounter; + n16 scanlines; + n16 vcounter; + n16 hcounter; } status; struct IO { @@ -131,7 +131,7 @@ struct SA1 : WDC65816, Thread { bool sa1_rdyb; bool sa1_resb; bool sa1_nmi; - uint8 smeg; + n8 smeg; //$2201 SIE bool cpu_irqen; @@ -142,19 +142,19 @@ struct SA1 : WDC65816, Thread { bool chdma_irqcl; //$2203,$2204 CRV - uint16 crv; + n16 crv; //$2205,$2206 CNV - uint16 cnv; + n16 cnv; //$2207,$2208 CIV - uint16 civ; + n16 civ; //$2209 SCNT bool cpu_irq; bool cpu_ivsw; bool cpu_nvsw; - uint8 cmeg; + n8 cmeg; //$220a CIE bool sa1_irqen; @@ -169,10 +169,10 @@ struct SA1 : WDC65816, Thread { bool sa1_nmicl; //$220c,$220d SNV - uint16 snv; + n16 snv; //$220e,$220f SIV - uint16 siv; + n16 siv; //$2210 TMC bool hvselb; @@ -180,33 +180,33 @@ struct SA1 : WDC65816, Thread { bool hen; //$2212,$2213 - uint16 hcnt; + n16 hcnt; //$2214,$2215 - uint16 vcnt; + n16 vcnt; //$2220 CXB bool cbmode; - uint cb; + n32 cb; //$2221 DXB bool dbmode; - uint db; + n32 db; //$2222 EXB bool ebmode; - uint eb; + n32 eb; //$2223 FXB bool fbmode; - uint fb; + n32 fb; //$2224 BMAPS - uint8 sbm; + n8 sbm; //$2225 BMAP bool sw46; - uint8 cbm; + n8 cbm; //$2226 SBWE bool swen; @@ -215,13 +215,13 @@ struct SA1 : WDC65816, Thread { bool cwen; //$2228 BWPA - uint8 bwp; + n8 bwp; //$2229 SIWP - uint8 siwp; + n8 siwp; //$222a CIWP - uint8 ciwp; + n8 ciwp; //$2230 DCNT bool dmaen; @@ -229,45 +229,45 @@ struct SA1 : WDC65816, Thread { bool cden; bool cdsel; bool dd; - uint8 sd; + n8 sd; //$2231 CDMA bool chdend; - uint8 dmasize; - uint8 dmacb; + n8 dmasize; + n8 dmacb; //$2232-$2234 SDA - uint24 dsa; + n24 dsa; //$2235-$2237 DDA - uint24 dda; + n24 dda; //$2238,$2239 DTC - uint16 dtc; + n16 dtc; //$223f BBF bool bbf; //$2240-224f BRF - uint8 brf[16]; + n8 brf[16]; //$2250 MCNT bool acm; bool md; //$2251,$2252 MA - uint16 ma; + n16 ma; //$2253,$2254 MB - uint16 mb; + n16 mb; //$2258 VBD bool hl; - uint8 vb; + n8 vb; //$2259-$225b VDA - uint24 va; - uint8 vbit; + n24 va; + n8 vbit; //$2300 SFR bool cpu_irqfl; @@ -280,13 +280,13 @@ struct SA1 : WDC65816, Thread { bool sa1_nmifl; //$2302,$2303 HCR - uint16 hcr; + n16 hcr; //$2304,$2305 VCR - uint16 vcr; + n16 vcr; //$2306-230a MR - uint64 mr; + n64 mr; //$230b OF bool overflow; diff --git a/ares/sfc/coprocessor/sdd1/decompressor.cpp b/ares/sfc/coprocessor/sdd1/decompressor.cpp index c647e1251d..0aa6d89043 100644 --- a/ares/sfc/coprocessor/sdd1/decompressor.cpp +++ b/ares/sfc/coprocessor/sdd1/decompressor.cpp @@ -4,14 +4,14 @@ //input manager -auto SDD1::Decompressor::IM::init(uint offset_) -> void { +auto SDD1::Decompressor::IM::init(n32 offset_) -> void { offset = offset_; bitCount = 4; } -auto SDD1::Decompressor::IM::getCodeWord(uint8 codeLength) -> uint8 { - uint8 codeWord; - uint8 compCount; +auto SDD1::Decompressor::IM::getCodeWord(n8 codeLength) -> n8 { + n8 codeWord; + n8 compCount; codeWord = sdd1.mmcRead(offset) << bitCount; bitCount++; @@ -31,7 +31,7 @@ auto SDD1::Decompressor::IM::getCodeWord(uint8 codeLength) -> uint8 { //golomb-code decoder -const uint8 SDD1::Decompressor::GCD::runCount[] = { +const n8 SDD1::Decompressor::GCD::runCount[] = { 0x00, 0x00, 0x01, 0x00, 0x03, 0x01, 0x02, 0x00, 0x07, 0x03, 0x05, 0x01, 0x06, 0x02, 0x04, 0x00, 0x0f, 0x07, 0x0b, 0x03, 0x0d, 0x05, 0x09, 0x01, @@ -66,8 +66,8 @@ const uint8 SDD1::Decompressor::GCD::runCount[] = { 0x70, 0x30, 0x50, 0x10, 0x60, 0x20, 0x40, 0x00, }; -auto SDD1::Decompressor::GCD::getRunCount(uint8 codeNumber, uint8& mpsCount, bool& lpsIndex) -> void { - uint8 codeWord = self.im.getCodeWord(codeNumber); +auto SDD1::Decompressor::GCD::getRunCount(n8 codeNumber, n8& mpsCount, bool& lpsIndex) -> void { + n8 codeWord = self.im.getCodeWord(codeNumber); if(codeWord & 0x80) { lpsIndex = 1; @@ -84,10 +84,10 @@ auto SDD1::Decompressor::BG::init() -> void { lpsIndex = 0; } -auto SDD1::Decompressor::BG::getBit(bool& endOfRun) -> uint8 { +auto SDD1::Decompressor::BG::getBit(bool& endOfRun) -> n8 { if(!(mpsCount || lpsIndex)) self.gcd.getRunCount(codeNumber, mpsCount, lpsIndex); - uint8 bit; + n8 bit; if(mpsCount) { bit = 0; mpsCount--; @@ -145,13 +145,13 @@ auto SDD1::Decompressor::PEM::init() -> void { } } -auto SDD1::Decompressor::PEM::getBit(uint8 context) -> uint8 { +auto SDD1::Decompressor::PEM::getBit(n8 context) -> n8 { ContextInfo& info = contextInfo[context]; - uint8 currentStatus = info.status; - uint8 currentMps = info.mps; + n8 currentStatus = info.status; + n8 currentMps = info.mps; const State& s = SDD1::Decompressor::PEM::evolutionTable[currentStatus]; - uint8 bit; + n8 bit; bool endOfRun; switch(s.codeNumber) { case 0: bit = self.bg0.getBit(endOfRun); break; @@ -178,7 +178,7 @@ auto SDD1::Decompressor::PEM::getBit(uint8 context) -> uint8 { //context model -auto SDD1::Decompressor::CM::init(uint offset) -> void { +auto SDD1::Decompressor::CM::init(n32 offset) -> void { bitplanesInfo = sdd1.mmcRead(offset) & 0xc0; contextBitsInfo = sdd1.mmcRead(offset) & 0x30; bitNumber = 0; @@ -190,7 +190,7 @@ auto SDD1::Decompressor::CM::init(uint offset) -> void { } } -auto SDD1::Decompressor::CM::getBit() -> uint8 { +auto SDD1::Decompressor::CM::getBit() -> n8 { switch(bitplanesInfo) { case 0x00: currentBitplane ^= 0x01; @@ -208,8 +208,8 @@ auto SDD1::Decompressor::CM::getBit() -> uint8 { break; } - uint16& contextBits = previousBitplaneBits[currentBitplane]; - uint8 currentContext = (currentBitplane & 0x01) << 4; + n16& contextBits = previousBitplaneBits[currentBitplane]; + n8 currentContext = (currentBitplane & 0x01) << 4; switch(contextBitsInfo) { case 0x00: currentContext |= ((contextBits & 0x01c0) >> 5) | (contextBits & 0x0001); break; case 0x10: currentContext |= ((contextBits & 0x0180) >> 5) | (contextBits & 0x0001); break; @@ -217,7 +217,7 @@ auto SDD1::Decompressor::CM::getBit() -> uint8 { case 0x30: currentContext |= ((contextBits & 0x0180) >> 5) | (contextBits & 0x0003); break; } - uint8 bit = self.pem.getBit(currentContext); + n8 bit = self.pem.getBit(currentContext); contextBits <<= 1; contextBits |= bit; bitNumber++; @@ -226,12 +226,12 @@ auto SDD1::Decompressor::CM::getBit() -> uint8 { //output logic -auto SDD1::Decompressor::OL::init(uint offset) -> void { +auto SDD1::Decompressor::OL::init(n32 offset) -> void { bitplanesInfo = sdd1.mmcRead(offset) & 0xc0; r0 = 0x01; } -auto SDD1::Decompressor::OL::decompress() -> uint8 { +auto SDD1::Decompressor::OL::decompress() -> n8 { switch(bitplanesInfo) { case 0x00: case 0x40: case 0x80: if(r0 == 0) { @@ -262,7 +262,7 @@ bg4(*this, 4), bg5(*this, 5), bg6(*this, 6), bg7(*this, 7), pem(*this), cm(*this), ol(*this) { } -auto SDD1::Decompressor::init(uint offset) -> void { +auto SDD1::Decompressor::init(n32 offset) -> void { im.init(offset); bg0.init(); bg1.init(); @@ -277,6 +277,6 @@ auto SDD1::Decompressor::init(uint offset) -> void { ol.init(offset); } -auto SDD1::Decompressor::read() -> uint8 { +auto SDD1::Decompressor::read() -> n8 { return ol.decompress(); } diff --git a/ares/sfc/coprocessor/sdd1/decompressor.hpp b/ares/sfc/coprocessor/sdd1/decompressor.hpp index e972c82165..cf74ff55b7 100644 --- a/ares/sfc/coprocessor/sdd1/decompressor.hpp +++ b/ares/sfc/coprocessor/sdd1/decompressor.hpp @@ -1,89 +1,89 @@ struct Decompressor { struct IM { //input manager IM(SDD1::Decompressor& self) : self(self) {} - auto init(uint offset) -> void; - auto getCodeWord(uint8 codeLength) -> uint8; + auto init(n32 offset) -> void; + auto getCodeWord(n8 codeLength) -> n8; auto serialize(serializer&) -> void; private: Decompressor& self; - uint offset; - uint bitCount; + n32 offset; + n32 bitCount; }; struct GCD { //golomb-code decoder GCD(SDD1::Decompressor& self) : self(self) {} - auto getRunCount(uint8 codeNumber, uint8& mpsCount, bool& lpsIndex) -> void; + auto getRunCount(n8 codeNumber, n8& mpsCount, bool& lpsIndex) -> void; auto serialize(serializer&) -> void; private: Decompressor& self; - static const uint8 runCount[256]; + static const n8 runCount[256]; }; struct BG { //bits generator - BG(SDD1::Decompressor& self, uint8 codeNumber) : self(self), codeNumber(codeNumber) {} + BG(SDD1::Decompressor& self, n8 codeNumber) : self(self), codeNumber(codeNumber) {} auto init() -> void; - auto getBit(bool& endOfRun) -> uint8; + auto getBit(bool& endOfRun) -> n8; auto serialize(serializer&) -> void; private: Decompressor& self; - const uint8 codeNumber; - uint8 mpsCount; + const n8 codeNumber; + n8 mpsCount; bool lpsIndex; }; struct PEM { //probability estimation module PEM(SDD1::Decompressor& self) : self(self) {} auto init() -> void; - auto getBit(uint8 context) -> uint8; + auto getBit(n8 context) -> n8; auto serialize(serializer&) -> void; private: Decompressor& self; struct State { - uint8 codeNumber; - uint8 nextIfMps; - uint8 nextIfLps; + n8 codeNumber; + n8 nextIfMps; + n8 nextIfLps; }; static const State evolutionTable[33]; struct ContextInfo { - uint8 status; - uint8 mps; + n8 status; + n8 mps; } contextInfo[32]; }; struct CM { //context model CM(SDD1::Decompressor& self) : self(self) {} - auto init(uint offset) -> void; - auto getBit() -> uint8; + auto init(n32 offset) -> void; + auto getBit() -> n8; auto serialize(serializer&) -> void; private: Decompressor& self; - uint8 bitplanesInfo; - uint8 contextBitsInfo; - uint8 bitNumber; - uint8 currentBitplane; - uint16 previousBitplaneBits[8]; + n8 bitplanesInfo; + n8 contextBitsInfo; + n8 bitNumber; + n8 currentBitplane; + n16 previousBitplaneBits[8]; }; struct OL { //output logic OL(SDD1::Decompressor& self) : self(self) {} - auto init(uint offset) -> void; - auto decompress() -> uint8; + auto init(n32 offset) -> void; + auto decompress() -> n8; auto serialize(serializer&) -> void; private: Decompressor& self; - uint8 bitplanesInfo; - uint8 r0, r1, r2; + n8 bitplanesInfo; + n8 r0, r1, r2; }; Decompressor(); - auto init(uint offset) -> void; - auto read() -> uint8; + auto init(n32 offset) -> void; + auto read() -> n8; auto serialize(serializer&) -> void; IM im; diff --git a/ares/sfc/coprocessor/sdd1/sdd1.cpp b/ares/sfc/coprocessor/sdd1/sdd1.cpp index 562f27300e..e31bf785ab 100644 --- a/ares/sfc/coprocessor/sdd1/sdd1.cpp +++ b/ares/sfc/coprocessor/sdd1/sdd1.cpp @@ -26,7 +26,7 @@ auto SDD1::power() -> void { dmaReady = false; } -auto SDD1::ioRead(uint24 address, uint8 data) -> uint8 { +auto SDD1::ioRead(n24 address, n8 data) -> n8 { address = 0x4800 | address.bit(0,3); switch(address) { @@ -42,7 +42,7 @@ auto SDD1::ioRead(uint24 address, uint8 data) -> uint8 { return rom.read(address); } -auto SDD1::ioWrite(uint24 address, uint8 data) -> void { +auto SDD1::ioWrite(n24 address, n8 data) -> void { address = 0x4800 | address.bit(0,3); switch(address) { @@ -55,12 +55,12 @@ auto SDD1::ioWrite(uint24 address, uint8 data) -> void { } } -auto SDD1::dmaRead(uint24 address, uint8 data) -> uint8 { +auto SDD1::dmaRead(n24 address, n8 data) -> n8 { return cpu.readDMA(address, data); } -auto SDD1::dmaWrite(uint24 address, uint8 data) -> void { - uint channel = address.bit(4,6); +auto SDD1::dmaWrite(n24 address, n8 data) -> void { + n3 channel = address.bit(4,6); switch(address.bit(0,3)) { case 2: dma[channel].address.byte(0) = data; break; case 3: dma[channel].address.byte(1) = data; break; @@ -71,31 +71,31 @@ auto SDD1::dmaWrite(uint24 address, uint8 data) -> void { return cpu.writeDMA(address, data); } -auto SDD1::mmcRead(uint24 address) -> uint8 { +auto SDD1::mmcRead(n24 address) -> n8 { switch(address.bit(20,21)) { - case 0: return rom.read((uint4)r4804 << 20 | (uint20)address); //c0-cf:0000-ffff - case 1: return rom.read((uint4)r4805 << 20 | (uint20)address); //d0-df:0000-ffff - case 2: return rom.read((uint4)r4806 << 20 | (uint20)address); //e0-ef:0000-ffff - case 3: return rom.read((uint4)r4807 << 20 | (uint20)address); //f0-ff:0000-ffff + case 0: return rom.read((n4)r4804 << 20 | (n20)address); //c0-cf:0000-ffff + case 1: return rom.read((n4)r4805 << 20 | (n20)address); //d0-df:0000-ffff + case 2: return rom.read((n4)r4806 << 20 | (n20)address); //e0-ef:0000-ffff + case 3: return rom.read((n4)r4807 << 20 | (n20)address); //f0-ff:0000-ffff } unreachable; } //map address=00-3f,80-bf:8000-ffff //map address=c0-ff:0000-ffff -auto SDD1::mcuRead(uint24 address, uint8 data) -> uint8 { +auto SDD1::mcuRead(n24 address, n8 data) -> n8 { //map address=00-3f,80-bf:8000-ffff if(!address.bit(22)) { if(!address.bit(23) && address.bit(21) && r4805.bit(7)) address.bit(21) = 0; //20-3f:8000-ffff if( address.bit(23) && address.bit(21) && r4807.bit(7)) address.bit(21) = 0; //a0-bf:8000-ffff - address = address.bit(16,21) << 15 | (uint15)address; + address = address.bit(16,21) << 15 | (n15)address; return rom.read(address); } //map address=c0-ff:0000-ffff if(r4800 & r4801) { //at least one channel has S-DD1 decompression enabled ... - for(uint n : range(8)) { + for(u32 n : range(8)) { if(r4800.bit(n) && r4801.bit(n)) { //S-DD1 always uses fixed transfer mode, so address will not change during transfer if(address == dma[n].address) { @@ -122,5 +122,5 @@ auto SDD1::mcuRead(uint24 address, uint8 data) -> uint8 { return mmcRead(address); } -auto SDD1::mcuWrite(uint24 address, uint8 data) -> void { +auto SDD1::mcuWrite(n24 address, n8 data) -> void { } diff --git a/ares/sfc/coprocessor/sdd1/sdd1.hpp b/ares/sfc/coprocessor/sdd1/sdd1.hpp index d564766434..6072109f9e 100644 --- a/ares/sfc/coprocessor/sdd1/sdd1.hpp +++ b/ares/sfc/coprocessor/sdd1/sdd1.hpp @@ -2,35 +2,34 @@ struct SDD1 { auto unload() -> void; auto power() -> void; - auto ioRead(uint24 address, uint8 data) -> uint8; - auto ioWrite(uint24 address, uint8 data) -> void; + auto ioRead(n24 address, n8 data) -> n8; + auto ioWrite(n24 address, n8 data) -> void; - auto dmaRead(uint24 address, uint8 data) -> uint8; - auto dmaWrite(uint24 address, uint8 data) -> void; + auto dmaRead(n24 address, n8 data) -> n8; + auto dmaWrite(n24 address, n8 data) -> void; - auto mmcRead(uint24 address) -> uint8; + auto mmcRead(n24 address) -> n8; - auto mcuRead(uint24 address, uint8 data) -> uint8; - auto mcuWrite(uint24 address, uint8 data) -> void; + auto mcuRead(n24 address, n8 data) -> n8; + auto mcuWrite(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; ReadableMemory rom; private: - uint8 r4800; //hard enable - uint8 r4801; //soft enable - uint8 r4804; //MMC bank 0 - uint8 r4805; //MMC bank 1 - uint8 r4806; //MMC bank 2 - uint8 r4807; //MMC bank 3 + n8 r4800; //hard enable + n8 r4801; //soft enable + n8 r4804; //MMC bank 0 + n8 r4805; //MMC bank 1 + n8 r4806; //MMC bank 2 + n8 r4807; //MMC bank 3 struct DMA { - uint24 address; //$43x2-$43x4 -- DMA transfer address - uint16 size; //$43x5-$43x6 -- DMA transfer size + n24 address; //$43x2-$43x4 -- DMA transfer address + n16 size; //$43x5-$43x6 -- DMA transfer size } dma[8]; - - bool dmaReady; //used to initialize decompression module + n1 dmaReady; //used to initialize decompression module public: #include "decompressor.hpp" diff --git a/ares/sfc/coprocessor/sharprtc/memory.cpp b/ares/sfc/coprocessor/sharprtc/memory.cpp index 6087a1df50..5ee0749c62 100644 --- a/ares/sfc/coprocessor/sharprtc/memory.cpp +++ b/ares/sfc/coprocessor/sharprtc/memory.cpp @@ -1,4 +1,4 @@ -auto SharpRTC::rtcRead(uint4 address) -> uint4 { +auto SharpRTC::rtcRead(n4 address) -> n4 { switch(address) { case 0: return second % 10; case 1: return second / 10; @@ -17,7 +17,7 @@ auto SharpRTC::rtcRead(uint4 address) -> uint4 { } } -auto SharpRTC::rtcWrite(uint4 address, uint4 data) -> void { +auto SharpRTC::rtcWrite(n4 address, n4 data) -> void { switch(address) { case 0: second = second / 10 * 10 + data; break; case 1: second = data * 10 + second % 10; break; @@ -35,31 +35,31 @@ auto SharpRTC::rtcWrite(uint4 address, uint4 data) -> void { } } -auto SharpRTC::load(const uint8* data) -> void { +auto SharpRTC::load(const n8* data) -> void { for(auto byte : range(8)) { rtcWrite(byte * 2 + 0, data[byte] >> 0); rtcWrite(byte * 2 + 1, data[byte] >> 4); } - uint64 timestamp = 0; + n64 timestamp = 0; for(auto byte : range(8)) { timestamp |= data[8 + byte] << (byte * 8); } - uint64 diff = (uint64)time(0) - timestamp; + n64 diff = (n64)time(0) - timestamp; while(diff >= 60 * 60 * 24) { tickDay(); diff -= 60 * 60 * 24; } while(diff >= 60 * 60) { tickHour(); diff -= 60 * 60; } while(diff >= 60) { tickMinute(); diff -= 60; } while(diff--) tickSecond(); } -auto SharpRTC::save(uint8* data) -> void { +auto SharpRTC::save(n8* data) -> void { for(auto byte : range(8)) { data[byte] = rtcRead(byte * 2 + 0) << 0; data[byte] |= rtcRead(byte * 2 + 1) << 4; } - uint64 timestamp = (uint64)time(nullptr); + n64 timestamp = (n64)time(nullptr); for(auto byte : range(8)) { data[8 + byte] = timestamp; timestamp >>= 8; diff --git a/ares/sfc/coprocessor/sharprtc/serialization.cpp b/ares/sfc/coprocessor/sharprtc/serialization.cpp index 6110a3f3cf..d0b727b838 100644 --- a/ares/sfc/coprocessor/sharprtc/serialization.cpp +++ b/ares/sfc/coprocessor/sharprtc/serialization.cpp @@ -1,7 +1,7 @@ auto SharpRTC::serialize(serializer& s) -> void { Thread::serialize(s); - s((uint&)state); + s((u32&)state); s(index); s(second); diff --git a/ares/sfc/coprocessor/sharprtc/sharprtc.cpp b/ares/sfc/coprocessor/sharprtc/sharprtc.cpp index d073885a5e..d39eef9db9 100644 --- a/ares/sfc/coprocessor/sharprtc/sharprtc.cpp +++ b/ares/sfc/coprocessor/sharprtc/sharprtc.cpp @@ -37,7 +37,7 @@ auto SharpRTC::power() -> void { index = -1; } -auto SharpRTC::synchronize(uint64 timestamp) -> void { +auto SharpRTC::synchronize(n64 timestamp) -> void { time_t systime = timestamp; tm* timeinfo = localtime(&systime); @@ -50,7 +50,7 @@ auto SharpRTC::synchronize(uint64 timestamp) -> void { weekday = timeinfo->tm_wday; } -auto SharpRTC::read(uint24 address, uint8 data) -> uint8 { +auto SharpRTC::read(n24 address, n8 data) -> n8 { address &= 1; if(address == 0) { @@ -70,7 +70,7 @@ auto SharpRTC::read(uint24 address, uint8 data) -> uint8 { return data; } -auto SharpRTC::write(uint24 address, uint8 data) -> void { +auto SharpRTC::write(n24 address, n8 data) -> void { address &= 1, data &= 15; if(address == 1) { diff --git a/ares/sfc/coprocessor/sharprtc/sharprtc.hpp b/ares/sfc/coprocessor/sharprtc/sharprtc.hpp index 4ef9b2d6b0..72b5568c6f 100644 --- a/ares/sfc/coprocessor/sharprtc/sharprtc.hpp +++ b/ares/sfc/coprocessor/sharprtc/sharprtc.hpp @@ -9,33 +9,33 @@ struct SharpRTC : Thread { auto initialize() -> void; auto unload() -> void; auto power() -> void; - auto synchronize(uint64 timestamp) -> void; + auto synchronize(n64 timestamp) -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; - enum class State : uint { Ready, Command, Read, Write } state; - int index; + enum class State : u32 { Ready, Command, Read, Write } state; + s32 index; - uint second; - uint minute; - uint hour; - uint day; - uint month; - uint year; - uint weekday; + u32 second; + u32 minute; + u32 hour; + u32 day; + u32 month; + u32 year; + u32 weekday; //memory.cpp - auto rtcRead(uint4 address) -> uint4; - auto rtcWrite(uint4 address, uint4 data) -> void; + auto rtcRead(n4 address) -> n4; + auto rtcWrite(n4 address, n4 data) -> void; - auto load(const uint8* data) -> void; - auto save(uint8* data) -> void; + auto load(const n8* data) -> void; + auto save(n8* data) -> void; //time.cpp - static const uint daysInMonth[12]; + static const u32 daysInMonth[12]; auto tickSecond() -> void; auto tickMinute() -> void; auto tickHour() -> void; @@ -43,7 +43,7 @@ struct SharpRTC : Thread { auto tickMonth() -> void; auto tickYear() -> void; - auto calculateWeekday(uint year, uint month, uint day) -> uint; + auto calculateWeekday(u32 year, u32 month, u32 day) -> u32; }; extern SharpRTC sharprtc; diff --git a/ares/sfc/coprocessor/sharprtc/time.cpp b/ares/sfc/coprocessor/sharprtc/time.cpp index be7355df81..948926fd3b 100644 --- a/ares/sfc/coprocessor/sharprtc/time.cpp +++ b/ares/sfc/coprocessor/sharprtc/time.cpp @@ -1,4 +1,4 @@ -const uint SharpRTC::daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +const u32 SharpRTC::daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; auto SharpRTC::tickSecond() -> void { if(++second < 60) return; @@ -19,7 +19,7 @@ auto SharpRTC::tickHour() -> void { } auto SharpRTC::tickDay() -> void { - uint days = daysInMonth[(month - 1) % 12]; + u32 days = daysInMonth[(month - 1) % 12]; //add one day in February for leap years if(month == 2) { @@ -41,15 +41,15 @@ auto SharpRTC::tickMonth() -> void { auto SharpRTC::tickYear() -> void { year++; - year = (uint12)year; + year = (n12)year; } //returns day of week for specified date //eg 0 = Sunday, 1 = Monday, ... 6 = Saturday //usage: calculate_weekday(2008, 1, 1) returns weekday of January 1st, 2008 -auto SharpRTC::calculateWeekday(uint year, uint month, uint day) -> uint { - uint y = 1000, m = 1; //SharpRTC epoch is 1000-01-01 - uint sum = 0; //number of days passed since epoch +auto SharpRTC::calculateWeekday(u32 year, u32 month, u32 day) -> u32 { + u32 y = 1000, m = 1; //SharpRTC epoch is 1000-01-01 + u32 sum = 0; //number of days passed since epoch year = max(1000, year); month = max(1, min(12, month)); @@ -66,7 +66,7 @@ auto SharpRTC::calculateWeekday(uint year, uint month, uint day) -> uint { } while(m < month) { - uint days = daysInMonth[(m - 1) % 12]; + u32 days = daysInMonth[(m - 1) % 12]; bool leapyearmonth = false; if(days == 28) { if(y % 4 == 0) { diff --git a/ares/sfc/coprocessor/spc7110/alu.cpp b/ares/sfc/coprocessor/spc7110/alu.cpp index 6b71dbc64d..e1bbdb83f0 100644 --- a/ares/sfc/coprocessor/spc7110/alu.cpp +++ b/ares/sfc/coprocessor/spc7110/alu.cpp @@ -3,20 +3,20 @@ auto SPC7110::aluMultiply() -> void { if(r482e & 1) { //signed 16-bit x 16-bit multiplication - int16 r0 = (int16)(r4824 | r4825 << 8); - int16 r1 = (int16)(r4820 | r4821 << 8); + i16 r0 = (i16)(r4824 | r4825 << 8); + i16 r1 = (i16)(r4820 | r4821 << 8); - int result = r0 * r1; + i32 result = r0 * r1; r4828 = result; r4829 = result >> 8; r482a = result >> 16; r482b = result >> 24; } else { //unsigned 16-bit x 16-bit multiplication - uint16 r0 = (uint16)(r4824 | r4825 << 8); - uint16 r1 = (uint16)(r4820 | r4821 << 8); + n16 r0 = (n16)(r4824 | r4825 << 8); + n16 r1 = (n16)(r4820 | r4821 << 8); - uint result = r0 * r1; + n32 result = r0 * r1; r4828 = result; r4829 = result >> 8; r482a = result >> 16; @@ -31,15 +31,15 @@ auto SPC7110::aluDivide() -> void { if(r482e & 1) { //signed 32-bit x 16-bit division - int32 dividend = (int32)(r4820 | r4821 << 8 | r4822 << 16 | r4823 << 24); - int16 divisor = (int16)(r4826 | r4827 << 8); + i32 dividend = (i32)(r4820 | r4821 << 8 | r4822 << 16 | r4823 << 24); + i16 divisor = (i16)(r4826 | r4827 << 8); - int32 quotient; - int16 remainder; + i32 quotient; + i16 remainder; if(divisor) { - quotient = (int32)(dividend / divisor); - remainder = (int32)(dividend % divisor); + quotient = (i32)(dividend / divisor); + remainder = (i32)(dividend % divisor); } else { //illegal division by zero quotient = 0; @@ -55,15 +55,15 @@ auto SPC7110::aluDivide() -> void { r482d = remainder >> 8; } else { //unsigned 32-bit x 16-bit division - uint32 dividend = (uint32)(r4820 | r4821 << 8 | r4822 << 16 | r4823 << 24); - uint16 divisor = (uint16)(r4826 | r4827 << 8); + n32 dividend = (n32)(r4820 | r4821 << 8 | r4822 << 16 | r4823 << 24); + n16 divisor = (n16)(r4826 | r4827 << 8); - uint32 quotient; - uint16 remainder; + n32 quotient; + n16 remainder; if(divisor) { - quotient = (uint32)(dividend / divisor); - remainder = (uint16)(dividend % divisor); + quotient = (n32)(dividend / divisor); + remainder = (n16)(dividend % divisor); } else { //illegal division by zero quotient = 0; diff --git a/ares/sfc/coprocessor/spc7110/data.cpp b/ares/sfc/coprocessor/spc7110/data.cpp index b10c0f1080..7ea087f7c4 100644 --- a/ares/sfc/coprocessor/spc7110/data.cpp +++ b/ares/sfc/coprocessor/spc7110/data.cpp @@ -1,30 +1,30 @@ -auto SPC7110::dataromRead(uint addr) -> uint8 { - uint size = 1 << (r4834 & 3); //size in MB - uint mask = 0x100000 * size - 1; - uint offset = addr & mask; - if((r4834 & 3) != 3 && (addr & 0x400000)) return 0x00; +auto SPC7110::dataromRead(n24 address) -> n8 { + n24 size = 1 << (r4834 & 3); //size in MB + n24 mask = 0x100000 * size - 1; + n24 offset = address & mask; + if((r4834 & 3) != 3 && (address & 0x400000)) return 0x00; return drom.read(Bus::mirror(offset, drom.size())); } -auto SPC7110::dataOffset() -> uint { return r4811 | r4812 << 8 | r4813 << 16; } -auto SPC7110::dataAdjust() -> uint { return r4814 | r4815 << 8; } -auto SPC7110::dataStride() -> uint { return r4816 | r4817 << 8; } -auto SPC7110::setDataOffset(uint addr) -> void { r4811 = addr; r4812 = addr >> 8; r4813 = addr >> 16; } -auto SPC7110::setDataAdjust(uint addr) -> void { r4814 = addr; r4815 = addr >> 8; } +auto SPC7110::dataOffset() -> n24 { return r4811 | r4812 << 8 | r4813 << 16; } +auto SPC7110::dataAdjust() -> n16 { return r4814 | r4815 << 8; } +auto SPC7110::dataStride() -> n16 { return r4816 | r4817 << 8; } +auto SPC7110::setDataOffset(n24 address) -> void { r4811 = address; r4812 = address >> 8; r4813 = address >> 16; } +auto SPC7110::setDataAdjust(n16 address) -> void { r4814 = address; r4815 = address >> 8; } auto SPC7110::dataPortRead() -> void { - uint offset = dataOffset(); - uint adjust = r4818 & 2 ? dataAdjust() : 0; - if(r4818 & 8) adjust = (int16)adjust; + n24 offset = dataOffset(); + n16 adjust = r4818 & 2 ? dataAdjust() : (n16)0; + if(r4818 & 8) adjust = (i16)adjust; r4810 = dataromRead(offset + adjust); } auto SPC7110::dataPortIncrement4810() -> void { - uint offset = dataOffset(); - uint stride = r4818 & 1 ? dataStride() : 1; - uint adjust = dataAdjust(); - if(r4818 & 4) stride = (int16)stride; - if(r4818 & 8) adjust = (int16)adjust; + n24 offset = dataOffset(); + n16 stride = r4818 & 1 ? dataStride() : (n16)1; + n16 adjust = dataAdjust(); + if(r4818 & 4) stride = (i16)stride; + if(r4818 & 8) adjust = (i16)adjust; if((r4818 & 16) == 0) setDataOffset(offset + stride); if((r4818 & 16) != 0) setDataAdjust(adjust + stride); dataPortRead(); @@ -32,27 +32,27 @@ auto SPC7110::dataPortIncrement4810() -> void { auto SPC7110::dataPortIncrement4814() -> void { if(r4818 >> 5 != 1) return; - uint offset = dataOffset(); - uint adjust = dataAdjust(); - if(r4818 & 8) adjust = (int16)adjust; + n24 offset = dataOffset(); + n16 adjust = dataAdjust(); + if(r4818 & 8) adjust = (i16)adjust; setDataOffset(offset + adjust); dataPortRead(); } auto SPC7110::dataPortIncrement4815() -> void { if(r4818 >> 5 != 2) return; - uint offset = dataOffset(); - uint adjust = dataAdjust(); - if(r4818 & 8) adjust = (int16)adjust; + n24 offset = dataOffset(); + n16 adjust = dataAdjust(); + if(r4818 & 8) adjust = (i16)adjust; setDataOffset(offset + adjust); dataPortRead(); } auto SPC7110::dataPortIncrement481a() -> void { if(r4818 >> 5 != 3) return; - uint offset = dataOffset(); - uint adjust = dataAdjust(); - if(r4818 & 8) adjust = (int16)adjust; + n24 offset = dataOffset(); + n16 adjust = dataAdjust(); + if(r4818 & 8) adjust = (i16)adjust; setDataOffset(offset + adjust); dataPortRead(); } diff --git a/ares/sfc/coprocessor/spc7110/dcu.cpp b/ares/sfc/coprocessor/spc7110/dcu.cpp index b91f2b63bb..cbfc86a0cb 100644 --- a/ares/sfc/coprocessor/spc7110/dcu.cpp +++ b/ares/sfc/coprocessor/spc7110/dcu.cpp @@ -1,10 +1,10 @@ #include "decompressor.cpp" auto SPC7110::dcuLoadAddress() -> void { - uint table = r4801 | r4802 << 8 | r4803 << 16; - uint index = r4804 << 2; + n24 table = r4801 | r4802 << 8 | r4803 << 16; + n24 index = r4804 << 2; - uint address = table + index; + n24 address = table + index; dcuMode = dataromRead(address + 0); dcuAddress = dataromRead(address + 1) << 16; dcuAddress |= dataromRead(address + 2) << 8; @@ -18,14 +18,14 @@ auto SPC7110::dcuBeginTransfer() -> void { decompressor->initialize(dcuMode, dcuAddress); decompressor->decode(); - uint seek = r480b & 2 ? r4805 | r4806 << 8 : 0; + n16 seek = r480b & 2 ? r4805 | r4806 << 8 : 0; while(seek--) decompressor->decode(); r480c |= 0x80; dcuOffset = 0; } -auto SPC7110::dcuRead() -> uint8 { +auto SPC7110::dcuRead() -> n8 { if((r480c & 0x80) == 0) return 0x00; if(dcuOffset == 0) { @@ -46,12 +46,12 @@ auto SPC7110::dcuRead() -> uint8 { break; } - uint seek = r480b & 1 ? r4807 : (uint8)1; + n8 seek = r480b & 1 ? r4807 : (n8)1; while(seek--) decompressor->decode(); } } - uint8 data = dcuTile[dcuOffset++]; + n8 data = dcuTile[dcuOffset++]; dcuOffset &= 8 * decompressor->bpp - 1; return data; } diff --git a/ares/sfc/coprocessor/spc7110/decompressor.cpp b/ares/sfc/coprocessor/spc7110/decompressor.cpp index 8699d21c3f..decbead6b7 100644 --- a/ares/sfc/coprocessor/spc7110/decompressor.cpp +++ b/ares/sfc/coprocessor/spc7110/decompressor.cpp @@ -7,13 +7,13 @@ struct Decompressor { Decompressor(SPC7110& spc7110) : spc7110(spc7110) {} - auto read() -> uint8 { + auto read() -> n8 { return spc7110.dataromRead(offset++); } //inverse morton code transform: unpack big-endian packed pixels //returns odd bits in lower half; even bits in upper half - auto deinterleave(uint64 data, uint bits) -> uint32 { + auto deinterleave(n64 data, n32 bits) -> n32 { data = data & (1ull << bits) - 1; data = 0x5555555555555555ull & (data << bits | data >> 1); data = 0x3333333333333333ull & (data | data >> 1); @@ -24,15 +24,15 @@ struct Decompressor { } //extract a nibble and move it to the low four bits - auto moveToFront(uint64 list, uint nibble) -> uint64 { - for(uint64 n = 0, mask = ~15; n < 64; n += 4, mask <<= 4) { + auto moveToFront(n64 list, n32 nibble) -> n64 { + for(n64 n = 0, mask = ~15; n < 64; n += 4, mask <<= 4) { if((list >> n & 15) != nibble) continue; return list = (list & mask) + (list << 4 & ~mask) + nibble; } return list; } - auto initialize(uint mode, uint origin) -> void { + auto initialize(n32 mode, n32 origin) -> void { for(auto& root : context) for(auto& node : root) node = {0, 0}; bpp = 1 << mode; offset = origin; @@ -46,17 +46,17 @@ struct Decompressor { } auto decode() -> void { - for(uint pixel = 0; pixel < 8; pixel++) { - uint64 map = colormap; - uint diff = 0; + for(n32 pixel = 0; pixel < 8; pixel++) { + n64 map = colormap; + n32 diff = 0; if(bpp > 1) { - uint pa = (bpp == 2 ? pixels >> 2 & 3 : pixels >> 0 & 15); - uint pb = (bpp == 2 ? pixels >> 14 & 3 : pixels >> 28 & 15); - uint pc = (bpp == 2 ? pixels >> 16 & 3 : pixels >> 32 & 15); + n32 pa = (bpp == 2 ? pixels >> 2 & 3 : pixels >> 0 & 15); + n32 pb = (bpp == 2 ? pixels >> 14 & 3 : pixels >> 28 & 15); + n32 pc = (bpp == 2 ? pixels >> 16 & 3 : pixels >> 32 & 15); if(pa != pb || pb != pc) { - uint match = pa ^ pb ^ pc; + n32 match = pa ^ pb ^ pc; diff = 4; //no match; all pixels differ if((match ^ pc) == 0) diff = 3; //a == b; pixel c differs if((match ^ pb) == 0) diff = 2; //c == a; pixel b differs @@ -70,10 +70,10 @@ struct Decompressor { map = moveToFront(map, pa); } - for(uint plane = 0; plane < bpp; plane++) { - uint bit = bpp > 1 ? 1 << plane : 1 << (pixel & 3); - uint history = bit - 1 & output; - uint set = 0; + for(n32 plane = 0; plane < bpp; plane++) { + n32 bit = bpp > 1 ? 1 << plane : 1 << (pixel & 3); + n32 history = bit - 1 & output; + n32 set = 0; if(bpp == 1) set = pixel >= 4; if(bpp == 2) set = diff; @@ -81,7 +81,7 @@ struct Decompressor { auto& ctx = context[set][bit + history - 1]; auto& model = evolution[ctx.prediction]; - uint8 lps_offset = range - model.probability; + n8 lps_offset = range - model.probability; bool symbol = input >= (lps_offset << 8); //test only the MSB output = output << 1 | (symbol ^ ctx.swap); @@ -108,7 +108,7 @@ struct Decompressor { if(symbol == LPS && model.probability > Half) ctx.swap ^= 1; } - uint index = output & (1 << bpp) - 1; + n32 index = output & (1 << bpp) - 1; if(bpp == 1) index ^= pixels >> 15 & 1; pixels = pixels << bpp | (map >> 4 * index & 15); @@ -138,29 +138,29 @@ struct Decompressor { s(result); } - enum : uint { MPS = 0, LPS = 1 }; - enum : uint { One = 0xaa, Half = 0x55, Max = 0xff }; + enum : u32 { MPS = 0, LPS = 1 }; + enum : u32 { One = 0xaa, Half = 0x55, Max = 0xff }; struct ModelState { - uint8 probability; //of the more probable symbol (MPS) - uint8 next[2]; //next state after output {MPS, LPS} + n8 probability; //of the more probable symbol (MPS) + n8 next[2]; //next state after output {MPS, LPS} }; static ModelState evolution[53]; struct Context { - uint8 prediction; //current model state - uint8 swap; //if 1, exchange the role of MPS and LPS + n8 prediction; //current model state + n8 swap; //if 1, exchange the role of MPS and LPS } context[5][15]; //not all 75 contexts exists; this simplifies the code - uint bpp; //bits per pixel (1bpp = 1; 2bpp = 2; 4bpp = 4) - uint offset; //SPC7110 data ROM read offset - uint bits; //bits remaining in input - uint16 range; //arithmetic range: technically 8-bits, but Max+1 = 256 - uint16 input; //input data from SPC7110 data ROM - uint8 output; - uint64 pixels; - uint64 colormap; //most recently used list - uint32 result; //decompressed word after calling decode() + n32 bpp; //bits per pixel (1bpp = 1; 2bpp = 2; 4bpp = 4) + n32 offset; //SPC7110 data ROM read offset + n32 bits; //bits remaining in input + n16 range; //arithmetic range: technically 8-bits, but Max+1 = 256 + n16 input; //input data from SPC7110 data ROM + n8 output; + n64 pixels; + n64 colormap; //most recently used list + n32 result; //decompressed word after calling decode() }; Decompressor::ModelState Decompressor::evolution[53] = { diff --git a/ares/sfc/coprocessor/spc7110/spc7110.cpp b/ares/sfc/coprocessor/spc7110/spc7110.cpp index 0d776322f6..108c0e3ac2 100644 --- a/ares/sfc/coprocessor/spc7110/spc7110.cpp +++ b/ares/sfc/coprocessor/spc7110/spc7110.cpp @@ -19,7 +19,7 @@ auto SPC7110::main() -> void { addClocks(1); } -auto SPC7110::addClocks(uint clocks) -> void { +auto SPC7110::addClocks(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -91,7 +91,7 @@ auto SPC7110::power() -> void { r4834 = 0x00; } -auto SPC7110::read(uint24 addr, uint8 data) -> uint8 { +auto SPC7110::read(n24 addr, n8 data) -> n8 { cpu.synchronize(*this); if((addr & 0xff0000) == 0x500000) addr = 0x4800; //$50:0000-ffff == $4800 if((addr & 0xff0000) == 0x580000) addr = 0x4808; //$58:0000-ffff == $4808 @@ -102,7 +102,7 @@ auto SPC7110::read(uint24 addr, uint8 data) -> uint8 { //decompression unit //================== case 0x4800: { - uint16 counter = r4809 | r480a << 8; + n16 counter = r4809 | r480a << 8; counter--; r4809 = counter >> 0; r480a = counter >> 8; @@ -175,7 +175,7 @@ auto SPC7110::read(uint24 addr, uint8 data) -> uint8 { return data; } -auto SPC7110::write(uint24 addr, uint8 data) -> void { +auto SPC7110::write(n24 addr, n8 data) -> void { cpu.synchronize(*this); if((addr & 0xff0000) == 0x500000) addr = 0x4800; //$50:0000-ffff == $4800 if((addr & 0xff0000) == 0x580000) addr = 0x4808; //$58:0000-ffff == $4808 @@ -239,8 +239,8 @@ auto SPC7110::write(uint24 addr, uint8 data) -> void { //map address=00-3f,80-bf:8000-ffff mask=0x800000 => 00-3f:8000-ffff //map address=c0-ff:0000-ffff mask=0xc00000 => c0-ff:0000-ffff -auto SPC7110::mcuromRead(uint24 addr, uint8 data) -> uint8 { - uint mask = (1 << (r4834 & 3)) - 1; //8mbit, 16mbit, 32mbit, 64mbit DROM +auto SPC7110::mcuromRead(n24 addr, n8 data) -> n8 { + u32 mask = (1 << (r4834 & 3)) - 1; //8mbit, 16mbit, 32mbit, 64mbit DROM if(addr < 0x100000) { //$00-0f,80-8f:8000-ffff; $c0-cf:0000-ffff addr &= 0x0fffff; @@ -275,7 +275,7 @@ auto SPC7110::mcuromRead(uint24 addr, uint8 data) -> uint8 { return data; } -auto SPC7110::mcuromWrite(uint24 addr, uint8 data) -> void { +auto SPC7110::mcuromWrite(n24 addr, n8 data) -> void { } //=============== @@ -283,7 +283,7 @@ auto SPC7110::mcuromWrite(uint24 addr, uint8 data) -> void { //=============== //map address=00-3f,80-bf:6000-7fff mask=0x80e000 => 00-07:0000-ffff -auto SPC7110::mcuramRead(uint24 addr, uint8) -> uint8 { +auto SPC7110::mcuramRead(n24 addr, n8) -> n8 { if(r4830 & 0x80) { addr = bus.mirror(addr, ram.size()); return ram.read(addr); @@ -291,7 +291,7 @@ auto SPC7110::mcuramRead(uint24 addr, uint8) -> uint8 { return 0x00; } -auto SPC7110::mcuramWrite(uint24 addr, uint8 data) -> void { +auto SPC7110::mcuramWrite(n24 addr, n8 data) -> void { if(r4830 & 0x80) { addr = bus.mirror(addr, ram.size()); ram.write(addr, data); diff --git a/ares/sfc/coprocessor/spc7110/spc7110.hpp b/ares/sfc/coprocessor/spc7110/spc7110.hpp index 25b06926d3..4051607d6a 100644 --- a/ares/sfc/coprocessor/spc7110/spc7110.hpp +++ b/ares/sfc/coprocessor/spc7110/spc7110.hpp @@ -8,37 +8,37 @@ struct SPC7110 : Thread { auto unload() -> void; auto power() -> void; - auto addClocks(uint clocks) -> void; + auto addClocks(u32 clocks) -> void; - auto read(uint24 addr, uint8 data) -> uint8; - auto write(uint24 addr, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; - auto mcuromRead(uint24 addr, uint8 data) -> uint8; - auto mcuromWrite(uint24 addr, uint8 data) -> void; + auto mcuromRead(n24 address, n8 data) -> n8; + auto mcuromWrite(n24 address, n8 data) -> void; - auto mcuramRead(uint24 addr, uint8 data) -> uint8; - auto mcuramWrite(uint24 addr, uint8 data) -> void; + auto mcuramRead(n24 address, n8 data) -> n8; + auto mcuramWrite(n24 address, n8 data) -> void; auto serialize(serializer&) -> void; //dcu.cpp auto dcuLoadAddress() -> void; auto dcuBeginTransfer() -> void; - auto dcuRead() -> uint8; + auto dcuRead() -> n8; - auto deinterleave1bpp(uint length) -> void; - auto deinterleave2bpp(uint length) -> void; - auto deinterleave4bpp(uint length) -> void; + auto deinterleave1bpp(u32 length) -> void; + auto deinterleave2bpp(u32 length) -> void; + auto deinterleave4bpp(u32 length) -> void; //data.cpp - auto dataromRead(uint addr) -> uint8; + auto dataromRead(n24 address) -> n8; - auto dataOffset() -> uint; - auto dataAdjust() -> uint; - auto dataStride() -> uint; + auto dataOffset() -> n24; + auto dataAdjust() -> n16; + auto dataStride() -> n16; - auto setDataOffset(uint addr) -> void; - auto setDataAdjust(uint addr) -> void; + auto setDataOffset(n24 address) -> void; + auto setDataAdjust(n16 address) -> void; auto dataPortRead() -> void; @@ -57,64 +57,64 @@ struct SPC7110 : Thread { private: //decompression unit - uint8 r4801; //compression table B0 - uint8 r4802; //compression table B1 - uint7 r4803; //compression table B2 - uint8 r4804; //compression table index - uint8 r4805; //adjust length B0 - uint8 r4806; //adjust length B1 - uint8 r4807; //stride length - uint8 r4809; //compression counter B0 - uint8 r480a; //compression counter B1 - uint8 r480b; //decompression settings - uint8 r480c; //decompression status - - bool dcuPending; - uint2 dcuMode; - uint23 dcuAddress; - uint dcuOffset; - uint8 dcuTile[32]; + n8 r4801; //compression table B0 + n8 r4802; //compression table B1 + n7 r4803; //compression table B2 + n8 r4804; //compression table index + n8 r4805; //adjust length B0 + n8 r4806; //adjust length B1 + n8 r4807; //stride length + n8 r4809; //compression counter B0 + n8 r480a; //compression counter B1 + n8 r480b; //decompression settings + n8 r480c; //decompression status + + n1 dcuPending; + n2 dcuMode; + n23 dcuAddress; + n32 dcuOffset; + n8 dcuTile[32]; Decompressor* decompressor = nullptr; //data port unit - uint8 r4810; //data port read + seek - uint8 r4811; //data offset B0 - uint8 r4812; //data offset B1 - uint7 r4813; //data offset B2 - uint8 r4814; //data adjust B0 - uint8 r4815; //data adjust B1 - uint8 r4816; //data stride B0 - uint8 r4817; //data stride B1 - uint8 r4818; //data port settings - uint8 r481a; //data port seek + n8 r4810; //data port read + seek + n8 r4811; //data offset B0 + n8 r4812; //data offset B1 + n7 r4813; //data offset B2 + n8 r4814; //data adjust B0 + n8 r4815; //data adjust B1 + n8 r4816; //data stride B0 + n8 r4817; //data stride B1 + n8 r4818; //data port settings + n8 r481a; //data port seek //arithmetic logic unit - uint8 r4820; //16-bit multiplicand B0, 32-bit dividend B0 - uint8 r4821; //16-bit multiplicand B1, 32-bit dividend B1 - uint8 r4822; //32-bit dividend B2 - uint8 r4823; //32-bit dividend B3 - uint8 r4824; //16-bit multiplier B0 - uint8 r4825; //16-bit multiplier B1 - uint8 r4826; //16-bit divisor B0 - uint8 r4827; //16-bit divisor B1 - uint8 r4828; //32-bit product B0, 32-bit quotient B0 - uint8 r4829; //32-bit product B1, 32-bit quotient B1 - uint8 r482a; //32-bit product B2, 32-bit quotient B2 - uint8 r482b; //32-bit product B3, 32-bit quotient B3 - uint8 r482c; //16-bit remainder B0 - uint8 r482d; //16-bit remainder B1 - uint8 r482e; //math settings - uint8 r482f; //math status - - bool mulPending; - bool divPending; + n8 r4820; //16-bit multiplicand B0, 32-bit dividend B0 + n8 r4821; //16-bit multiplicand B1, 32-bit dividend B1 + n8 r4822; //32-bit dividend B2 + n8 r4823; //32-bit dividend B3 + n8 r4824; //16-bit multiplier B0 + n8 r4825; //16-bit multiplier B1 + n8 r4826; //16-bit divisor B0 + n8 r4827; //16-bit divisor B1 + n8 r4828; //32-bit product B0, 32-bit quotient B0 + n8 r4829; //32-bit product B1, 32-bit quotient B1 + n8 r482a; //32-bit product B2, 32-bit quotient B2 + n8 r482b; //32-bit product B3, 32-bit quotient B3 + n8 r482c; //16-bit remainder B0 + n8 r482d; //16-bit remainder B1 + n8 r482e; //math settings + n8 r482f; //math status + + n1 mulPending; + n1 divPending; //memory control unit - uint8 r4830; //bank 0 mapping + SRAM write enable - uint8 r4831; //bank 1 mapping - uint8 r4832; //bank 2 mapping - uint8 r4833; //bank 3 mapping - uint8 r4834; //bank mapping settings + n8 r4830; //bank 0 mapping + SRAM write enable + n8 r4831; //bank 1 mapping + n8 r4832; //bank 2 mapping + n8 r4833; //bank 3 mapping + n8 r4834; //bank mapping settings }; extern SPC7110 spc7110; diff --git a/ares/sfc/coprocessor/superfx/bus.cpp b/ares/sfc/coprocessor/superfx/bus.cpp index 1ac550fa77..d7112b7c05 100644 --- a/ares/sfc/coprocessor/superfx/bus.cpp +++ b/ares/sfc/coprocessor/superfx/bus.cpp @@ -1,16 +1,16 @@ //ROM / RAM access from the S-CPU -auto SuperFX::CPUROM::data() -> uint8* { +auto SuperFX::CPUROM::data() -> n8* { return superfx.rom.data(); } -auto SuperFX::CPUROM::size() const -> uint { +auto SuperFX::CPUROM::size() const -> u32 { return superfx.rom.size(); } -auto SuperFX::CPUROM::read(uint24 address, uint8 data) -> uint8 { +auto SuperFX::CPUROM::read(n24 address, n8 data) -> n8 { if(superfx.regs.sfr.g && superfx.regs.scmr.ron) { - static const uint8 vector[16] = { + static constexpr u8 vector[16] = { 0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01, 0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01, }; @@ -19,44 +19,44 @@ auto SuperFX::CPUROM::read(uint24 address, uint8 data) -> uint8 { return superfx.rom.read(address, data); } -auto SuperFX::CPUROM::write(uint24 address, uint8 data) -> void { +auto SuperFX::CPUROM::write(n24 address, n8 data) -> void { superfx.rom.write(address, data); } // -auto SuperFX::CPURAM::data() -> uint8* { +auto SuperFX::CPURAM::data() -> n8* { return superfx.ram.data(); } -auto SuperFX::CPURAM::size() const -> uint { +auto SuperFX::CPURAM::size() const -> u32 { return superfx.ram.size(); } -auto SuperFX::CPURAM::read(uint24 address, uint8 data) -> uint8 { +auto SuperFX::CPURAM::read(n24 address, n8 data) -> n8 { if(superfx.regs.sfr.g && superfx.regs.scmr.ran) return data; return superfx.ram.read(address, data); } -auto SuperFX::CPURAM::write(uint24 address, uint8 data) -> void { +auto SuperFX::CPURAM::write(n24 address, n8 data) -> void { superfx.ram.write(address, data); } // -auto SuperFX::CPUBRAM::data() -> uint8* { +auto SuperFX::CPUBRAM::data() -> n8* { return superfx.bram.data(); } -auto SuperFX::CPUBRAM::size() const -> uint { +auto SuperFX::CPUBRAM::size() const -> u32 { return superfx.bram.size(); } -auto SuperFX::CPUBRAM::read(uint24 address, uint8 data) -> uint8 { +auto SuperFX::CPUBRAM::read(n24 address, n8 data) -> n8 { return superfx.bram.read(address, data); } -auto SuperFX::CPUBRAM::write(uint24 address, uint8 data) -> void { +auto SuperFX::CPUBRAM::write(n24 address, n8 data) -> void { if(!superfx.regs.bramr) return; superfx.bram.write(address, data); } diff --git a/ares/sfc/coprocessor/superfx/core.cpp b/ares/sfc/coprocessor/superfx/core.cpp index eb44044a6b..06212a868a 100644 --- a/ares/sfc/coprocessor/superfx/core.cpp +++ b/ares/sfc/coprocessor/superfx/core.cpp @@ -2,13 +2,13 @@ auto SuperFX::stop() -> void { cpu.irq(1); } -auto SuperFX::color(uint8 source) -> uint8 { +auto SuperFX::color(n8 source) -> n8 { if(regs.por.highnibble) return (regs.colr & 0xf0) | (source >> 4); if(regs.por.freezehigh) return (regs.colr & 0xf0) | (source & 0x0f); return source; } -auto SuperFX::plot(uint8 x, uint8 y) -> void { +auto SuperFX::plot(n8 x, n8 y) -> void { if(!regs.por.transparent) { if(regs.scmr.md == 3) { if(regs.por.freezehigh) { @@ -21,13 +21,13 @@ auto SuperFX::plot(uint8 x, uint8 y) -> void { } } - uint8 color = regs.colr; + n8 color = regs.colr; if(regs.por.dither && regs.scmr.md != 3) { if((x ^ y) & 1) color >>= 4; color &= 0x0f; } - uint16 offset = (y << 5) + (x >> 3); + n16 offset = (y << 5) + (x >> 3); if(offset != pixelcache[0].offset) { flushPixelCache(pixelcache[1]); pixelcache[1] = pixelcache[0]; @@ -45,24 +45,24 @@ auto SuperFX::plot(uint8 x, uint8 y) -> void { } } -auto SuperFX::rpix(uint8 x, uint8 y) -> uint8 { +auto SuperFX::rpix(n8 x, n8 y) -> n8 { flushPixelCache(pixelcache[1]); flushPixelCache(pixelcache[0]); - uint cn; //character number + u32 cn; //character number switch(regs.por.obj ? 3 : regs.scmr.ht) { case 0: cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3); break; case 1: cn = ((x & 0xf8) << 1) + ((x & 0xf8) >> 1) + ((y & 0xf8) >> 3); break; case 2: cn = ((x & 0xf8) << 1) + ((x & 0xf8) << 0) + ((y & 0xf8) >> 3); break; case 3: cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 3); break; } - uint bpp = 2 << (regs.scmr.md - (regs.scmr.md >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; - uint addr = 0x700000 + (cn * (bpp << 3)) + (regs.scbr << 10) + ((y & 0x07) * 2); - uint8 data = 0x00; + u32 bpp = 2 << (regs.scmr.md - (regs.scmr.md >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; + u32 addr = 0x700000 + (cn * (bpp << 3)) + (regs.scbr << 10) + ((y & 0x07) * 2); + n8 data = 0x00; x = (x & 7) ^ 7; - for(uint n : range(bpp)) { - uint byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; + for(u32 n : range(bpp)) { + u32 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; step(regs.clsr ? 5 : 6); data |= ((read(addr + byte) >> x) & 1) << n; } @@ -73,23 +73,23 @@ auto SuperFX::rpix(uint8 x, uint8 y) -> uint8 { auto SuperFX::flushPixelCache(PixelCache& cache) -> void { if(cache.bitpend == 0x00) return; - uint8 x = cache.offset << 3; - uint8 y = cache.offset >> 5; + n8 x = cache.offset << 3; + n8 y = cache.offset >> 5; - uint cn; //character number + u32 cn; //character number switch(regs.por.obj ? 3 : regs.scmr.ht) { case 0: cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3); break; case 1: cn = ((x & 0xf8) << 1) + ((x & 0xf8) >> 1) + ((y & 0xf8) >> 3); break; case 2: cn = ((x & 0xf8) << 1) + ((x & 0xf8) << 0) + ((y & 0xf8) >> 3); break; case 3: cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 3); break; } - uint bpp = 2 << (regs.scmr.md - (regs.scmr.md >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; - uint addr = 0x700000 + (cn * (bpp << 3)) + (regs.scbr << 10) + ((y & 0x07) * 2); + u32 bpp = 2 << (regs.scmr.md - (regs.scmr.md >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; + u32 addr = 0x700000 + (cn * (bpp << 3)) + (regs.scbr << 10) + ((y & 0x07) * 2); - for(uint n : range(bpp)) { - uint byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; - uint8 data = 0x00; - for(uint x : range(8)) data |= ((cache.data[x] >> n) & 1) << x; + for(u32 n : range(bpp)) { + u32 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; + n8 data = 0x00; + for(u32 x : range(8)) data |= ((cache.data[x] >> n) & 1) << x; if(cache.bitpend != 0xff) { step(regs.clsr ? 5 : 6); data &= cache.bitpend; diff --git a/ares/sfc/coprocessor/superfx/io.cpp b/ares/sfc/coprocessor/superfx/io.cpp index f645eecfa2..ed35415d49 100644 --- a/ares/sfc/coprocessor/superfx/io.cpp +++ b/ares/sfc/coprocessor/superfx/io.cpp @@ -1,4 +1,4 @@ -auto SuperFX::readIO(uint24 address, uint8) -> uint8 { +auto SuperFX::readIO(n24 address, n8) -> n8 { cpu.synchronize(*this); address = 0x3000 | address.bit(0,9); @@ -16,7 +16,7 @@ auto SuperFX::readIO(uint24 address, uint8) -> uint8 { } case 0x3031: { - uint8 r = regs.sfr >> 8; + n8 r = regs.sfr >> 8; regs.sfr.irq = 0; cpu.irq(0); return r; @@ -50,7 +50,7 @@ auto SuperFX::readIO(uint24 address, uint8) -> uint8 { return 0x00; } -auto SuperFX::writeIO(uint24 address, uint8 data) -> void { +auto SuperFX::writeIO(n24 address, n8 data) -> void { cpu.synchronize(*this); address = 0x3000 | address.bit(0,9); @@ -59,7 +59,7 @@ auto SuperFX::writeIO(uint24 address, uint8 data) -> void { } if(address >= 0x3000 && address <= 0x301f) { - uint n = address >> 1 & 15; + n4 n = address >> 1 & 15; if(!address.bit(0)) { regs.r[n] = (regs.r[n] & 0xff00) | data; } else { diff --git a/ares/sfc/coprocessor/superfx/memory.cpp b/ares/sfc/coprocessor/superfx/memory.cpp index 1970464976..b20e35ebb7 100644 --- a/ares/sfc/coprocessor/superfx/memory.cpp +++ b/ares/sfc/coprocessor/superfx/memory.cpp @@ -1,4 +1,4 @@ -auto SuperFX::read(uint24 address, uint8 data) -> uint8 { +auto SuperFX::read(n24 address, n8 data) -> n8 { if((address & 0xc00000) == 0x000000) { //$00-3f:0000-7fff,:8000-ffff while(!regs.scmr.ron) { step(6); @@ -29,7 +29,7 @@ auto SuperFX::read(uint24 address, uint8 data) -> uint8 { return data; } -auto SuperFX::write(uint24 address, uint8 data) -> void { +auto SuperFX::write(n24 address, n8 data) -> void { if((address & 0xfe0000) == 0x700000) { //$70-71:0000-ffff while(!regs.scmr.ran) { step(6); @@ -40,13 +40,13 @@ auto SuperFX::write(uint24 address, uint8 data) -> void { } } -auto SuperFX::readOpcode(uint16 address) -> uint8 { - uint16 offset = address - regs.cbr; +auto SuperFX::readOpcode(n16 address) -> n8 { + n16 offset = address - regs.cbr; if(offset < 512) { if(cache.valid[offset >> 4] == false) { - uint dp = offset & 0xfff0; - uint sp = (regs.pbr << 16) + ((regs.cbr + dp) & 0xfff0); - for(uint n : range(16)) { + u32 dp = offset & 0xfff0; + u32 sp = (regs.pbr << 16) + ((regs.cbr + dp) & 0xfff0); + for(u32 n : range(16)) { step(regs.clsr ? 5 : 6); cache.buffer[dp++] = read(sp++); } @@ -70,30 +70,30 @@ auto SuperFX::readOpcode(uint16 address) -> uint8 { } } -inline auto SuperFX::peekpipe() -> uint8 { - uint8 result = regs.pipeline; +inline auto SuperFX::peekpipe() -> n8 { + n8 result = regs.pipeline; regs.pipeline = readOpcode(regs.r[15]); regs.r[15].modified = false; return result; } -inline auto SuperFX::pipe() -> uint8 { - uint8 result = regs.pipeline; +inline auto SuperFX::pipe() -> n8 { + n8 result = regs.pipeline; regs.pipeline = readOpcode(++regs.r[15]); regs.r[15].modified = false; return result; } auto SuperFX::flushCache() -> void { - for(uint n : range(32)) cache.valid[n] = false; + for(u32 n : range(32)) cache.valid[n] = false; } -auto SuperFX::readCache(uint16 address) -> uint8 { +auto SuperFX::readCache(n16 address) -> n8 { address = (address + regs.cbr) & 511; return cache.buffer[address]; } -auto SuperFX::writeCache(uint16 address, uint8 data) -> void { +auto SuperFX::writeCache(n16 address, n8 data) -> void { address = (address + regs.cbr) & 511; cache.buffer[address] = data; if((address & 15) == 15) cache.valid[address >> 4] = true; diff --git a/ares/sfc/coprocessor/superfx/superfx.cpp b/ares/sfc/coprocessor/superfx/superfx.cpp index bebd3f7df3..da0220f960 100644 --- a/ares/sfc/coprocessor/superfx/superfx.cpp +++ b/ares/sfc/coprocessor/superfx/superfx.cpp @@ -54,9 +54,9 @@ auto SuperFX::power() -> void { ramMask = ram.size() - 1; bramMask = bram.size() - 1; - for(uint n : range(512)) cache.buffer[n] = 0x00; - for(uint n : range(32)) cache.valid[n] = false; - for(uint n : range(2)) { + for(u32 n : range(512)) cache.buffer[n] = 0x00; + for(u32 n : range(32)) cache.valid[n] = false; + for(u32 n : range(2)) { pixelcache[n].offset = ~0; pixelcache[n].bitpend = 0x00; } diff --git a/ares/sfc/coprocessor/superfx/superfx.hpp b/ares/sfc/coprocessor/superfx/superfx.hpp index a6040679c3..fdaaaae8e1 100644 --- a/ares/sfc/coprocessor/superfx/superfx.hpp +++ b/ares/sfc/coprocessor/superfx/superfx.hpp @@ -23,74 +23,74 @@ struct SuperFX : GSU, Thread { //bus.cpp struct CPUROM : AbstractMemory { - auto data() -> uint8* override; - auto size() const -> uint override; - auto read(uint24 address, uint8 data) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto data() -> n8* override; + auto size() const -> u32 override; + auto read(n24 address, n8 data) -> n8 override; + auto write(n24 address, n8 data) -> void override; }; struct CPURAM : AbstractMemory { - auto data() -> uint8* override; - auto size() const -> uint override; - auto read(uint24 address, uint8 data) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto data() -> n8* override; + auto size() const -> u32 override; + auto read(n24 address, n8 data) -> n8 override; + auto write(n24 address, n8 data) -> void override; }; struct CPUBRAM : AbstractMemory { - auto data() -> uint8* override; - auto size() const -> uint override; - auto read(uint24 address, uint8 data) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto data() -> n8* override; + auto size() const -> u32 override; + auto read(n24 address, n8 data) -> n8 override; + auto write(n24 address, n8 data) -> void override; }; //core.cpp auto stop() -> void override; - auto color(uint8 source) -> uint8 override; - auto plot(uint8 x, uint8 y) -> void override; - auto rpix(uint8 x, uint8 y) -> uint8 override; + auto color(n8 source) -> n8 override; + auto plot(n8 x, n8 y) -> void override; + auto rpix(n8 x, n8 y) -> n8 override; auto flushPixelCache(PixelCache& cache) -> void; //memory.cpp - auto read(uint24 address, uint8 data = 0x00) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; + auto read(n24 address, n8 data = 0x00) -> n8 override; + auto write(n24 address, n8 data) -> void override; - auto readOpcode(uint16 address) -> uint8; - auto peekpipe() -> uint8; - auto pipe() -> uint8 override; + auto readOpcode(n16 address) -> n8; + auto peekpipe() -> n8; + auto pipe() -> n8 override; auto flushCache() -> void override; - auto readCache(uint16 address) -> uint8; - auto writeCache(uint16 address, uint8 data) -> void; + auto readCache(n16 address) -> n8; + auto writeCache(n16 address, n8 data) -> void; //io.cpp - auto readIO(uint24 address, uint8 data) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto readIO(n24 address, n8 data) -> n8; + auto writeIO(n24 address, n8 data) -> void; //timing.cpp - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto syncROMBuffer() -> void override; - auto readROMBuffer() -> uint8 override; + auto readROMBuffer() -> n8 override; auto updateROMBuffer() -> void; auto syncRAMBuffer() -> void override; - auto readRAMBuffer(uint16 address) -> uint8 override; - auto writeRAMBuffer(uint16 address, uint8 data) -> void override; + auto readRAMBuffer(n16 address) -> n8 override; + auto writeRAMBuffer(n16 address, n8 data) -> void override; //serialization.cpp auto serialize(serializer&) -> void; - uint Frequency; + n32 Frequency; CPUROM cpurom; CPURAM cpuram; CPUBRAM cpubram; private: - uint romMask; - uint ramMask; - uint bramMask; + n32 romMask; + n32 ramMask; + n32 bramMask; }; extern SuperFX superfx; diff --git a/ares/sfc/coprocessor/superfx/timing.cpp b/ares/sfc/coprocessor/superfx/timing.cpp index 83c4afbf98..7043518688 100644 --- a/ares/sfc/coprocessor/superfx/timing.cpp +++ b/ares/sfc/coprocessor/superfx/timing.cpp @@ -1,4 +1,4 @@ -auto SuperFX::step(uint clocks) -> void { +auto SuperFX::step(u32 clocks) -> void { if(regs.romcl) { regs.romcl -= min(clocks, regs.romcl); if(regs.romcl == 0) { @@ -22,7 +22,7 @@ auto SuperFX::syncROMBuffer() -> void { if(regs.romcl) step(regs.romcl); } -auto SuperFX::readROMBuffer() -> uint8 { +auto SuperFX::readROMBuffer() -> n8 { syncROMBuffer(); return regs.romdr; } @@ -36,12 +36,12 @@ auto SuperFX::syncRAMBuffer() -> void { if(regs.ramcl) step(regs.ramcl); } -auto SuperFX::readRAMBuffer(uint16 address) -> uint8 { +auto SuperFX::readRAMBuffer(n16 address) -> n8 { syncRAMBuffer(); return read(0x700000 + (regs.rambr << 16) + address); } -auto SuperFX::writeRAMBuffer(uint16 address, uint8 data) -> void { +auto SuperFX::writeRAMBuffer(n16 address, n8 data) -> void { syncRAMBuffer(); regs.ramcl = regs.clsr ? 5 : 6; regs.ramar = address; diff --git a/ares/sfc/cpu/cpu.cpp b/ares/sfc/cpu/cpu.cpp index 5473983023..d97c0aea19 100644 --- a/ares/sfc/cpu/cpu.cpp +++ b/ares/sfc/cpu/cpu.cpp @@ -61,8 +61,8 @@ auto CPU::main() -> void { } auto CPU::map() -> void { - function reader; - function writer; + function reader; + function writer; reader = {&CPU::readRAM, this}; writer = {&CPU::writeRAM, this}; @@ -91,7 +91,7 @@ auto CPU::power(bool reset) -> void { if(!reset) random.array({wram, sizeof(wram)}); - for(uint id : range(8)) { + for(u32 id : range(8)) { channels[id] = {}; channels[id].id = id; if(id != 7) channels[id].next = channels[id + 1]; diff --git a/ares/sfc/cpu/cpu.hpp b/ares/sfc/cpu/cpu.hpp index 8ab718ddd2..b96d7acc05 100644 --- a/ares/sfc/cpu/cpu.hpp +++ b/ares/sfc/cpu/cpu.hpp @@ -7,7 +7,7 @@ struct CPU : WDC65816, Thread, PPUcounter { auto load(Node::Object) -> void; auto instruction() -> void; auto interrupt(string_view) -> void; - auto dma(uint8 channelID, uint24 addressA, uint8 addressB, uint8 data) -> void; + auto dma(n8 channelID, n24 addressA, n8 addressB, n8 data) -> void; struct Memory { Node::Debugger::Memory wram; @@ -21,7 +21,7 @@ struct CPU : WDC65816, Thread, PPUcounter { } debugger; auto interruptPending() const -> bool override { return status.interruptPending; } - auto pio() const -> uint8 { return io.pio; } + auto pio() const -> n8 { return io.pio; } auto refresh() const -> bool { return status.dramRefresh == 1; } auto synchronizing() const -> bool override { return scheduler.synchronizing(); } @@ -45,26 +45,26 @@ struct CPU : WDC65816, Thread, PPUcounter { //memory.cpp auto idle() -> void override; - auto read(uint24 address) -> uint8 override; - auto write(uint24 address, uint8 data) -> void override; - auto wait(uint24 address) const -> uint; - auto readDisassembler(uint24 address) -> uint8 override; + auto read(n24 address) -> n8 override; + auto write(n24 address, n8 data) -> void override; + auto wait(n24 address) const -> u32; + auto readDisassembler(n24 address) -> n8 override; //io.cpp - auto readRAM(uint24 address, uint8 data) -> uint8; - auto readAPU(uint24 address, uint8 data) -> uint8; - auto readCPU(uint24 address, uint8 data) -> uint8; - auto readDMA(uint24 address, uint8 data) -> uint8; - auto writeRAM(uint24 address, uint8 data) -> void; - auto writeAPU(uint24 address, uint8 data) -> void; - auto writeCPU(uint24 address, uint8 data) -> void; - auto writeDMA(uint24 address, uint8 data) -> void; + auto readRAM(n24 address, n8 data) -> n8; + auto readAPU(n24 address, n8 data) -> n8; + auto readCPU(n24 address, n8 data) -> n8; + auto readDMA(n24 address, n8 data) -> n8; + auto writeRAM(n24 address, n8 data) -> void; + auto writeAPU(n24 address, n8 data) -> void; + auto writeCPU(n24 address, n8 data) -> void; + auto writeDMA(n24 address, n8 data) -> void; //timing.cpp - auto dmaCounter() const -> uint; - auto joypadCounter() const -> uint; + auto dmaCounter() const -> u32; + auto joypadCounter() const -> u32; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto scanline() -> void; auto aluEdge() -> void; @@ -74,7 +74,7 @@ struct CPU : WDC65816, Thread, PPUcounter { //irq.cpp auto nmiPoll() -> void; auto irqPoll() -> void; - auto nmitimenUpdate(uint8 data) -> void; + auto nmitimenUpdate(n8 data) -> void; auto rdnmi() -> bool; auto timeup() -> bool; @@ -85,28 +85,28 @@ struct CPU : WDC65816, Thread, PPUcounter { //serialization.cpp auto serialize(serializer&) -> void; - uint8 wram[128 * 1024]; + n8 wram[128_KiB]; vector coprocessors; vector peripherals; private: struct Counter { - uint cpu = 0; - uint dma = 0; + u32 cpu = 0; + u32 dma = 0; } counter; struct Status { - uint clockCount = 0; + u32 clockCount = 0; bool irqLock = 0; - uint dramRefreshPosition = 0; - uint dramRefresh = 0; //0 = not refreshed; 1 = refresh active; 2 = refresh inactive + u32 dramRefreshPosition = 0; + u32 dramRefresh = 0; //0 = not refreshed; 1 = refresh active; 2 = refresh inactive - uint hdmaSetupPosition = 0; + u32 hdmaSetupPosition = 0; bool hdmaSetupTriggered = 0; - uint hdmaPosition = 0; + u32 hdmaPosition = 0; bool hdmaTriggered = 0; boolean nmiValid; @@ -129,12 +129,12 @@ struct CPU : WDC65816, Thread, PPUcounter { bool hdmaPending = 0; bool hdmaMode = 0; //0 = init, 1 = run - uint autoJoypadCounter = 33; //state machine; 4224 / 128 = 33 (inactive) + u32 autoJoypadCounter = 33; //state machine; 4224 / 128 = 33 (inactive) } status; struct IO { //$2181-$2183 - uint17 wramAddress; + n17 wramAddress; //$4200 boolean hirqEnable; @@ -144,54 +144,54 @@ struct CPU : WDC65816, Thread, PPUcounter { boolean autoJoypadPoll; //$4201 - uint8 pio = 0xff; + n8 pio = 0xff; //$4202-$4203 - uint8 wrmpya = 0xff; - uint8 wrmpyb = 0xff; + n8 wrmpya = 0xff; + n8 wrmpyb = 0xff; //$4204-$4206 - uint16 wrdiva = 0xffff; - uint8 wrdivb = 0xff; + n16 wrdiva = 0xffff; + n8 wrdivb = 0xff; //$4207-$420a - uint12 htime = 0x1ff + 1 << 2; - uint9 vtime = 0x1ff; + n12 htime = 0x1ff + 1 << 2; + n9 vtime = 0x1ff; //$420d - uint romSpeed = 8; + u32 romSpeed = 8; //$4210 - uint4 version = 2; //allowed values: 1, 2 + n4 version = 2; //allowed values: 1, 2 //$4214-$4217 - uint16 rddiv; - uint16 rdmpy; + n16 rddiv; + n16 rdmpy; //$4218-$421f - uint16 joy1; - uint16 joy2; - uint16 joy3; - uint16 joy4; + n16 joy1; + n16 joy2; + n16 joy3; + n16 joy4; } io; struct ALU { - uint mpyctr = 0; - uint divctr = 0; - uint shift = 0; + u32 mpyctr = 0; + u32 divctr = 0; + u32 shift = 0; } alu; struct Channel { //dma.cpp - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto edge() -> void; - auto validA(uint24 address) -> bool; - auto readA(uint24 address) -> uint8; - auto readB(uint8 address, bool valid) -> uint8; - auto writeA(uint24 address, uint8 data) -> void; - auto writeB(uint8 address, uint8 data, bool valid) -> void; - auto transfer(uint24 address, uint2 index) -> void; + auto validA(n24 address) -> bool; + auto readA(n24 address) -> n8; + auto readB(n8 address, bool valid) -> n8; + auto writeA(n24 address, n8 data) -> void; + auto writeB(n8 address, n8 data, bool valid) -> void; + auto transfer(n24 address, n2 index) -> void; auto dmaRun() -> void; auto hdmaActive() -> bool; @@ -203,52 +203,52 @@ struct CPU : WDC65816, Thread, PPUcounter { auto hdmaAdvance() -> void; //$420b - uint1 dmaEnable; + n1 dmaEnable; //$420c - uint1 hdmaEnable; + n1 hdmaEnable; //$43x0 - uint3 transferMode = 7; - uint1 fixedTransfer = 1; - uint1 reverseTransfer = 1; - uint1 unused = 1; - uint1 indirect = 1; - uint1 direction = 1; + n3 transferMode = 7; + n1 fixedTransfer = 1; + n1 reverseTransfer = 1; + n1 unused = 1; + n1 indirect = 1; + n1 direction = 1; //$43x1 - uint8 targetAddress = 0xff; + n8 targetAddress = 0xff; //$43x2-$43x3 - uint16 sourceAddress = 0xffff; + n16 sourceAddress = 0xffff; //$43x4 - uint8 sourceBank = 0xff; + n8 sourceBank = 0xff; //$43x5-$43x6 union { - uint16 transferSize; - uint16 indirectAddress; + n16 transferSize; + n16 indirectAddress; }; //$43x7 - uint8 indirectBank = 0xff; + n8 indirectBank = 0xff; //$43x8-$43x9 - uint16 hdmaAddress = 0xffff; + n16 hdmaAddress = 0xffff; //$43xa - uint8 lineCounter = 0xff; + n8 lineCounter = 0xff; //$43xb/$43xf - uint8 unknown = 0xff; + n8 unknown = 0xff; //internal state - uint1 hdmaCompleted; - uint1 hdmaDoTransfer; + n1 hdmaCompleted; + n1 hdmaDoTransfer; //unserialized: - uint8 id; + n8 id; maybe next; Channel() : transferSize(0xffff) {} diff --git a/ares/sfc/cpu/debugger.cpp b/ares/sfc/cpu/debugger.cpp index 662b34dd31..cb6e900dab 100644 --- a/ares/sfc/cpu/debugger.cpp +++ b/ares/sfc/cpu/debugger.cpp @@ -2,10 +2,10 @@ auto CPU::Debugger::load(Node::Object parent) -> void { memory.wram = parent->append("CPU WRAM"); memory.wram->setSize(128_KiB); memory.wram->setRead([&](u32 address) -> u8 { - return cpu.wram[uint17(address)]; + return cpu.wram[n17(address)]; }); memory.wram->setWrite([&](u32 address, u8 data) -> void { - cpu.wram[uint17(address)] = data; + cpu.wram[n17(address)] = data; }); tracer.instruction = parent->append("Instruction", "CPU"); @@ -19,7 +19,7 @@ auto CPU::Debugger::load(Node::Object parent) -> void { auto CPU::Debugger::instruction() -> void { if(tracer.instruction->enabled() && tracer.instruction->address(cpu.r.pc.d)) { tracer.instruction->notify(cpu.disassembleInstruction(), cpu.disassembleContext(), { - "V:", pad(cpu.vcounter(), 3L), " ", "H:", pad(cpu.hcounter(), 4L), " I:", (uint)cpu.field() + "V:", pad(cpu.vcounter(), 3L), " ", "H:", pad(cpu.hcounter(), 4L), " I:", (u32)cpu.field() }); } } @@ -30,7 +30,7 @@ auto CPU::Debugger::interrupt(string_view type) -> void { } } -auto CPU::Debugger::dma(uint8 channelID, uint24 addressA, uint8 addressB, uint8 data) -> void { +auto CPU::Debugger::dma(n8 channelID, n24 addressA, n8 addressB, n8 data) -> void { if(tracer.dma->enabled()) { string output; output.append("Channel ", channelID, ": "); diff --git a/ares/sfc/cpu/dma.cpp b/ares/sfc/cpu/dma.cpp index 607edd2dd4..16261ff888 100644 --- a/ares/sfc/cpu/dma.cpp +++ b/ares/sfc/cpu/dma.cpp @@ -42,7 +42,7 @@ auto CPU::hdmaRun() -> void { // -inline auto CPU::Channel::step(uint clocks) -> void { +inline auto CPU::Channel::step(u32 clocks) -> void { cpu.counter.dma += clocks; cpu.step(clocks); } @@ -51,7 +51,7 @@ inline auto CPU::Channel::edge() -> void { cpu.dmaEdge(); } -inline auto CPU::Channel::validA(uint24 address) -> bool { +inline auto CPU::Channel::validA(n24 address) -> bool { //A-bus cannot access the B-bus or CPU I/O registers if((address & 0x40ff00) == 0x2100) return false; //00-3f,80-bf:2100-21ff if((address & 0x40fe00) == 0x4000) return false; //00-3f,80-bf:4000-41ff @@ -60,30 +60,30 @@ inline auto CPU::Channel::validA(uint24 address) -> bool { return true; } -inline auto CPU::Channel::readA(uint24 address) -> uint8 { +inline auto CPU::Channel::readA(n24 address) -> n8 { step(4); - cpu.r.mdr = validA(address) ? bus.read(address, cpu.r.mdr) : (uint8)0x00; + cpu.r.mdr = validA(address) ? bus.read(address, cpu.r.mdr) : (n8)0x00; step(4); return cpu.r.mdr; } -inline auto CPU::Channel::readB(uint8 address, bool valid) -> uint8 { +inline auto CPU::Channel::readB(n8 address, bool valid) -> n8 { step(4); - cpu.r.mdr = valid ? bus.read(0x2100 | address, cpu.r.mdr) : (uint8)0x00; + cpu.r.mdr = valid ? bus.read(0x2100 | address, cpu.r.mdr) : (n8)0x00; step(4); return cpu.r.mdr; } -inline auto CPU::Channel::writeA(uint24 address, uint8 data) -> void { +inline auto CPU::Channel::writeA(n24 address, n8 data) -> void { if(validA(address)) bus.write(address, data); } -inline auto CPU::Channel::writeB(uint8 address, uint8 data, bool valid) -> void { +inline auto CPU::Channel::writeB(n8 address, n8 data, bool valid) -> void { if(valid) bus.write(0x2100 | address, data); } -inline auto CPU::Channel::transfer(uint24 addressA, uint2 index) -> void { - uint8 addressB = targetAddress; +inline auto CPU::Channel::transfer(n24 addressA, n2 index) -> void { + n8 addressB = targetAddress; switch(transferMode) { case 1: case 5: addressB += index.bit(0); break; case 3: case 7: addressB += index.bit(1); break; @@ -111,7 +111,7 @@ inline auto CPU::Channel::dmaRun() -> void { step(8); edge(); - uint2 index = 0; + n2 index = 0; do { transfer(sourceBank << 16 | sourceAddress, index++); if(!fixedTransfer) !reverseTransfer ? sourceAddress++ : sourceAddress--; @@ -152,7 +152,7 @@ inline auto CPU::Channel::hdmaSetup() -> void { inline auto CPU::Channel::hdmaReload() -> void { auto data = readA(cpu.r.mar = sourceBank << 16 | hdmaAddress); - if((uint7)lineCounter == 0) { + if((n7)lineCounter == 0) { lineCounter = data; hdmaAddress++; @@ -175,9 +175,9 @@ inline auto CPU::Channel::hdmaTransfer() -> void { dmaEnable = false; //HDMA will stop active DMA mid-transfer if(!hdmaDoTransfer) return; - static const uint lengths[8] = {1, 2, 2, 4, 4, 4, 2, 4}; - for(uint2 index : range(lengths[transferMode])) { - uint24 address = !indirect ? sourceBank << 16 | hdmaAddress++ : indirectBank << 16 | indirectAddress++; + static constexpr u32 lengths[8] = {1, 2, 2, 4, 4, 4, 2, 4}; + for(n2 index : range(lengths[transferMode])) { + n24 address = !indirect ? sourceBank << 16 | hdmaAddress++ : indirectBank << 16 | indirectAddress++; transfer(address, index); } } diff --git a/ares/sfc/cpu/io.cpp b/ares/sfc/cpu/io.cpp index 2102483846..6f5cd11722 100644 --- a/ares/sfc/cpu/io.cpp +++ b/ares/sfc/cpu/io.cpp @@ -1,14 +1,14 @@ -auto CPU::readRAM(uint24 address, uint8 data) -> uint8 { +auto CPU::readRAM(n24 address, n8 data) -> n8 { return wram[address]; } -auto CPU::readAPU(uint24 address, uint8 data) -> uint8 { +auto CPU::readAPU(n24 address, n8 data) -> n8 { synchronize(smp); return smp.portRead(address.bit(0,1)); } -auto CPU::readCPU(uint24 address, uint8 data) -> uint8 { - switch((uint16)address) { +auto CPU::readCPU(n24 address, n8 data) -> n8 { + switch((n16)address) { case 0x2180: //WMDATA return bus.read(0x7e0000 | io.wramAddress++, data); @@ -57,7 +57,7 @@ auto CPU::readCPU(uint24 address, uint8 data) -> uint8 { return data; } -auto CPU::readDMA(uint24 address, uint8 data) -> uint8 { +auto CPU::readDMA(n24 address, n8 data) -> n8 { auto& channel = this->channels[address.bit(4,6)]; switch(address & 0xff8f) { @@ -89,17 +89,17 @@ auto CPU::readDMA(uint24 address, uint8 data) -> uint8 { return data; } -auto CPU::writeRAM(uint24 address, uint8 data) -> void { +auto CPU::writeRAM(n24 address, n8 data) -> void { wram[address] = data; } -auto CPU::writeAPU(uint24 address, uint8 data) -> void { +auto CPU::writeAPU(n24 address, n8 data) -> void { synchronize(smp); return smp.portWrite(address.bit(0,1), data); } -auto CPU::writeCPU(uint24 address, uint8 data) -> void { - switch((uint16)address) { +auto CPU::writeCPU(n24 address, n8 data) -> void { + switch((n16)address) { case 0x2180: //WMDATA return bus.write(0x7e0000 | io.wramAddress++, data); @@ -192,12 +192,12 @@ auto CPU::writeCPU(uint24 address, uint8 data) -> void { return; case 0x420b: //DMAEN - for(uint n : range(8)) channels[n].dmaEnable = data.bit(n); + for(u32 n : range(8)) channels[n].dmaEnable = data.bit(n); if(data) status.dmaPending = true; return; case 0x420c: //HDMAEN - for(uint n : range(8)) channels[n].hdmaEnable = data.bit(n); + for(u32 n : range(8)) channels[n].hdmaEnable = data.bit(n); return; case 0x420d: //MEMSEL @@ -207,7 +207,7 @@ auto CPU::writeCPU(uint24 address, uint8 data) -> void { } } -auto CPU::writeDMA(uint24 address, uint8 data) -> void { +auto CPU::writeDMA(n24 address, n8 data) -> void { auto& channel = this->channels[address.bit(4,6)]; switch(address & 0xff8f) { diff --git a/ares/sfc/cpu/irq.cpp b/ares/sfc/cpu/irq.cpp index 541cf34e89..bed7b199a1 100644 --- a/ares/sfc/cpu/irq.cpp +++ b/ares/sfc/cpu/irq.cpp @@ -30,7 +30,7 @@ alwaysinline auto CPU::irqPoll() -> void { )) status.irqLine = status.irqHold = 1; //hold /IRQ for four cycles } -auto CPU::nmitimenUpdate(uint8 data) -> void { +auto CPU::nmitimenUpdate(n8 data) -> void { io.hirqEnable = data.bit(4); io.virqEnable = data.bit(5); io.irqEnable = io.hirqEnable || io.virqEnable; diff --git a/ares/sfc/cpu/memory.cpp b/ares/sfc/cpu/memory.cpp index c927a8ae51..d42401e8d1 100644 --- a/ares/sfc/cpu/memory.cpp +++ b/ares/sfc/cpu/memory.cpp @@ -5,7 +5,7 @@ auto CPU::idle() -> void { aluEdge(); } -auto CPU::read(uint24 address) -> uint8 { +auto CPU::read(n24 address) -> n8 { status.clockCount = wait(address); dmaEdge(); r.mar = address; @@ -18,7 +18,7 @@ auto CPU::read(uint24 address) -> uint8 { return data; } -auto CPU::write(uint24 address, uint8 data) -> void { +auto CPU::write(n24 address, n8 data) -> void { aluEdge(); status.clockCount = wait(address); dmaEdge(); @@ -27,7 +27,7 @@ auto CPU::write(uint24 address, uint8 data) -> void { bus.write(address, r.mdr = data); } -alwaysinline auto CPU::wait(uint24 address) const -> uint { +alwaysinline auto CPU::wait(n24 address) const -> u32 { //00-3f,80-bf:8000-ffff; 40-7f,c0-ff:0000-ffff if(address & 0x408000) return address & 0x800000 ? io.romSpeed : 8; @@ -41,6 +41,6 @@ alwaysinline auto CPU::wait(uint24 address) const -> uint { return 12; } -auto CPU::readDisassembler(uint24 address) -> uint8 { +auto CPU::readDisassembler(n24 address) -> n8 { return bus.read(address, r.mdr); } diff --git a/ares/sfc/cpu/timing.cpp b/ares/sfc/cpu/timing.cpp index 82ebfb0a3a..85c796150f 100644 --- a/ares/sfc/cpu/timing.cpp +++ b/ares/sfc/cpu/timing.cpp @@ -1,16 +1,16 @@ //DMA clock divider -inline auto CPU::dmaCounter() const -> uint { +inline auto CPU::dmaCounter() const -> u32 { return counter.cpu & 7; } //joypad auto-poll clock divider -inline auto CPU::joypadCounter() const -> uint { +inline auto CPU::joypadCounter() const -> u32 { return counter.cpu & 127; } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { status.irqLock = 0; - uint ticks = clocks >> 1; + u32 ticks = clocks >> 1; while(ticks--) { counter.cpu += 2; tick(); @@ -169,8 +169,8 @@ alwaysinline auto CPU::joypadEdge() -> void { if(status.autoJoypadCounter >= 2 && !(status.autoJoypadCounter & 1)) { //sixteen bits are shifted into joy{1-4}, one bit per 256 clocks - uint2 port0 = controllerPort1.data(); - uint2 port1 = controllerPort2.data(); + n2 port0 = controllerPort1.data(); + n2 port1 = controllerPort2.data(); io.joy1 = io.joy1 << 1 | port0.bit(0); io.joy2 = io.joy2 << 1 | port1.bit(0); diff --git a/ares/sfc/dsp/brr.cpp b/ares/sfc/dsp/brr.cpp index 60694a924a..4438921609 100644 --- a/ares/sfc/dsp/brr.cpp +++ b/ares/sfc/dsp/brr.cpp @@ -1,15 +1,15 @@ auto DSP::brrDecode(Voice& v) -> void { //brr._byte = apuram[v.brrAddress + v.brrOffset] cached from previous clock cycle - int nybbles = brr._byte << 8 | apuram[uint16(v.brrAddress + v.brrOffset + 1)]; + s32 nybbles = brr._byte << 8 | apuram[n16(v.brrAddress + v.brrOffset + 1)]; - const int filter = brr._header.bit(2,3); - const int scale = brr._header.bit(4,7); + const s32 filter = brr._header.bit(2,3); + const s32 scale = brr._header.bit(4,7); //decode four samples - for(uint n : range(4)) { + for(u32 n : range(4)) { //bits 12-15 = current nybble; sign extend, then shift right to 4-bit precision //result: s = 4-bit sign-extended sample value - int s = (int16)nybbles >> 12; + s32 s = (i16)nybbles >> 12; nybbles <<= 4; //slide nybble so that on next loop iteration, bits 12-15 = current nybble if(scale <= 12) { @@ -20,9 +20,9 @@ auto DSP::brrDecode(Voice& v) -> void { } //apply IIR filter (2 is the most commonly used) - int offset = v.bufferOffset; - if(--offset < 0) offset = 11; const int p1 = v.buffer[offset]; - if(--offset < 0) offset = 11; const int p2 = v.buffer[offset] >> 1; + s32 offset = v.bufferOffset; + if(--offset < 0) offset = 11; const s32 p1 = v.buffer[offset]; + if(--offset < 0) offset = 11; const s32 p2 = v.buffer[offset] >> 1; switch(filter) { case 0: @@ -53,7 +53,7 @@ auto DSP::brrDecode(Voice& v) -> void { //adjust and write sample (mirror the written sample for wrapping) s = sclamp<16>(s); - s = (int16)(s << 1); + s = (i16)(s << 1); v.buffer[v.bufferOffset] = s; if(++v.bufferOffset >= 12) v.bufferOffset = 0; } diff --git a/ares/sfc/dsp/counter.cpp b/ares/sfc/dsp/counter.cpp index 5712336134..e167a2dca4 100644 --- a/ares/sfc/dsp/counter.cpp +++ b/ares/sfc/dsp/counter.cpp @@ -2,7 +2,7 @@ //all rates are evenly divisible by counter_range (0x7800, 30720, or 2048 * 5 * 3) //note that rate[0] is a special case, which never triggers -const uint16 DSP::CounterRate[32] = { +const n16 DSP::CounterRate[32] = { 0, 2048, 1536, 1280, 1024, 768, 640, 512, 384, @@ -20,7 +20,7 @@ const uint16 DSP::CounterRate[32] = { //counter offset from zero //counters do not appear to be aligned at zero for all rates -const uint16 DSP::CounterOffset[32] = { +const n16 DSP::CounterOffset[32] = { 0, 0, 1040, 536, 0, 1040, 536, 0, 1040, @@ -42,7 +42,7 @@ inline auto DSP::counterTick() -> void { //return true if counter event should trigger -inline auto DSP::counterPoll(uint rate) -> bool { +inline auto DSP::counterPoll(u32 rate) -> bool { if(rate == 0) return false; return (clock.counter + CounterOffset[rate]) % CounterRate[rate] == 0; } diff --git a/ares/sfc/dsp/debugger.cpp b/ares/sfc/dsp/debugger.cpp index 9844d64b0f..f14877b3d7 100644 --- a/ares/sfc/dsp/debugger.cpp +++ b/ares/sfc/dsp/debugger.cpp @@ -2,9 +2,9 @@ auto DSP::Debugger::load(Node::Object parent) -> void { memory.ram = parent->append("APU RAM"); memory.ram->setSize(64_KiB); memory.ram->setRead([&](u32 address) -> u8 { - return dsp.apuram[uint16(address)]; + return dsp.apuram[n16(address)]; }); memory.ram->setWrite([&](u32 address, u8 data) -> void { - dsp.apuram[uint16(address)] = data; + dsp.apuram[n16(address)] = data; }); } diff --git a/ares/sfc/dsp/dsp.cpp b/ares/sfc/dsp/dsp.cpp index f7eddde35b..cf0277c7e8 100644 --- a/ares/sfc/dsp/dsp.cpp +++ b/ares/sfc/dsp/dsp.cpp @@ -188,7 +188,7 @@ auto DSP::tick() -> void { Thread::synchronize(smp); } -auto DSP::sample(int16 left, int16 right) -> void { +auto DSP::sample(i16 left, i16 right) -> void { stream->frame(left / 32768.0, right / 32768.0); } @@ -205,7 +205,7 @@ auto DSP::power(bool reset) -> void { noise = {}; brr = {}; latch = {}; - for(uint n : range(8)) { + for(u32 n : range(8)) { voice[n] = {}; voice[n].index = n << 4; } diff --git a/ares/sfc/dsp/dsp.hpp b/ares/sfc/dsp/dsp.hpp index 149ef0278d..a0914841c8 100644 --- a/ares/sfc/dsp/dsp.hpp +++ b/ares/sfc/dsp/dsp.hpp @@ -13,8 +13,8 @@ struct DSP : Thread { } memory; } debugger; - uint8 apuram[64 * 1024]; - uint8 registers[128]; + n8 apuram[64_KiB]; + n8 registers[128]; auto mute() const -> bool { return master.mute; } @@ -26,14 +26,14 @@ struct DSP : Thread { auto power(bool reset) -> void; //memory.cpp - auto read(uint7 address) -> uint8; - auto write(uint7 address, uint8 data) -> void; + auto read(n7 address) -> n8; + auto write(n7 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; private: - struct Envelope { enum : uint { + struct Envelope { enum : u32 { Release, Attack, Decay, @@ -41,111 +41,111 @@ struct DSP : Thread { };}; struct Clock { - uint15 counter; - uint1 sample = 1; + n15 counter; + n1 sample = 1; } clock; struct Master { - uint1 reset = 1; - uint1 mute = 1; - int8 volume[2]; - int17 output[2]; + n1 reset = 1; + n1 mute = 1; + i8 volume[2]; + i17 output[2]; } master; struct Echo { - int8 feedback; - int8 volume[2]; - int8 fir[8]; - int16 history[2][8]; - uint8 bank; - uint4 delay; - uint1 readonly = 1; - int17 input[2]; - int17 output[2]; - - uint8 _bank; - uint1 _readonly; - uint16 _address; - uint16 _offset; //offset from ESA into echo buffer - uint16 _length; //number of bytes that echo offset will stop at - uint3 _historyOffset; + i8 feedback; + i8 volume[2]; + i8 fir[8]; + i16 history[2][8]; + n8 bank; + n4 delay; + n1 readonly = 1; + i17 input[2]; + i17 output[2]; + + n8 _bank; + n1 _readonly; + n16 _address; + n16 _offset; //offset from ESA into echo buffer + n16 _length; //number of bytes that echo offset will stop at + n3 _historyOffset; } echo; struct Noise { - uint5 frequency; - uint15 lfsr = 0x4000; + n5 frequency; + n15 lfsr = 0x4000; } noise; struct BRR { - uint8 bank; - - uint8 _bank; - uint8 _source; - uint16 _address; - uint16 _nextAddress; - uint8 _header; - uint8 _byte; + n8 bank; + + n8 _bank; + n8 _source; + n16 _address; + n16 _nextAddress; + n8 _header; + n8 _byte; } brr; struct Latch { - uint8 adsr0; - uint8 envx; - uint8 outx; - uint15 pitch; - int16 output; + n8 adsr0; + n8 envx; + n8 outx; + n15 pitch; + i16 output; } latch; struct Voice { //serialization.cpp auto serialize(serializer&) -> void; - uint7 index; //voice channel register index: 0x00 for voice 0, 0x10 for voice 1, etc - - int8 volume[2]; - uint14 pitch; - uint8 source; - uint8 adsr0; - uint8 adsr1; - uint8 gain; - uint8 envx; - uint1 keyon; - uint1 keyoff; - uint1 modulate; //0 = normal, 1 = modulate by previous voice pitch - uint1 noise; //0 = BRR, 1 = noise - uint1 echo; //0 = direct, 1 = echo - uint1 end; //0 = keyed on, 1 = BRR end bit encountered - - int16 buffer[12]; //12 decoded samples (mirrored for wrapping) - uint4 bufferOffset; //place in buffer where next samples will be decoded - uint16 gaussianOffset; //relative fractional position in sample (0x1000 = 1.0) - uint16 brrAddress; //address of current BRR block - uint4 brrOffset = 1; //current decoding offset in BRR block (1-8) - uint3 keyonDelay; //KON delay/current setup phase - uint2 envelopeMode; - uint11 envelope; //current envelope level (0-2047) + n7 index; //voice channel register index: 0x00 for voice 0, 0x10 for voice 1, etc + + i8 volume[2]; + n14 pitch; + n8 source; + n8 adsr0; + n8 adsr1; + n8 gain; + n8 envx; + n1 keyon; + n1 keyoff; + n1 modulate; //0 = normal, 1 = modulate by previous voice pitch + n1 noise; //0 = BRR, 1 = noise + n1 echo; //0 = direct, 1 = echo + n1 end; //0 = keyed on, 1 = BRR end bit encountered + + i16 buffer[12]; //12 decoded samples (mirrored for wrapping) + n4 bufferOffset; //place in buffer where next samples will be decoded + n16 gaussianOffset; //relative fractional position in sample (0x1000 = 1.0) + n16 brrAddress; //address of current BRR block + n4 brrOffset = 1; //current decoding offset in BRR block (1-8) + n3 keyonDelay; //KON delay/current setup phase + n2 envelopeMode; + n11 envelope; //current envelope level (0-2047) //internal latches - int32 _envelope; //used by GAIN mode 7, very obscure quirk - uint1 _keylatch; - uint1 _keyon; - uint1 _keyoff; - uint1 _modulate; - uint1 _noise; - uint1 _echo; - uint1 _end; - uint1 _looped; + i32 _envelope; //used by GAIN mode 7, very obscure quirk + n1 _keylatch; + n1 _keyon; + n1 _keyoff; + n1 _modulate; + n1 _noise; + n1 _echo; + n1 _end; + n1 _looped; } voice[8]; //gaussian.cpp - int16 gaussianTable[512]; + i16 gaussianTable[512]; auto gaussianConstructTable() -> void; - auto gaussianInterpolate(const Voice& v) -> int; + auto gaussianInterpolate(const Voice& v) -> s32; //counter.cpp - static const uint16 CounterRate[32]; - static const uint16 CounterOffset[32]; + static const n16 CounterRate[32]; + static const n16 CounterOffset[32]; auto counterTick() -> void; - auto counterPoll(uint rate) -> bool; + auto counterPoll(u32 rate) -> bool; //envelope.cpp auto envelopeRun(Voice& v) -> void; @@ -160,7 +160,7 @@ struct DSP : Thread { auto misc30() -> void; //voice.cpp - auto voiceOutput(Voice& v, uint1 channel) -> void; + auto voiceOutput(Voice& v, n1 channel) -> void; auto voice1 (Voice& v) -> void; auto voice2 (Voice& v) -> void; auto voice3 (Voice& v) -> void; @@ -175,10 +175,10 @@ struct DSP : Thread { auto voice9 (Voice& v) -> void; //echo.cpp - auto calculateFIR(uint1 channel, int index) -> int; - auto echoOutput(uint1 channel) const -> int16; - auto echoRead(uint1 channel) -> void; - auto echoWrite(uint1 channel) -> void; + auto calculateFIR(n1 channel, s32 index) -> s32; + auto echoOutput(n1 channel) const -> i16; + auto echoRead(n1 channel) -> void; + auto echoWrite(n1 channel) -> void; auto echo22() -> void; auto echo23() -> void; auto echo24() -> void; @@ -191,7 +191,7 @@ struct DSP : Thread { //dsp.cpp auto tick() -> void; - auto sample(int16 left, int16 right) -> void; + auto sample(i16 left, i16 right) -> void; }; extern DSP dsp; diff --git a/ares/sfc/dsp/echo.cpp b/ares/sfc/dsp/echo.cpp index 3e36908ad3..cf75928df6 100644 --- a/ares/sfc/dsp/echo.cpp +++ b/ares/sfc/dsp/echo.cpp @@ -1,25 +1,25 @@ -auto DSP::calculateFIR(uint1 channel, int index) -> int { - int sample = echo.history[channel][(uint3)(echo._historyOffset + index + 1)]; +auto DSP::calculateFIR(n1 channel, s32 index) -> s32 { + s32 sample = echo.history[channel][(n3)(echo._historyOffset + index + 1)]; return (sample * echo.fir[index]) >> 6; } -auto DSP::echoOutput(uint1 channel) const -> int16 { - int16 masterOutput = master.output[channel] * master.volume[channel] >> 7; - int16 echoOutput = echo.input[channel] * echo.volume[channel] >> 7; +auto DSP::echoOutput(n1 channel) const -> i16 { + i16 masterOutput = master.output[channel] * master.volume[channel] >> 7; + i16 echoOutput = echo.input[channel] * echo.volume[channel] >> 7; return sclamp<16>(masterOutput + echoOutput); } -auto DSP::echoRead(uint1 channel) -> void { - uint16 address = echo._address + channel * 2; - uint8 lo = apuram[address++]; - uint8 hi = apuram[address++]; - int s = (int16)((hi << 8) + lo); +auto DSP::echoRead(n1 channel) -> void { + n16 address = echo._address + channel * 2; + n8 lo = apuram[address++]; + n8 hi = apuram[address++]; + s32 s = (i16)((hi << 8) + lo); echo.history[channel][echo._historyOffset] = s >> 1; } -auto DSP::echoWrite(uint1 channel) -> void { +auto DSP::echoWrite(n1 channel) -> void { if(!echo._readonly) { - uint16 address = echo._address + channel * 2; + n16 address = echo._address + channel * 2; auto sample = echo.output[channel]; apuram[address++] = sample.byte(0); apuram[address++] = sample.byte(1); @@ -35,16 +35,16 @@ auto DSP::echo22() -> void { echoRead(0); //FIR - int l = calculateFIR(0, 0); - int r = calculateFIR(1, 0); + s32 l = calculateFIR(0, 0); + s32 r = calculateFIR(1, 0); echo.input[0] = l; echo.input[1] = r; } auto DSP::echo23() -> void { - int l = calculateFIR(0, 1) + calculateFIR(0, 2); - int r = calculateFIR(1, 1) + calculateFIR(1, 2); + s32 l = calculateFIR(0, 1) + calculateFIR(0, 2); + s32 r = calculateFIR(1, 1) + calculateFIR(1, 2); echo.input[0] += l; echo.input[1] += r; @@ -53,22 +53,22 @@ auto DSP::echo23() -> void { } auto DSP::echo24() -> void { - int l = calculateFIR(0, 3) + calculateFIR(0, 4) + calculateFIR(0, 5); - int r = calculateFIR(1, 3) + calculateFIR(1, 4) + calculateFIR(1, 5); + s32 l = calculateFIR(0, 3) + calculateFIR(0, 4) + calculateFIR(0, 5); + s32 r = calculateFIR(1, 3) + calculateFIR(1, 4) + calculateFIR(1, 5); echo.input[0] += l; echo.input[1] += r; } auto DSP::echo25() -> void { - int l = echo.input[0] + calculateFIR(0, 6); - int r = echo.input[1] + calculateFIR(1, 6); + s32 l = echo.input[0] + calculateFIR(0, 6); + s32 r = echo.input[1] + calculateFIR(1, 6); - l = (int16)l; - r = (int16)r; + l = (i16)l; + r = (i16)r; - l += (int16)calculateFIR(0, 7); - r += (int16)calculateFIR(1, 7); + l += (i16)calculateFIR(0, 7); + r += (i16)calculateFIR(1, 7); echo.input[0] = sclamp<16>(l) & ~1; echo.input[1] = sclamp<16>(r) & ~1; @@ -80,16 +80,16 @@ auto DSP::echo26() -> void { master.output[0] = echoOutput(0); //echo feedback - int l = echo.output[0] + int16(echo.input[0] * echo.feedback >> 7); - int r = echo.output[1] + int16(echo.input[1] * echo.feedback >> 7); + s32 l = echo.output[0] + i16(echo.input[0] * echo.feedback >> 7); + s32 r = echo.output[1] + i16(echo.input[1] * echo.feedback >> 7); echo.output[0] = sclamp<16>(l) & ~1; echo.output[1] = sclamp<16>(r) & ~1; } auto DSP::echo27() -> void { - int outl = master.output[0]; - int outr = echoOutput(1); + s32 outl = master.output[0]; + s32 outr = echoOutput(1); master.output[0] = 0; master.output[1] = 0; diff --git a/ares/sfc/dsp/envelope.cpp b/ares/sfc/dsp/envelope.cpp index 0d6b19b080..82cd6e3820 100644 --- a/ares/sfc/dsp/envelope.cpp +++ b/ares/sfc/dsp/envelope.cpp @@ -1,5 +1,5 @@ auto DSP::envelopeRun(Voice& v) -> void { - int envelope = v.envelope; + s32 envelope = v.envelope; if(v.envelopeMode == Envelope::Release) { //60% envelope -= 0x8; @@ -8,8 +8,8 @@ auto DSP::envelopeRun(Voice& v) -> void { return; } - int rate; - int envelopeData = v.adsr1; + s32 rate; + s32 envelopeData = v.adsr1; if(latch.adsr0.bit(7)) { //99% ADSR if(v.envelopeMode >= Envelope::Decay) { //99% envelope--; @@ -24,7 +24,7 @@ auto DSP::envelopeRun(Voice& v) -> void { } } else { //GAIN envelopeData = v.gain; - int mode = envelopeData >> 5; + s32 mode = envelopeData >> 5; if(mode < 4) { //direct envelope = envelopeData << 4; rate = 31; @@ -37,7 +37,7 @@ auto DSP::envelopeRun(Voice& v) -> void { envelope -= envelope >> 8; } else { //6, 7: linear increase envelope += 0x20; - if(mode > 6 && (uint)v._envelope >= 0x600) { + if(mode > 6 && (u32)v._envelope >= 0x600) { envelope += 0x8 - 0x20; //7: two-slope linear increase } } @@ -50,8 +50,8 @@ auto DSP::envelopeRun(Voice& v) -> void { } v._envelope = envelope; - //uint cast because linear decrease underflowing also triggers this - if((uint)envelope > 0x7ff) { + //u32 cast because linear decrease underflowing also triggers this + if((u32)envelope > 0x7ff) { envelope = (envelope < 0 ? 0 : 0x7ff); if(v.envelopeMode == Envelope::Attack) v.envelopeMode = Envelope::Decay; } diff --git a/ares/sfc/dsp/gaussian.cpp b/ares/sfc/dsp/gaussian.cpp index af6892677e..7698978a5a 100644 --- a/ares/sfc/dsp/gaussian.cpp +++ b/ares/sfc/dsp/gaussian.cpp @@ -1,39 +1,39 @@ auto DSP::gaussianConstructTable() -> void { - double table[512]; - for(uint n : range(512)) { - double k = 0.5 + n; - double s = (sin(Math::Pi * k * 1.280 / 1024)); - double t = (cos(Math::Pi * k * 2.000 / 1023) - 1) * 0.50; - double u = (cos(Math::Pi * k * 4.000 / 1023) - 1) * 0.08; - double r = s * (t + u + 1.0) / k; + f64 table[512]; + for(u32 n : range(512)) { + f64 k = 0.5 + n; + f64 s = (sin(Math::Pi * k * 1.280 / 1024)); + f64 t = (cos(Math::Pi * k * 2.000 / 1023) - 1) * 0.50; + f64 u = (cos(Math::Pi * k * 4.000 / 1023) - 1) * 0.08; + f64 r = s * (t + u + 1.0) / k; table[511 - n] = r; } - for(uint phase : range(128)) { - double sum = 0.0; + for(u32 phase : range(128)) { + f64 sum = 0.0; sum += table[phase + 0]; sum += table[phase + 256]; sum += table[511 - phase]; sum += table[255 - phase]; - double scale = 2048.0 / sum; - gaussianTable[phase + 0] = int16(table[phase + 0] * scale + 0.5); - gaussianTable[phase + 256] = int16(table[phase + 256] * scale + 0.5); - gaussianTable[511 - phase] = int16(table[511 - phase] * scale + 0.5); - gaussianTable[255 - phase] = int16(table[255 - phase] * scale + 0.5); + f64 scale = 2048.0 / sum; + gaussianTable[phase + 0] = i16(table[phase + 0] * scale + 0.5); + gaussianTable[phase + 256] = i16(table[phase + 256] * scale + 0.5); + gaussianTable[511 - phase] = i16(table[511 - phase] * scale + 0.5); + gaussianTable[255 - phase] = i16(table[255 - phase] * scale + 0.5); } } -auto DSP::gaussianInterpolate(const Voice& v) -> int { +auto DSP::gaussianInterpolate(const Voice& v) -> s32 { //make pointers into gaussian table based on fractional position between samples - uint8 offset = v.gaussianOffset >> 4; - const int16* forward = gaussianTable + 255 - offset; - const int16* reverse = gaussianTable + offset; //mirror left half of gaussian table + n8 offset = v.gaussianOffset >> 4; + const i16* forward = gaussianTable + 255 - offset; + const i16* reverse = gaussianTable + offset; //mirror left half of gaussian table offset = (v.bufferOffset + (v.gaussianOffset >> 12)) % 12; - int output; + s32 output; output = forward[ 0] * v.buffer[offset] >> 11; if(++offset >= 12) offset = 0; output += forward[256] * v.buffer[offset] >> 11; if(++offset >= 12) offset = 0; output += reverse[256] * v.buffer[offset] >> 11; if(++offset >= 12) offset = 0; - output = int16(output); + output = i16(output); output += reverse[ 0] * v.buffer[offset] >> 11; return sclamp<16>(output) & ~1; } diff --git a/ares/sfc/dsp/memory.cpp b/ares/sfc/dsp/memory.cpp index 9b9ca2f97e..667f29a3d7 100644 --- a/ares/sfc/dsp/memory.cpp +++ b/ares/sfc/dsp/memory.cpp @@ -1,8 +1,8 @@ -auto DSP::read(uint7 address) -> uint8 { +auto DSP::read(n7 address) -> n8 { return registers[address]; } -auto DSP::write(uint7 address, uint8 data) -> void { +auto DSP::write(n7 address, n8 data) -> void { registers[address] = data; switch(address) { @@ -19,11 +19,11 @@ auto DSP::write(uint7 address, uint8 data) -> void { echo.volume[1] = data; break; case 0x4c: //KON - for(uint n : range(8)) voice[n].keyon = data.bit(n); - for(uint n : range(8)) voice[n]._keylatch = data.bit(n); + for(u32 n : range(8)) voice[n].keyon = data.bit(n); + for(u32 n : range(8)) voice[n]._keylatch = data.bit(n); break; case 0x5c: //KOFF - for(uint n : range(8)) voice[n].keyoff = data.bit(n); + for(u32 n : range(8)) voice[n].keyoff = data.bit(n); break; case 0x6c: //FLG noise.frequency = data.bit(0,4); @@ -32,21 +32,21 @@ auto DSP::write(uint7 address, uint8 data) -> void { master.reset = data.bit(7); break; case 0x7c: //ENDX - for(uint n : range(8)) voice[n]._end = 0; + for(u32 n : range(8)) voice[n]._end = 0; registers[0x7c] = 0; //always cleared, regardless of data written break; case 0x0d: //EFB echo.feedback = data; break; case 0x2d: //PMON - for(uint n : range(8)) voice[n].modulate = data.bit(n); + for(u32 n : range(8)) voice[n].modulate = data.bit(n); voice[0].modulate = 0; //voice 0 does not support modulation break; case 0x3d: //NON - for(uint n : range(8)) voice[n].noise = data.bit(n); + for(u32 n : range(8)) voice[n].noise = data.bit(n); break; case 0x4d: //EON - for(uint n : range(8)) voice[n].echo = data.bit(n); + for(u32 n : range(8)) voice[n].echo = data.bit(n); break; case 0x5d: //DIR brr.bank = data; @@ -59,8 +59,8 @@ auto DSP::write(uint7 address, uint8 data) -> void { break; } - uint4 n = address.bit(4,6); - switch((uint4)address) { + n3 n = address.bit(4,6); + switch((n4)address) { case 0x00: //VxVOLL voice[n].volume[0] = data; break; diff --git a/ares/sfc/dsp/misc.cpp b/ares/sfc/dsp/misc.cpp index f80aa807b7..32690c8b57 100644 --- a/ares/sfc/dsp/misc.cpp +++ b/ares/sfc/dsp/misc.cpp @@ -23,7 +23,7 @@ auto DSP::misc30() -> void { //noise if(counterPoll(noise.frequency)) { - int feedback = noise.lfsr << 13 ^ noise.lfsr << 14; + s32 feedback = noise.lfsr << 13 ^ noise.lfsr << 14; noise.lfsr = feedback & 0x4000 ^ noise.lfsr >> 1; } } diff --git a/ares/sfc/dsp/voice.cpp b/ares/sfc/dsp/voice.cpp index 132dfd0477..2226e467c0 100644 --- a/ares/sfc/dsp/voice.cpp +++ b/ares/sfc/dsp/voice.cpp @@ -1,6 +1,6 @@ -inline auto DSP::voiceOutput(Voice& v, uint1 channel) -> void { +inline auto DSP::voiceOutput(Voice& v, n1 channel) -> void { //apply left/right volume - int amp = latch.output * v.volume[channel] >> 7; + s32 amp = latch.output * v.volume[channel] >> 7; //add to output total master.output[channel] += amp; @@ -20,7 +20,7 @@ auto DSP::voice1(Voice& v) -> void { auto DSP::voice2(Voice& v) -> void { //read sample pointer (ignored if not needed) - uint16 address = brr._address; + n16 address = brr._address; if(!v.keyonDelay) address += 2; brr._nextAddress.byte(0) = apuram[address++]; brr._nextAddress.byte(1) = apuram[address++]; @@ -41,8 +41,8 @@ auto DSP::voice3a(Voice& v) -> void { } auto DSP::voice3b(Voice& v) -> void { - brr._byte = apuram[uint16(v.brrAddress + v.brrOffset)]; - brr._header = apuram[uint16(v.brrAddress)]; + brr._byte = apuram[n16(v.brrAddress + v.brrOffset)]; + brr._header = apuram[n16(v.brrAddress)]; } auto DSP::voice3c(Voice& v) -> void { @@ -75,11 +75,11 @@ auto DSP::voice3c(Voice& v) -> void { } //gaussian interpolation - int output = gaussianInterpolate(v); + s32 output = gaussianInterpolate(v); //noise if(v._noise) { - output = (int16)(noise.lfsr << 1); + output = (i16)(noise.lfsr << 1); } //apply envelope @@ -117,7 +117,7 @@ auto DSP::voice4(Voice& v) -> void { v.brrOffset += 2; if(v.brrOffset >= 9) { //start decoding next BRR block - v.brrAddress = uint16(v.brrAddress + 9); + v.brrAddress = n16(v.brrAddress + 9); if(brr._header.bit(0)) { v.brrAddress = brr._nextAddress; v._looped = 1; @@ -152,7 +152,7 @@ auto DSP::voice6(Voice& v) -> void { } auto DSP::voice7(Voice& v) -> void { - for(uint n : range(8)) registers[0x7c].bit(n) = voice[n]._end; + for(u32 n : range(8)) registers[0x7c].bit(n) = voice[n]._end; latch.envx = v.envx; } diff --git a/ares/sfc/expansion/21fx/21fx.cpp b/ares/sfc/expansion/21fx/21fx.cpp index 68f9972cf2..c5ce788f6d 100644 --- a/ares/sfc/expansion/21fx/21fx.cpp +++ b/ares/sfc/expansion/21fx/21fx.cpp @@ -24,7 +24,7 @@ S21FX::S21FX(Node::Port parent) { //there's not really much choice but to copy the library to a temporary directory here if(auto fp = platform->open(node, "21fx.so", File::Read, File::Required)) { if(auto buffer = file::open({Path::temporary(), "21fx.so"}, file::mode::write)) { - for(uint index : range(fp->size())) buffer.write(fp->read()); + for(u32 index : range(fp->size())) buffer.write(fp->read()); } } @@ -46,10 +46,10 @@ S21FX::~S21FX() { //the downside is that if 00:fffc-fffd were anything but ROM; it will now only act as ROM //given that this is the only device that hooks the reset vector like this, //it's not worth the added complexity to support some form of reversible bus mapping hooks - uint vector = resetVector; - bus.map([vector](uint24 addr, uint8) -> uint8 { + u32 vector = resetVector; + bus.map([vector](n24 addr, n8) -> n8 { return vector >> addr * 8; - }, [](uint24, uint8) -> void { + }, [](n24, n8) -> void { }, "00:fffc-fffd", 2); if(link.open()) link.close(); @@ -57,7 +57,7 @@ S21FX::~S21FX() { linkMain.reset(); } -auto S21FX::step(uint clocks) -> void { +auto S21FX::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); } @@ -75,7 +75,7 @@ auto S21FX::main() -> void { while(true) scheduler.synchronize(), step(10'000'000); } -auto S21FX::read(uint24 address, uint8 data) -> uint8 { +auto S21FX::read(n24 address, n8 data) -> n8 { address &= 0x40ffff; if(address == 0xfffc) return booted ? resetVector >> 0 : (0x84); @@ -98,7 +98,7 @@ auto S21FX::read(uint24 address, uint8 data) -> uint8 { return data; } -auto S21FX::write(uint24 address, uint8 data) -> void { +auto S21FX::write(n24 address, n8 data) -> void { address &= 0x40ffff; if(address == 0x21ff) { @@ -113,7 +113,7 @@ auto S21FX::quit() -> bool { return false; } -auto S21FX::usleep(uint microseconds) -> void { +auto S21FX::usleep(u32 microseconds) -> void { step(10 * microseconds); } @@ -128,7 +128,7 @@ auto S21FX::writable() -> bool { } //SNES -> Link -auto S21FX::read() -> uint8 { +auto S21FX::read() -> n8 { step(1); if(snesBuffer.size() > 0) { return snesBuffer.takeLeft(); @@ -137,7 +137,7 @@ auto S21FX::read() -> uint8 { } //Link -> SNES -auto S21FX::write(uint8 data) -> void { +auto S21FX::write(n8 data) -> void { step(1); if(linkBuffer.size() < 1024) { linkBuffer.append(data); diff --git a/ares/sfc/expansion/21fx/21fx.hpp b/ares/sfc/expansion/21fx/21fx.hpp index ecdad11b55..b8e9f4fb93 100644 --- a/ares/sfc/expansion/21fx/21fx.hpp +++ b/ares/sfc/expansion/21fx/21fx.hpp @@ -2,35 +2,35 @@ struct S21FX : Expansion { S21FX(Node::Port); ~S21FX(); - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto main() -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; private: auto quit() -> bool; - auto usleep(uint) -> void; + auto usleep(u32) -> void; auto readable() -> bool; auto writable() -> bool; - auto read() -> uint8; - auto write(uint8) -> void; + auto read() -> n8; + auto write(n8) -> void; - bool booted = false; - uint16 resetVector; - uint8 ram[122]; + n1 booted; + n16 resetVector; + n8 ram[122]; nall::library link; function, //quit - function, //usleep - function, //readable - function, //writable - function, //read - function //write + function, //quit + function, //usleep + function, //readable + function, //writable + function, //read + function //write )> linkInit; function)> linkMain; - vector snesBuffer; //SNES -> Link - vector linkBuffer; //Link -> SNES + vector snesBuffer; //SNES -> Link + vector linkBuffer; //Link -> SNES }; diff --git a/ares/sfc/expansion/satellaview/satellaview.cpp b/ares/sfc/expansion/satellaview/satellaview.cpp index 38dcf8eb33..4e87c57d06 100644 --- a/ares/sfc/expansion/satellaview/satellaview.cpp +++ b/ares/sfc/expansion/satellaview/satellaview.cpp @@ -9,7 +9,7 @@ Satellaview::~Satellaview() { bus.unmap("00-3f,80-bf:2188-219f"); } -auto Satellaview::read(uint24 addr, uint8 data) -> uint8 { +auto Satellaview::read(n24 addr, n8 data) -> n8 { switch(addr &= 0xffff) { case 0x2188: return regs.r2188; case 0x2189: return regs.r2189; @@ -20,7 +20,7 @@ auto Satellaview::read(uint24 addr, uint8 data) -> uint8 { case 0x2190: return regs.r2190; case 0x2192: { - uint counter = regs.rtcCounter++; + u32 counter = regs.rtcCounter++; if(regs.rtcCounter >= 18) regs.rtcCounter = 0; if(counter == 0) { @@ -65,7 +65,7 @@ auto Satellaview::read(uint24 addr, uint8 data) -> uint8 { return data; } -auto Satellaview::write(uint24 addr, uint8 data) -> void { +auto Satellaview::write(n24 addr, n8 data) -> void { switch(addr &= 0xffff) { case 0x2188: { regs.r2188 = data; diff --git a/ares/sfc/expansion/satellaview/satellaview.hpp b/ares/sfc/expansion/satellaview/satellaview.hpp index be8f4725df..3e3c38daae 100644 --- a/ares/sfc/expansion/satellaview/satellaview.hpp +++ b/ares/sfc/expansion/satellaview/satellaview.hpp @@ -2,21 +2,21 @@ struct Satellaview : Expansion { Satellaview(Node::Port); ~Satellaview(); - auto read(uint24 addr, uint8 data) -> uint8; - auto write(uint24 addr, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; private: struct { - uint8 r2188, r2189, r218a, r218b; - uint8 r218c, r218d, r218e, r218f; - uint8 r2190, r2191, r2192, r2193; - uint8 r2194, r2195, r2196, r2197; - uint8 r2198, r2199, r219a, r219b; - uint8 r219c, r219d, r219e, r219f; + n8 r2188, r2189, r218a, r218b; + n8 r218c, r218d, r218e, r218f; + n8 r2190, r2191, r2192, r2193; + n8 r2194, r2195, r2196, r2197; + n8 r2198, r2199, r219a, r219b; + n8 r219c, r219d, r219e, r219f; - uint8 rtcCounter; - uint8 rtcHour; - uint8 rtcMinute; - uint8 rtcSecond; + n8 rtcCounter; + n8 rtcHour; + n8 rtcMinute; + n8 rtcSecond; } regs; }; diff --git a/ares/sfc/memory/memory-inline.hpp b/ares/sfc/memory/memory-inline.hpp index 7df1caa142..253921c450 100644 --- a/ares/sfc/memory/memory-inline.hpp +++ b/ares/sfc/memory/memory-inline.hpp @@ -1,7 +1,7 @@ -alwaysinline auto Bus::mirror(uint address, uint size) -> uint { +alwaysinline auto Bus::mirror(u32 address, u32 size) -> u32 { if(size == 0) return 0; - uint base = 0; - uint mask = 1 << 23; + u32 base = 0; + u32 mask = 1 << 23; while(address >= size) { while(!(address & mask)) mask >>= 1; address -= mask; @@ -14,19 +14,19 @@ alwaysinline auto Bus::mirror(uint address, uint size) -> uint { return base + address; } -alwaysinline auto Bus::reduce(uint address, uint mask) -> uint { +alwaysinline auto Bus::reduce(u32 address, u32 mask) -> u32 { while(mask) { - uint bits = (mask & -mask) - 1; + u32 bits = (mask & -mask) - 1; address = (address >> 1 & ~bits) | address & bits; mask = (mask & mask - 1) >> 1; } return address; } -alwaysinline auto Bus::read(uint24 address, uint8 data) -> uint8 { +alwaysinline auto Bus::read(n24 address, n8 data) -> n8 { return reader[lookup[address]](target[address], data); } -alwaysinline auto Bus::write(uint24 address, uint8 data) -> void { +alwaysinline auto Bus::write(n24 address, n8 data) -> void { return writer[lookup[address]](target[address], data); } diff --git a/ares/sfc/memory/memory.cpp b/ares/sfc/memory/memory.cpp index ada6894013..c2c097171a 100644 --- a/ares/sfc/memory/memory.cpp +++ b/ares/sfc/memory/memory.cpp @@ -19,22 +19,22 @@ auto Bus::reset() -> void { if(lookup) delete[] lookup; if(target) delete[] target; - lookup = new uint8 [16 * 1024 * 1024](); - target = new uint32[16 * 1024 * 1024](); + lookup = new n8 [16_MiB](); + target = new n32[16_MiB](); - reader[0] = [](uint24, uint8 data) -> uint8 { return data; }; - writer[0] = [](uint24, uint8) -> void {}; + reader[0] = [](n24, n8 data) -> n8 { return data; }; + writer[0] = [](n24, n8) -> void {}; cpu.map(); ppu.map(); } auto Bus::map( - const function& read, - const function& write, - const string& addr, uint size, uint base, uint mask -) -> uint { - uint id = 1; + const function& read, + const function& write, + const string& addr, u32 size, u32 base, u32 mask +) -> u32 { + u32 id = 1; while(counter[id]) { if(++id >= 256) return print("SFC error: bus map exhausted\n"), 0; } @@ -49,20 +49,20 @@ auto Bus::map( for(auto& addr : addrs) { auto bankRange = bank.split("-", 1L); auto addrRange = addr.split("-", 1L); - uint bankLo = bankRange(0).hex(); - uint bankHi = bankRange(1, bankRange(0)).hex(); - uint addrLo = addrRange(0).hex(); - uint addrHi = addrRange(1, addrRange(0)).hex(); - - for(uint bank = bankLo; bank <= bankHi; bank++) { - for(uint addr = addrLo; addr <= addrHi; addr++) { - uint pid = lookup[bank << 16 | addr]; + u32 bankLo = bankRange(0).hex(); + u32 bankHi = bankRange(1, bankRange(0)).hex(); + u32 addrLo = addrRange(0).hex(); + u32 addrHi = addrRange(1, addrRange(0)).hex(); + + for(u32 bank = bankLo; bank <= bankHi; bank++) { + for(u32 addr = addrLo; addr <= addrHi; addr++) { + u32 pid = lookup[bank << 16 | addr]; if(pid && --counter[pid] == 0) { reader[pid].reset(); writer[pid].reset(); } - uint offset = reduce(bank << 16 | addr, mask); + u32 offset = reduce(bank << 16 | addr, mask); if(size) base = mirror(base, size); if(size) offset = base + mirror(offset, size - base); lookup[bank << 16 | addr] = id; @@ -84,14 +84,14 @@ auto Bus::unmap(const string& addr) -> void { for(auto& addr : addrs) { auto bankRange = bank.split("-", 1L); auto addrRange = addr.split("-", 1L); - uint bankLo = bankRange(0).hex(); - uint bankHi = bankRange(1, bankRange(0)).hex(); - uint addrLo = addrRange(0).hex(); - uint addrHi = addrRange(1, addrRange(1)).hex(); - - for(uint bank = bankLo; bank <= bankHi; bank++) { - for(uint addr = addrLo; addr <= addrHi; addr++) { - uint pid = lookup[bank << 16 | addr]; + u32 bankLo = bankRange(0).hex(); + u32 bankHi = bankRange(1, bankRange(0)).hex(); + u32 addrLo = addrRange(0).hex(); + u32 addrHi = addrRange(1, addrRange(1)).hex(); + + for(u32 bank = bankLo; bank <= bankHi; bank++) { + for(u32 addr = addrLo; addr <= addrHi; addr++) { + u32 pid = lookup[bank << 16 | addr]; if(pid && --counter[pid] == 0) { reader[pid].reset(); writer[pid].reset(); diff --git a/ares/sfc/memory/memory.hpp b/ares/sfc/memory/memory.hpp index f19adee0c9..6c870c64e7 100644 --- a/ares/sfc/memory/memory.hpp +++ b/ares/sfc/memory/memory.hpp @@ -3,18 +3,18 @@ struct AbstractMemory { explicit operator bool() const { return size() > 0; } virtual auto reset() -> void {} - virtual auto allocate(uint, uint8 = 0xff) -> void {} + virtual auto allocate(u32, n8 = 0xff) -> void {} virtual auto load(shared_pointer fp) -> void {} virtual auto save(shared_pointer fp) -> void {} - virtual auto data() -> uint8* = 0; - virtual auto size() const -> uint = 0; + virtual auto data() -> n8* = 0; + virtual auto size() const -> u32 = 0; - virtual auto read(uint24 address, uint8 data = 0) -> uint8 = 0; - virtual auto write(uint24 address, uint8 data) -> void = 0; + virtual auto read(n24 address, n8 data = 0) -> n8 = 0; + virtual auto write(n24 address, n8 data) -> void = 0; - uint id = 0; + u32 id = 0; }; #include "readable.hpp" @@ -22,29 +22,29 @@ struct AbstractMemory { #include "protectable.hpp" struct Bus { - static auto mirror(uint address, uint size) -> uint; - static auto reduce(uint address, uint mask) -> uint; + static auto mirror(u32 address, u32 size) -> u32; + static auto reduce(u32 address, u32 mask) -> u32; ~Bus(); - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; auto reset() -> void; auto map( - const function& read, - const function& write, - const string& address, uint size = 0, uint base = 0, uint mask = 0 - ) -> uint; + const function& read, + const function& write, + const string& address, u32 size = 0, u32 base = 0, u32 mask = 0 + ) -> u32; auto unmap(const string& address) -> void; private: - uint8* lookup = nullptr; - uint32* target = nullptr; + n8* lookup = nullptr; + n32* target = nullptr; - function reader[256]; - function writer[256]; - uint24 counter[256]; + function reader[256]; + function writer[256]; + n24 counter[256]; }; extern Bus bus; diff --git a/ares/sfc/memory/protectable.hpp b/ares/sfc/memory/protectable.hpp index 8b054c837c..a9f11f351e 100644 --- a/ares/sfc/memory/protectable.hpp +++ b/ares/sfc/memory/protectable.hpp @@ -5,25 +5,25 @@ struct ProtectableMemory : AbstractMemory { self.size = 0; } - auto allocate(uint size, uint8 fill = 0xff) -> void override { + auto allocate(u32 size, n8 fill = 0xff) -> void override { delete[] self.data; - self.data = new uint8[self.size = size]; - for(uint address : range(size)) self.data[address] = fill; + self.data = new n8[self.size = size]; + for(u32 address : range(size)) self.data[address] = fill; } - auto load(shared_pointer fp) -> void { + auto load(shared_pointer fp) -> void override { fp->read(self.data, min(fp->size(), self.size)); } - auto save(shared_pointer fp) -> void { + auto save(shared_pointer fp) -> void override { fp->write(self.data, self.size); } - auto data() -> uint8* override { + auto data() -> n8* override { return self.data; } - auto size() const -> uint override { + auto size() const -> u32 override { return self.size; } @@ -35,23 +35,23 @@ struct ProtectableMemory : AbstractMemory { self.writable = writable; } - auto read(uint24 address, uint8 data = 0) -> uint8 override { + auto read(n24 address, n8 data = 0) -> n8 override { return self.data[address]; } - auto write(uint24 address, uint8 data) -> void override { + auto write(n24 address, n8 data) -> void override { if(!self.writable) return; self.data[address] = data; } - auto operator[](uint24 address) const -> uint8 { + auto operator[](n24 address) const -> n8 { return self.data[address]; } private: struct { - uint8* data = nullptr; - uint size = 0; + n8* data = nullptr; + u32 size = 0; bool writable = false; } self; }; diff --git a/ares/sfc/memory/readable.hpp b/ares/sfc/memory/readable.hpp index e453c044ba..f09fa8a3d1 100644 --- a/ares/sfc/memory/readable.hpp +++ b/ares/sfc/memory/readable.hpp @@ -5,50 +5,50 @@ struct ReadableMemory : AbstractMemory { self.size = 0; } - auto allocate(uint size, uint8 fill = 0xff) -> void override { + auto allocate(u32 size, n8 fill = 0xff) -> void override { delete[] self.data; - self.data = new uint8[self.size = size]; - for(uint address : range(size)) self.data[address] = fill; + self.data = new n8[self.size = size]; + for(u32 address : range(size)) self.data[address] = fill; } - auto load(shared_pointer fp) -> void { + auto load(shared_pointer fp) -> void override { fp->read(self.data, min(fp->size(), self.size)); } - auto save(shared_pointer fp) -> void { + auto save(shared_pointer fp) -> void override { fp->write(self.data, self.size); } - auto data() -> uint8* override { + auto data() -> n8* override { return self.data; } - auto size() const -> uint override { + auto size() const -> u32 override { return self.size; } - auto read(uint24 address, uint8 data = 0) -> uint8 override { + auto read(n24 address, n8 data = 0) -> n8 override { return self.data[address]; } - auto write(uint24 address, uint8 data) -> void override { + auto write(n24 address, n8 data) -> void override { } - auto program(uint24 address, uint8 data) -> void { + auto program(n24 address, n8 data) -> void { self.data[address] = data; } - auto operator[](uint24 address) const -> uint8 { + auto operator[](n24 address) const -> n8 { return self.data[address]; } auto serialize(serializer& s) -> void { - s(array_span{self.data, self.size}); + s(array_span{self.data, self.size}); } private: struct { - uint8* data = nullptr; - uint size = 0; + n8* data = nullptr; + u32 size = 0; } self; }; diff --git a/ares/sfc/memory/writable.hpp b/ares/sfc/memory/writable.hpp index d59a4c2607..6d8e08bfcd 100644 --- a/ares/sfc/memory/writable.hpp +++ b/ares/sfc/memory/writable.hpp @@ -5,47 +5,47 @@ struct WritableMemory : AbstractMemory { self.size = 0; } - auto allocate(uint size, uint8 fill = 0xff) -> void override { + auto allocate(u32 size, n8 fill = 0xff) -> void override { delete[] self.data; - self.data = new uint8[self.size = size]; - for(uint address : range(size)) self.data[address] = fill; + self.data = new n8[self.size = size]; + for(u32 address : range(size)) self.data[address] = fill; } - auto load(shared_pointer fp) -> void { + auto load(shared_pointer fp) -> void override { fp->read(self.data, min(fp->size(), self.size)); } - auto save(shared_pointer fp) -> void { + auto save(shared_pointer fp) -> void override { fp->write(self.data, self.size); } - auto data() -> uint8* override { + auto data() -> n8* override { return self.data; } - auto size() const -> uint override { + auto size() const -> u32 override { return self.size; } - auto read(uint24 address, uint8 data = 0) -> uint8 override { + auto read(n24 address, n8 data = 0) -> n8 override { return self.data[address]; } - auto write(uint24 address, uint8 data) -> void override { + auto write(n24 address, n8 data) -> void override { self.data[address] = data; } - auto operator[](uint24 address) -> uint8& { + auto operator[](n24 address) -> n8& { return self.data[address]; } auto serialize(serializer& s) -> void { - s(array_span{self.data, self.size}); + s(array_span{self.data, self.size}); } private: struct { - uint8* data = nullptr; - uint size = 0; + n8* data = nullptr; + u32 size = 0; } self; }; diff --git a/ares/sfc/ppu-performance/background.cpp b/ares/sfc/ppu-performance/background.cpp index 95d2ada905..f3775ab8d3 100644 --- a/ares/sfc/ppu-performance/background.cpp +++ b/ares/sfc/ppu-performance/background.cpp @@ -11,23 +11,23 @@ auto PPU::Background::render() -> void { bool hires = ppu.io.bgMode == 5 || ppu.io.bgMode == 6; bool offsetPerTileMode = ppu.io.bgMode == 2 || ppu.io.bgMode == 4 || ppu.io.bgMode == 6; bool directColorMode = ppu.dac.io.directColor && id == ID::BG1 && (ppu.io.bgMode == 3 || ppu.io.bgMode == 4); - uint colorShift = 3 + io.mode; - int width = 256 << hires; + u32 colorShift = 3 + io.mode; + s32 width = 256 << hires; - uint tileHeight = 3 + io.tileSize; - uint tileWidth = !hires ? tileHeight : 4; - uint tileMask = 0x0fff >> io.mode; - uint tiledataIndex = io.tiledataAddress >> 3 + io.mode; + u32 tileHeight = 3 + io.tileSize; + u32 tileWidth = !hires ? tileHeight : 4; + u32 tileMask = 0x0fff >> io.mode; + u32 tiledataIndex = io.tiledataAddress >> 3 + io.mode; - uint paletteBase = ppu.io.bgMode == 0 ? id << 5 : 0; - uint paletteShift = 2 << io.mode; + u32 paletteBase = ppu.io.bgMode == 0 ? id << 5 : 0; + u32 paletteShift = 2 << io.mode; - uint hscroll = io.hoffset; - uint vscroll = io.voffset; - uint hmask = (width << io.tileSize << !!(io.screenSize & 1)) - 1; - uint vmask = (width << io.tileSize << !!(io.screenSize & 2)) - 1; + u32 hscroll = io.hoffset; + u32 vscroll = io.voffset; + u32 hmask = (width << io.tileSize << !!(io.screenSize & 1)) - 1; + u32 vmask = (width << io.tileSize << !!(io.screenSize & 2)) - 1; - uint y = ppu.vcounter(); + u32 y = ppu.vcounter(); if(hires) { hscroll <<= 1; if(ppu.io.interlace) y = y << 1 | (ppu.field() && !io.mosaicEnable); @@ -36,20 +36,20 @@ auto PPU::Background::render() -> void { y -= ppu.mosaic.voffset() << (hires && ppu.io.interlace); } - uint mosaicCounter = 1; - uint mosaicPalette = 0; - uint mosaicPriority = 0; - uint15 mosaicColor = 0; + u32 mosaicCounter = 1; + u32 mosaicPalette = 0; + u32 mosaicPriority = 0; + n15 mosaicColor = 0; - int x = 0 - (hscroll & 7); + s32 x = 0 - (hscroll & 7); while(x < width) { - uint hoffset = x + hscroll; - uint voffset = y + vscroll; + u32 hoffset = x + hscroll; + u32 voffset = y + vscroll; if(offsetPerTileMode) { - uint validBit = 0x2000 << id; - uint offsetX = x + (hscroll & 7); + u32 validBit = 0x2000 << id; + u32 offsetX = x + (hscroll & 7); if(offsetX >= 8) { //first column is exempt - uint hlookup = ppu.bg3.getTile((offsetX - 8) + (ppu.bg3.io.hoffset & ~7), ppu.bg3.io.voffset + 0); + u32 hlookup = ppu.bg3.getTile((offsetX - 8) + (ppu.bg3.io.hoffset & ~7), ppu.bg3.io.voffset + 0); if(ppu.io.bgMode == 4) { if(hlookup & validBit) { if(!(hlookup & 0x8000)) { @@ -59,7 +59,7 @@ auto PPU::Background::render() -> void { } } } else { - uint vlookup = ppu.bg3.getTile((offsetX - 8) + (ppu.bg3.io.hoffset & ~7), ppu.bg3.io.voffset + 8); + u32 vlookup = ppu.bg3.getTile((offsetX - 8) + (ppu.bg3.io.hoffset & ~7), ppu.bg3.io.voffset + 8); if(hlookup & validBit) { hoffset = offsetX + (hlookup & ~7); } @@ -72,30 +72,30 @@ auto PPU::Background::render() -> void { hoffset &= hmask; voffset &= vmask; - uint tileNumber = getTile(hoffset, voffset); - uint mirrorY = tileNumber & 0x8000 ? 7 : 0; - uint mirrorX = tileNumber & 0x4000 ? 7 : 0; - uint8 tilePriority = io.priority[bool(tileNumber & 0x2000)]; - uint paletteNumber = tileNumber >> 10 & 7; - uint paletteIndex = paletteBase + (paletteNumber << paletteShift) & 0xff; + u32 tileNumber = getTile(hoffset, voffset); + u32 mirrorY = tileNumber & 0x8000 ? 7 : 0; + u32 mirrorX = tileNumber & 0x4000 ? 7 : 0; + n8 tilePriority = io.priority[bool(tileNumber & 0x2000)]; + u32 paletteNumber = tileNumber >> 10 & 7; + u32 paletteIndex = paletteBase + (paletteNumber << paletteShift) & 0xff; if(tileWidth == 4 && (bool(hoffset & 8) ^ bool(mirrorX))) tileNumber += 1; if(tileHeight == 4 && (bool(voffset & 8) ^ bool(mirrorY))) tileNumber += 16; tileNumber = (tileNumber & 0x03ff) + tiledataIndex & tileMask; - uint16 address; + n16 address; address = (tileNumber << colorShift) + (voffset & 7 ^ mirrorY); - uint64 data; - data |= (uint64)ppu.vram[address + 0] << 0; - data |= (uint64)ppu.vram[address + 8] << 16; - data |= (uint64)ppu.vram[address + 16] << 32; - data |= (uint64)ppu.vram[address + 24] << 48; + n64 data; + data |= (n64)ppu.vram[address + 0] << 0; + data |= (n64)ppu.vram[address + 8] << 16; + data |= (n64)ppu.vram[address + 16] << 32; + data |= (n64)ppu.vram[address + 24] << 48; - for(uint tileX = 0; tileX < 8; tileX++, x++) { + for(u32 tileX = 0; tileX < 8; tileX++, x++) { if(x & width) continue; //x < 0 || x >= width if(--mosaicCounter == 0) { - uint color = 0, shift = mirrorX ? tileX : 7 - tileX; + u32 color = 0, shift = mirrorX ? tileX : 7 - tileX; /*if(io.mode >= Mode::BPP2)*/ { color += data >> shift + 0 & 1; color += data >> shift + 7 & 2; @@ -126,7 +126,7 @@ auto PPU::Background::render() -> void { if(io.aboveEnable && !windowAbove[x]) ppu.dac.plotAbove(x, id, mosaicPriority, mosaicColor); if(io.belowEnable && !windowBelow[x]) ppu.dac.plotBelow(x, id, mosaicPriority, mosaicColor); } else { - uint X = x >> 1; + u32 X = x >> 1; if(x & 1) { if(io.aboveEnable && !windowAbove[X]) ppu.dac.plotAbove(X, id, mosaicPriority, mosaicColor); } else { @@ -137,15 +137,15 @@ auto PPU::Background::render() -> void { } } -auto PPU::Background::getTile(uint hoffset, uint voffset) -> uint16 { +auto PPU::Background::getTile(u32 hoffset, u32 voffset) -> n16 { bool hires = ppu.io.bgMode == 5 || ppu.io.bgMode == 6; - uint tileHeight = 3 + io.tileSize; - uint tileWidth = !hires ? tileHeight : 4; - uint screenX = io.screenSize & 1 ? 32 << 5 : 0; - uint screenY = io.screenSize & 2 ? 32 << 5 + (io.screenSize & 1) : 0; - uint tileX = hoffset >> tileWidth; - uint tileY = voffset >> tileHeight; - uint offset = (tileY & 0x1f) << 5 | (tileX & 0x1f); + u32 tileHeight = 3 + io.tileSize; + u32 tileWidth = !hires ? tileHeight : 4; + u32 screenX = io.screenSize & 1 ? 32 << 5 : 0; + u32 screenY = io.screenSize & 2 ? 32 << 5 + (io.screenSize & 1) : 0; + u32 tileX = hoffset >> tileWidth; + u32 tileY = voffset >> tileHeight; + u32 offset = (tileY & 0x1f) << 5 | (tileX & 0x1f); if(tileX & 0x20) offset += screenX; if(tileY & 0x20) offset += screenY; return ppu.vram[io.screenAddress + offset]; diff --git a/ares/sfc/ppu-performance/background.hpp b/ares/sfc/ppu-performance/background.hpp index 51349e302a..51499ce8f7 100644 --- a/ares/sfc/ppu-performance/background.hpp +++ b/ares/sfc/ppu-performance/background.hpp @@ -1,13 +1,13 @@ struct Background { - struct ID { enum : uint { BG1, BG2, BG3, BG4 }; }; - struct Mode { enum : uint { BPP2, BPP4, BPP8, Mode7, Inactive }; }; + struct ID { enum : u32 { BG1, BG2, BG3, BG4 }; }; + struct Mode { enum : u32 { BPP2, BPP4, BPP8, Mode7, Inactive }; }; - const uint id; - Background(uint id) : id(id) {} + const u32 id; + Background(u32 id) : id(id) {} //background.cpp auto render() -> void; - auto getTile(uint hoffset, uint voffset) -> uint16; + auto getTile(u32 hoffset, u32 voffset) -> n16; auto power() -> void; //mode7.cpp @@ -17,21 +17,21 @@ struct Background { auto serialize(serializer&) -> void; struct IO { - uint2 screenSize; - uint16 screenAddress; + n2 screenSize; + n16 screenAddress; - uint16 tiledataAddress; - uint1 tileSize; + n16 tiledataAddress; + n1 tileSize; - uint16 hoffset; - uint16 voffset; + n16 hoffset; + n16 voffset; - uint1 aboveEnable; - uint1 belowEnable; - uint1 mosaicEnable; + n1 aboveEnable; + n1 belowEnable; + n1 mosaicEnable; - uint8 mode; - uint8 priority[2]; + n8 mode; + n8 priority[2]; } io; PPU::Window::Layer window; diff --git a/ares/sfc/ppu-performance/color.cpp b/ares/sfc/ppu-performance/color.cpp index 1a8795910f..de2b38c2a8 100644 --- a/ares/sfc/ppu-performance/color.cpp +++ b/ares/sfc/ppu-performance/color.cpp @@ -1,18 +1,18 @@ -auto PPU::color(uint32 color) -> uint64 { - uint r = color.bit( 0, 4); - uint g = color.bit( 5, 9); - uint b = color.bit(10,14); - uint l = color.bit(15,18); +auto PPU::color(n32 color) -> n64 { + n32 r = color.bit( 0, 4); + n32 g = color.bit( 5, 9); + n32 b = color.bit(10,14); + n32 l = color.bit(15,18); //luma=0 is not 100% black; but it's much darker than normal linear scaling. //exact effect seems to be analog; requires > 24-bit color depth to represent accurately. - double L = (1.0 + l) / 16.0 * (l ? 1.0 : 0.25); - uint64 R = L * image::normalize(r, 5, 16); - uint64 G = L * image::normalize(g, 5, 16); - uint64 B = L * image::normalize(b, 5, 16); + f64 L = (1.0 + l) / 16.0 * (l ? 1.0 : 0.25); + n64 R = L * image::normalize(r, 5, 16); + n64 G = L * image::normalize(g, 5, 16); + n64 B = L * image::normalize(b, 5, 16); if(colorEmulation->value()) { - static const uint8 gammaRamp[32] = { + static const n8 gammaRamp[32] = { 0x00, 0x01, 0x03, 0x06, 0x0a, 0x0f, 0x15, 0x1c, 0x24, 0x2d, 0x37, 0x42, 0x4e, 0x5b, 0x69, 0x78, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0, diff --git a/ares/sfc/ppu-performance/dac.cpp b/ares/sfc/ppu-performance/dac.cpp index c7f2c0dd91..ffe5c0600b 100644 --- a/ares/sfc/ppu-performance/dac.cpp +++ b/ares/sfc/ppu-performance/dac.cpp @@ -1,11 +1,11 @@ auto PPU::DAC::prepare() -> void { bool hires = ppu.io.pseudoHires || ppu.io.bgMode == 5 || ppu.io.bgMode == 6; - uint15 aboveColor = cgram[0]; - uint15 belowColor = hires ? cgram[0] : fixedColor(); + n15 aboveColor = cgram[0]; + n15 belowColor = hires ? cgram[0] : fixedColor(); if(ppu.io.displayDisable) aboveColor = 0, belowColor = 0; - for(uint x : range(256)) { + for(u32 x : range(256)) { above[x] = {PPU::Source::COL, 0, aboveColor}; below[x] = {PPU::Source::COL, 0, belowColor}; } @@ -16,19 +16,19 @@ auto PPU::DAC::render() -> void { ppu.window.render(window, window.belowMask, windowBelow); auto vcounter = ppu.vcounter(); - auto output = (uint32*)ppu.screen->pixels().data(); + auto output = (n32*)ppu.screen->pixels().data(); if(!ppu.state.overscan) vcounter += 8; if(vcounter < 240) { output += vcounter * 2 * 512; if(ppu.interlace() && ppu.field()) output += 512; - uint luma = ppu.io.displayBrightness << 15; + u32 luma = ppu.io.displayBrightness << 15; if(!ppu.hires()) { - for(uint x : range(256)) { + for(u32 x : range(256)) { *output++ = luma | pixel(x, above[x], below[x]); } } else { - for(uint x : range(256)) { + for(u32 x : range(256)) { *output++ = luma | pixel(x, below[x], above[x]); *output++ = luma | pixel(x, above[x], below[x]); } @@ -36,7 +36,7 @@ auto PPU::DAC::render() -> void { } } -auto PPU::DAC::pixel(uint8 x, Pixel above, Pixel below) const -> uint15 { +auto PPU::DAC::pixel(n8 x, Pixel above, Pixel below) const -> n15 { if(!windowAbove[x]) above.color = 0x0000; if(!windowBelow[x]) return above.color; if(!io.colorEnable[above.source]) return above.color; @@ -44,18 +44,18 @@ auto PPU::DAC::pixel(uint8 x, Pixel above, Pixel below) const -> uint15 { return blend(above.color, below.color, io.colorHalve && windowAbove[x] && below.source != PPU::Source::COL); } -auto PPU::DAC::blend(uint15 x, uint15 y, bool halve) const -> uint15 { +auto PPU::DAC::blend(n15 x, n15 y, bool halve) const -> n15 { if(!io.colorMode) { if(!halve) { - uint sum = x + y; - uint carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; + u32 sum = x + y; + u32 carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; return (sum - carry) | (carry - (carry >> 5)); } else { return (x + y - ((x ^ y) & 0x0421)) >> 1; } } else { - uint diff = x - y + 0x8420; - uint borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; + u32 diff = x - y + 0x8420; + u32 borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; if(!halve) { return (diff - borrow) & (borrow - (borrow >> 5)); } else { @@ -64,15 +64,15 @@ auto PPU::DAC::blend(uint15 x, uint15 y, bool halve) const -> uint15 { } } -inline auto PPU::DAC::plotAbove(uint8 x, uint8 source, uint8 priority, uint15 color) -> void { +inline auto PPU::DAC::plotAbove(n8 x, n8 source, n8 priority, n15 color) -> void { if(priority > above[x].priority) above[x] = {source, priority, color}; } -inline auto PPU::DAC::plotBelow(uint8 x, uint8 source, uint8 priority, uint15 color) -> void { +inline auto PPU::DAC::plotBelow(n8 x, n8 source, n8 priority, n15 color) -> void { if(priority > below[x].priority) below[x] = {source, priority, color}; } -inline auto PPU::DAC::directColor(uint8 palette, uint3 paletteGroup) const -> uint15 { +inline auto PPU::DAC::directColor(n8 palette, n3 paletteGroup) const -> n15 { //palette = -------- BBGGGRRR //group = -------- -----bgr //output = 0BBb00GG Gg0RRRr0 @@ -81,7 +81,7 @@ inline auto PPU::DAC::directColor(uint8 palette, uint3 paletteGroup) const -> ui + (palette << 2 & 0x001c) + (paletteGroup << 1 & 0x0002); } -inline auto PPU::DAC::fixedColor() const -> uint15 { +inline auto PPU::DAC::fixedColor() const -> n15 { return io.colorRed << 0 | io.colorGreen << 5 | io.colorBlue << 10; } diff --git a/ares/sfc/ppu-performance/dac.hpp b/ares/sfc/ppu-performance/dac.hpp index 50c0fe7690..bff77b261a 100644 --- a/ares/sfc/ppu-performance/dac.hpp +++ b/ares/sfc/ppu-performance/dac.hpp @@ -4,37 +4,37 @@ struct DAC { //dac.cpp auto prepare() -> void; auto render() -> void; - auto pixel(uint8 x, Pixel above, Pixel below) const -> uint15; - auto blend(uint15 x, uint15 y, bool halve) const -> uint15; - auto plotAbove(uint8 x, uint8 source, uint8 priority, uint15 color) -> void; - auto plotBelow(uint8 x, uint8 source, uint8 priority, uint15 color) -> void; - auto directColor(uint8 palette, uint3 paletteGroup) const -> uint15; - auto fixedColor() const -> uint15; + auto pixel(n8 x, Pixel above, Pixel below) const -> n15; + auto blend(n15 x, n15 y, bool halve) const -> n15; + auto plotAbove(n8 x, n8 source, n8 priority, n15 color) -> void; + auto plotBelow(n8 x, n8 source, n8 priority, n15 color) -> void; + auto directColor(n8 palette, n3 paletteGroup) const -> n15; + auto fixedColor() const -> n15; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint15 cgram[256]; + n15 cgram[256]; struct IO { - uint1 directColor; - uint1 blendMode; - uint1 colorEnable[7]; - uint1 colorHalve; - uint1 colorMode; - uint5 colorRed; - uint5 colorGreen; - uint5 colorBlue; + n1 directColor; + n1 blendMode; + n1 colorEnable[7]; + n1 colorHalve; + n1 colorMode; + n5 colorRed; + n5 colorGreen; + n5 colorBlue; } io; PPU::Window::Color window; //unserialized: struct Pixel { - uint8 source; - uint8 priority; - uint15 color; + n8 source; + n8 priority; + n15 color; } above[256], below[256]; bool windowAbove[256]; diff --git a/ares/sfc/ppu-performance/debugger.cpp b/ares/sfc/ppu-performance/debugger.cpp index 0e18d8411a..5353aef9be 100644 --- a/ares/sfc/ppu-performance/debugger.cpp +++ b/ares/sfc/ppu-performance/debugger.cpp @@ -29,15 +29,15 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles2bpp = parent->append("2 BPP Tiles"); graphics.tiles2bpp->setSize(512, 512); graphics.tiles2bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 512); - for(uint tileY : range(64)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 3; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y]; - for(uint x : range(8)) { - uint2 color; + for(u32 tileY : range(64)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 3; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y]; + for(u32 x : range(8)) { + n2 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); output[(tileY * 8 + y) * 512 + (tileX * 8 + x)] = color * 0x555555; @@ -51,16 +51,16 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles4bpp = parent->append("4 BPP Tiles"); graphics.tiles4bpp->setSize(512, 256); graphics.tiles4bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 256); - for(uint tileY : range(32)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 4; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y + 0]; - uint16 d1 = ppu.vram.data[address + y + 8]; - for(uint x : range(8)) { - uint4 color; + for(u32 tileY : range(32)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 4; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y + 0]; + n16 d1 = ppu.vram.data[address + y + 8]; + for(u32 x : range(8)) { + n4 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); color.bit(2) = d1.bit( 7 - x); @@ -76,18 +76,18 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles8bpp = parent->append("8 BPP Tiles"); graphics.tiles8bpp->setSize(512, 128); graphics.tiles8bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 128); - for(uint tileY : range(16)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 5; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y + 0]; - uint16 d1 = ppu.vram.data[address + y + 8]; - uint16 d2 = ppu.vram.data[address + y + 16]; - uint16 d3 = ppu.vram.data[address + y + 24]; - for(uint x : range(8)) { - uint8 color; + for(u32 tileY : range(16)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 5; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y + 0]; + n16 d1 = ppu.vram.data[address + y + 8]; + n16 d2 = ppu.vram.data[address + y + 16]; + n16 d3 = ppu.vram.data[address + y + 24]; + for(u32 x : range(8)) { + n8 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); color.bit(2) = d1.bit( 7 - x); @@ -107,14 +107,14 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tilesMode7 = parent->append("Mode 7 Tiles"); graphics.tilesMode7->setSize(128, 128); graphics.tilesMode7->setCapture([&]() -> vector { - vector output; + vector output; output.resize(128 * 128); - for(uint tileY : range(16)) { - for(uint tileX : range(16)) { - uint15 address = tileY * 16 + tileX << 6; - for(uint y : range(8)) { - for(uint x : range(8)) { - uint8 color = ppu.vram.data[address + y * 8 + x].byte(1); + for(u32 tileY : range(16)) { + for(u32 tileX : range(16)) { + n15 address = tileY * 16 + tileX << 6; + for(u32 y : range(8)) { + for(u32 x : range(8)) { + n8 color = ppu.vram.data[address + y * 8 + x].byte(1); output[(tileY * 8 + y) * 128 + (tileX * 8 + x)] = color << 16 | color << 8 | color << 0; } } diff --git a/ares/sfc/ppu-performance/io.cpp b/ares/sfc/ppu-performance/io.cpp index a4a0718021..5858a83def 100644 --- a/ares/sfc/ppu-performance/io.cpp +++ b/ares/sfc/ppu-performance/io.cpp @@ -5,8 +5,8 @@ auto PPU::latchCounters() -> void { latch.counters = 1; } -alwaysinline auto PPU::addressVRAM() const -> uint16 { - uint16 address = vram.address; +alwaysinline auto PPU::addressVRAM() const -> n16 { + n16 address = vram.address; switch(vram.mapping) { case 0: return address; case 1: return address.bit( 8,15) << 8 | address.bit(0,4) << 3 | address.bit(5,7); @@ -16,29 +16,29 @@ alwaysinline auto PPU::addressVRAM() const -> uint16 { unreachable; } -alwaysinline auto PPU::readVRAM() -> uint16 { +alwaysinline auto PPU::readVRAM() -> n16 { if(!io.displayDisable && cpu.vcounter() < vdisp()) return 0x0000; auto address = addressVRAM(); return vram[address]; } -alwaysinline auto PPU::writeVRAM(uint1 byte, uint8 data) -> void { +alwaysinline auto PPU::writeVRAM(n1 byte, n8 data) -> void { if(!io.displayDisable && cpu.vcounter() < vdisp()) return; auto address = addressVRAM(); vram[address].byte(byte) = data; } -alwaysinline auto PPU::readOAM(uint10 address) -> uint8 { +alwaysinline auto PPU::readOAM(n10 address) -> n8 { if(!io.displayDisable && cpu.vcounter() < vdisp()) address = 0x0218; return obj.oam.read(address); } -alwaysinline auto PPU::writeOAM(uint10 address, uint8 data) -> void { +alwaysinline auto PPU::writeOAM(n10 address, n8 data) -> void { if(!io.displayDisable && cpu.vcounter() < vdisp()) address = 0x0218; return obj.oam.write(address, data); } -alwaysinline auto PPU::readCGRAM(uint1 byte, uint8 address) -> uint8 { +alwaysinline auto PPU::readCGRAM(n1 byte, n8 address) -> n8 { if(!io.displayDisable && cpu.vcounter() > 0 && cpu.vcounter() < vdisp() && cpu.hcounter() >= 88 && cpu.hcounter() < 1096 @@ -46,7 +46,7 @@ alwaysinline auto PPU::readCGRAM(uint1 byte, uint8 address) -> uint8 { return dac.cgram[address].byte(byte); } -alwaysinline auto PPU::writeCGRAM(uint8 address, uint15 data) -> void { +alwaysinline auto PPU::writeCGRAM(n8 address, n15 data) -> void { if(!io.displayDisable && cpu.vcounter() > 0 && cpu.vcounter() < vdisp() && cpu.hcounter() >= 88 && cpu.hcounter() < 1096 @@ -54,10 +54,10 @@ alwaysinline auto PPU::writeCGRAM(uint8 address, uint15 data) -> void { dac.cgram[address] = data; } -auto PPU::readIO(uint24 address, uint8 data) -> uint8 { +auto PPU::readIO(n24 address, n8 data) -> n8 { cpu.synchronize(ppu); - switch((uint16)address) { + switch((n16)address) { case 0x2104: case 0x2105: case 0x2106: case 0x2108: case 0x2109: case 0x210a: case 0x2114: case 0x2115: @@ -69,19 +69,19 @@ auto PPU::readIO(uint24 address, uint8 data) -> uint8 { //MPYL case 0x2134: { - uint24 result = (int16)mode7.a * (int8)(mode7.b >> 8); + n24 result = (i16)mode7.a * (i8)(mode7.b >> 8); return ppu1.mdr = result.byte(0); } //MPYM case 0x2135: { - uint24 result = (int16)mode7.a * (int8)(mode7.b >> 8); + n24 result = (i16)mode7.a * (i8)(mode7.b >> 8); return ppu1.mdr = result.byte(1); } //MYPH case 0x2136: { - uint24 result = (int16)mode7.a * (int8)(mode7.b >> 8); + n24 result = (i16)mode7.a * (i8)(mode7.b >> 8); return ppu1.mdr = result.byte(2); } @@ -178,10 +178,10 @@ auto PPU::readIO(uint24 address, uint8 data) -> uint8 { return data; } -auto PPU::writeIO(uint24 address, uint8 data) -> void { +auto PPU::writeIO(n24 address, n8 data) -> void { cpu.synchronize(ppu); - switch((uint16)address) { + switch((n16)address) { //INIDISP case 0x2100: { @@ -216,8 +216,8 @@ auto PPU::writeIO(uint24 address, uint8 data) -> void { //OAMDATA case 0x2104: { - uint1 latchBit = io.oamAddress.bit(0); - uint10 address = io.oamAddress++; + n1 latchBit = io.oamAddress.bit(0); + n10 address = io.oamAddress++; if(latchBit == 0) latch.oam = data; if(address.bit(9)) { writeOAM(address, data); @@ -366,7 +366,7 @@ auto PPU::writeIO(uint24 address, uint8 data) -> void { //VMAIN case 0x2115: { - static const uint size[4] = {1, 32, 128, 128}; + static constexpr u32 size[4] = {1, 32, 128, 128}; vram.increment = size[data.bit(0,1)]; vram.mapping = data.bit(2,3); vram.mode = data.bit(7); diff --git a/ares/sfc/ppu-performance/mode7.cpp b/ares/sfc/ppu-performance/mode7.cpp index 6013df6ea3..4de9f3c193 100644 --- a/ares/sfc/ppu-performance/mode7.cpp +++ b/ares/sfc/ppu-performance/mode7.cpp @@ -1,49 +1,49 @@ auto PPU::Background::renderMode7() -> void { - int Y = ppu.vcounter(); + s32 Y = ppu.vcounter(); if(io.mosaicEnable) Y -= ppu.mosaic.voffset(); //BG2 vertical mosaic uses BG1 mosaic enable - int y = !ppu.mode7.vflip ? Y : 255 - Y; + s32 y = !ppu.mode7.vflip ? Y : 255 - Y; - int a = (int16)ppu.mode7.a; - int b = (int16)ppu.mode7.b; - int c = (int16)ppu.mode7.c; - int d = (int16)ppu.mode7.d; - int hcenter = (int13)ppu.mode7.hcenter; - int vcenter = (int13)ppu.mode7.vcenter; - int hoffset = (int13)ppu.mode7.hoffset; - int voffset = (int13)ppu.mode7.voffset; + s32 a = (i16)ppu.mode7.a; + s32 b = (i16)ppu.mode7.b; + s32 c = (i16)ppu.mode7.c; + s32 d = (i16)ppu.mode7.d; + s32 hcenter = (i13)ppu.mode7.hcenter; + s32 vcenter = (i13)ppu.mode7.vcenter; + s32 hoffset = (i13)ppu.mode7.hoffset; + s32 voffset = (i13)ppu.mode7.voffset; - uint mosaicCounter = 1; - uint mosaicPalette = 0; - uint8 mosaicPriority = 0; - uint15 mosaicColor = 0; + u32 mosaicCounter = 1; + u32 mosaicPalette = 0; + n8 mosaicPriority = 0; + n15 mosaicColor = 0; - auto clip = [](int n) -> int { return n & 0x2000 ? (n | ~1023) : (n & 1023); }; - int originX = (a * clip(hoffset - hcenter) & ~63) + (b * clip(voffset - vcenter) & ~63) + (b * y & ~63) + (hcenter << 8); - int originY = (c * clip(hoffset - hcenter) & ~63) + (d * clip(voffset - vcenter) & ~63) + (d * y & ~63) + (vcenter << 8); + auto clip = [](s32 n) -> s32 { return n & 0x2000 ? (n | ~1023) : (n & 1023); }; + s32 originX = (a * clip(hoffset - hcenter) & ~63) + (b * clip(voffset - vcenter) & ~63) + (b * y & ~63) + (hcenter << 8); + s32 originY = (c * clip(hoffset - hcenter) & ~63) + (d * clip(voffset - vcenter) & ~63) + (d * y & ~63) + (vcenter << 8); bool windowAbove[256]; bool windowBelow[256]; ppu.window.render(window, window.aboveEnable, windowAbove); ppu.window.render(window, window.belowEnable, windowBelow); - for(int X : range(256)) { - int x = !ppu.mode7.hflip ? X : 255 - X; + for(s32 X : range(256)) { + s32 x = !ppu.mode7.hflip ? X : 255 - X; - int pixelX = originX + a * x >> 8; - int pixelY = originY + c * x >> 8; + s32 pixelX = originX + a * x >> 8; + s32 pixelY = originY + c * x >> 8; - uint7 tileX = pixelX >> 3; - uint7 tileY = pixelY >> 3; + n7 tileX = pixelX >> 3; + n7 tileY = pixelY >> 3; bool outOfBounds = (pixelX | pixelY) & ~1023; - uint16 tileAddress = tileY << 7 | tileX; - uint16 paletteAddress = (uint3)pixelY << 3 | (uint3)pixelX; + n16 tileAddress = tileY << 7 | tileX; + n16 paletteAddress = (n3)pixelY << 3 | (n3)pixelX; - uint8 tile = ppu.mode7.repeat == 3 && outOfBounds ? 0 : ppu.vram[tileAddress] >> 0; - uint8 palette = ppu.mode7.repeat == 2 && outOfBounds ? 0 : ppu.vram[tile << 6 | paletteAddress] >> 8; + n8 tile = ppu.mode7.repeat == 3 && outOfBounds ? 0 : ppu.vram[tileAddress] >> 0; + n8 palette = ppu.mode7.repeat == 2 && outOfBounds ? 0 : ppu.vram[tile << 6 | paletteAddress] >> 8; - uint8 priority; + n8 priority; if(id == ID::BG1) { priority = io.priority[0]; } else { @@ -52,7 +52,7 @@ auto PPU::Background::renderMode7() -> void { } if(--mosaicCounter == 0) { - mosaicCounter = io.mosaicEnable ? (uint)ppu.mosaic.size : 1; + mosaicCounter = io.mosaicEnable ? (u32)ppu.mosaic.size : 1; mosaicPalette = palette; mosaicPriority = priority; if(ppu.dac.io.directColor && id == ID::BG1) { diff --git a/ares/sfc/ppu-performance/mosaic.cpp b/ares/sfc/ppu-performance/mosaic.cpp index 5c4594ae28..24ca6157dd 100644 --- a/ares/sfc/ppu-performance/mosaic.cpp +++ b/ares/sfc/ppu-performance/mosaic.cpp @@ -6,7 +6,7 @@ inline auto PPU::Mosaic::enable() const -> bool { return false; } -inline auto PPU::Mosaic::voffset() const -> uint { +inline auto PPU::Mosaic::voffset() const -> u32 { return size - vcounter; } diff --git a/ares/sfc/ppu-performance/mosaic.hpp b/ares/sfc/ppu-performance/mosaic.hpp index 957d74e683..88ae090cb7 100644 --- a/ares/sfc/ppu-performance/mosaic.hpp +++ b/ares/sfc/ppu-performance/mosaic.hpp @@ -1,13 +1,13 @@ struct Mosaic { //mosaic.cpp auto enable() const -> bool; - auto voffset() const -> uint; + auto voffset() const -> u32; auto scanline() -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint5 size; - uint5 vcounter; + n5 size; + n5 vcounter; }; diff --git a/ares/sfc/ppu-performance/oam.cpp b/ares/sfc/ppu-performance/oam.cpp index 9d1b4f078a..29be6fcf97 100644 --- a/ares/sfc/ppu-performance/oam.cpp +++ b/ares/sfc/ppu-performance/oam.cpp @@ -1,8 +1,8 @@ -auto PPU::OAM::read(uint10 address) -> uint8 { - uint8 data; +auto PPU::OAM::read(n10 address) -> n8 { + n8 data; if(!address.bit(9)) { - uint7 n = address >> 2; //object# + n7 n = address >> 2; //object# address &= 3; if(address == 0) return objects[n].x.bit(0,7); if(address == 1) return objects[n].y - 1; //-1 => rendering happens one scanline late @@ -15,7 +15,7 @@ auto PPU::OAM::read(uint10 address) -> uint8 { return data; } - uint7 n = (uint5)address << 2; //object# + n7 n = (n5)address << 2; //object# data.bit(0) = objects[n + 0].x.bit(8); data.bit(1) = objects[n + 0].size; data.bit(2) = objects[n + 1].x.bit(8); @@ -27,9 +27,9 @@ auto PPU::OAM::read(uint10 address) -> uint8 { return data; } -auto PPU::OAM::write(uint10 address, uint8 data) -> void { +auto PPU::OAM::write(n10 address, n8 data) -> void { if(!address.bit(9)) { - uint7 n = address >> 2; //object# + n7 n = address >> 2; //object# address &= 3; if(address == 0) { objects[n].x.bit(0,7) = data; return; } if(address == 1) { objects[n].y = data + 1; return; } //+1 => rendering happens one scanline late @@ -40,7 +40,7 @@ auto PPU::OAM::write(uint10 address, uint8 data) -> void { objects[n].hflip = data.bit(6); objects[n].vflip = data.bit(7); } else { - uint7 n = (uint5)address << 2; //object# + n7 n = (n5)address << 2; //object# objects[n + 0].x.bit(8) = data.bit(0); objects[n + 0].size = data.bit(1); objects[n + 1].x.bit(8) = data.bit(2); @@ -52,23 +52,23 @@ auto PPU::OAM::write(uint10 address, uint8 data) -> void { } } -alwaysinline auto PPU::OAM::Object::width() const -> uint { +alwaysinline auto PPU::OAM::Object::width() const -> u32 { if(size == 0) { - static const uint width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; + static const u32 width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; return width[ppu.obj.io.baseSize]; } else { - static const uint width[] = {16, 32, 64, 32, 64, 64, 32, 32}; + static const u32 width[] = {16, 32, 64, 32, 64, 64, 32, 32}; return width[ppu.obj.io.baseSize]; } } -alwaysinline auto PPU::OAM::Object::height() const -> uint { +alwaysinline auto PPU::OAM::Object::height() const -> u32 { if(size == 0) { if(ppu.obj.io.interlace && ppu.obj.io.baseSize >= 6) return 16; //hardware quirk - static const uint height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; + static const u32 height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; return height[ppu.obj.io.baseSize]; } else { - static const uint height[] = {16, 32, 64, 32, 64, 64, 64, 32}; + static const u32 height[] = {16, 32, 64, 32, 64, 64, 64, 32}; return height[ppu.obj.io.baseSize]; } } diff --git a/ares/sfc/ppu-performance/oam.hpp b/ares/sfc/ppu-performance/oam.hpp index 3f68764f7b..e478d0218f 100644 --- a/ares/sfc/ppu-performance/oam.hpp +++ b/ares/sfc/ppu-performance/oam.hpp @@ -1,24 +1,24 @@ struct OAM { //oam.cpp - auto read(uint10 address) -> uint8; - auto write(uint10 address, uint8 data) -> void; + auto read(n10 address) -> n8; + auto write(n10 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; struct Object { //oam.cpp - auto width() const -> uint; - auto height() const -> uint; + auto width() const -> u32; + auto height() const -> u32; - uint9 x; - uint8 y; - uint8 character; - uint1 nameselect; - uint1 vflip; - uint1 hflip; - uint2 priority; - uint3 palette; - uint1 size; + n9 x; + n8 y; + n8 character; + n1 nameselect; + n1 vflip; + n1 hflip; + n2 priority; + n3 palette; + n1 size; } objects[128]; }; diff --git a/ares/sfc/ppu-performance/object.cpp b/ares/sfc/ppu-performance/object.cpp index 58fd5c0215..17b85f8f80 100644 --- a/ares/sfc/ppu-performance/object.cpp +++ b/ares/sfc/ppu-performance/object.cpp @@ -16,19 +16,19 @@ auto PPU::Object::render() -> void { ppu.window.render(window, window.aboveEnable, windowAbove); ppu.window.render(window, window.belowEnable, windowBelow); - uint itemCount = 0; - uint tileCount = 0; - for(uint n : range(32)) items[n].valid = false; - for(uint n : range(34)) tiles[n].valid = false; + u32 itemCount = 0; + u32 tileCount = 0; + for(u32 n : range(32)) items[n].valid = false; + for(u32 n : range(34)) tiles[n].valid = false; - for(uint n : range(128)) { + for(u32 n : range(128)) { Item item{true, io.firstSprite + n & 127}; const auto& object = oam.objects[item.index]; item.width = object.width(); item.height = object.height(); if(object.x > 256 && object.x + item.width - 1 < 512) continue; - uint height = item.height >> io.interlace; + u32 height = item.height >> io.interlace; if((ppu.vcounter() >= object.y && ppu.vcounter() < object.y + height) || (object.y + height >= 256 && ppu.vcounter() < (object.y + height & 255)) ) { @@ -37,14 +37,14 @@ auto PPU::Object::render() -> void { } } - for(int n : reverse(range(32))) { + for(s32 n : reverse(range(32))) { const auto& item = items[n]; if(!item.valid) continue; const auto& object = oam.objects[item.index]; - uint tileWidth = item.width >> 3; - int x = object.x; - int y = ppu.vcounter() - object.y & 255; + u32 tileWidth = item.width >> 3; + s32 x = object.x; + s32 y = ppu.vcounter() - object.y & 255; if(io.interlace) y <<= 1; if(object.vflip) { @@ -64,13 +64,13 @@ auto PPU::Object::render() -> void { x &= 511; y &= 255; - uint16 tiledataAddress = io.tiledataAddress; + n16 tiledataAddress = io.tiledataAddress; if(object.nameselect) tiledataAddress += 1 + io.nameselect << 12; - uint16 characterX = object.character.bit(0,3); - uint16 characterY = (object.character.bit(4,7) + (y >> 3) & 15) << 4; + n16 characterX = object.character.bit(0,3); + n16 characterY = (object.character.bit(4,7) + (y >> 3) & 15) << 4; - for(uint tileX : range(tileWidth)) { - uint objectX = x + (tileX << 3) & 511; + for(u32 tileX : range(tileWidth)) { + u32 objectX = x + (tileX << 3) & 511; if(x != 256 && objectX >= 256 && objectX + 7 < 512) continue; Tile tile{true}; @@ -79,8 +79,8 @@ auto PPU::Object::render() -> void { tile.palette = 128 + (object.palette << 4); tile.hflip = object.hflip; - uint mirrorX = !object.hflip ? tileX : tileWidth - 1 - tileX; - uint address = tiledataAddress + ((characterY + (characterX + mirrorX & 15)) << 4); + u32 mirrorX = !object.hflip ? tileX : tileWidth - 1 - tileX; + u32 address = tiledataAddress + ((characterY + (characterX + mirrorX & 15)) << 4); address = (address & 0xfff0) + (y & 7); tile.data.bit( 0,15) = ppu.vram[address + 0]; tile.data.bit(16,31) = ppu.vram[address + 8]; @@ -93,18 +93,18 @@ auto PPU::Object::render() -> void { io.rangeOver |= itemCount > 32; io.timeOver |= tileCount > 34; - uint8 palette[256]; - uint8 priority[256]; + n8 palette[256]; + n8 priority[256]; - for(uint n : range(34)) { + for(u32 n : range(34)) { auto& tile = tiles[n]; if(!tile.valid) continue; - uint tileX = tile.x; - for(uint x : range(8)) { + u32 tileX = tile.x; + for(u32 x : range(8)) { tileX &= 511; if(tileX < 256) { - uint color = 0, shift = tile.hflip ? x : 7 - x; + u32 color = 0, shift = tile.hflip ? x : 7 - x; color += tile.data >> shift + 0 & 1; color += tile.data >> shift + 7 & 2; color += tile.data >> shift + 14 & 4; @@ -118,9 +118,9 @@ auto PPU::Object::render() -> void { } } - for(uint x : range(256)) { + for(u32 x : range(256)) { if(!priority[x]) continue; - uint8 source = palette[x] < 192 ? PPU::Source::OBJ1 : PPU::Source::OBJ2; + n8 source = palette[x] < 192 ? PPU::Source::OBJ1 : PPU::Source::OBJ2; if(io.aboveEnable && !windowAbove[x]) ppu.dac.plotAbove(x, source, priority[x], ppu.dac.cgram[palette[x]]); if(io.belowEnable && !windowBelow[x]) ppu.dac.plotBelow(x, source, priority[x], ppu.dac.cgram[palette[x]]); } diff --git a/ares/sfc/ppu-performance/object.hpp b/ares/sfc/ppu-performance/object.hpp index 3790c2b1ca..aa8198ffe2 100644 --- a/ares/sfc/ppu-performance/object.hpp +++ b/ares/sfc/ppu-performance/object.hpp @@ -11,39 +11,39 @@ struct Object { OAM oam; struct IO { - uint1 interlace; + n1 interlace; - uint16 tiledataAddress; - uint2 nameselect; - uint3 baseSize; - uint7 firstSprite; + n16 tiledataAddress; + n2 nameselect; + n3 baseSize; + n7 firstSprite; - uint1 aboveEnable; - uint1 belowEnable; + n1 aboveEnable; + n1 belowEnable; - uint1 rangeOver; - uint1 timeOver; + n1 rangeOver; + n1 timeOver; - uint8 priority[4]; + n8 priority[4]; } io; PPU::Window::Layer window; //unserialized: struct Item { - uint1 valid; - uint7 index; - uint8 width; - uint8 height; + n1 valid; + n7 index; + n8 width; + n8 height; } items[32]; struct Tile { - uint1 valid; - uint9 x; - uint2 priority; - uint8 palette; - uint1 hflip; - uint32 data; + n1 valid; + n9 x; + n2 priority; + n8 palette; + n1 hflip; + n32 data; } tiles[34]; friend class PPU; diff --git a/ares/sfc/ppu-performance/ppu.cpp b/ares/sfc/ppu-performance/ppu.cpp index 54ee9d101b..f93bdb3153 100644 --- a/ares/sfc/ppu-performance/ppu.cpp +++ b/ares/sfc/ppu-performance/ppu.cpp @@ -47,7 +47,7 @@ auto PPU::unload() -> void { debugger = {}; } -auto PPU::step(uint clocks) -> void { +auto PPU::step(u32 clocks) -> void { tick(clocks); Thread::step(clocks); Thread::synchronize(cpu); @@ -64,7 +64,7 @@ auto PPU::main() -> void { } if(vcounter() && vcounter() < vdisp() && !runAhead()) { - uint width = hires() ? 512 : 256; + u32 width = hires() ? 512 : 256; if(width == 256) width256 = 1; if(width == 512) width512 = 1; widths[vcounter()] = width; @@ -100,8 +100,8 @@ auto PPU::main() -> void { } auto PPU::map() -> void { - function reader{&PPU::readIO, this}; - function writer{&PPU::writeIO, this}; + function reader{&PPU::readIO, this}; + function writer{&PPU::writeIO, this}; bus.map(reader, writer, "00-3f,80-bf:2100-213f"); } @@ -131,7 +131,7 @@ auto PPU::power(bool reset) -> void { updateVideoMode(); string title; - for(uint index : range(21)) { + for(u32 index : range(21)) { char byte = bus.read(0xffc0 + index, 0x00); if(byte == 0x00) break; if(byte == 0xff) break; @@ -150,12 +150,12 @@ auto PPU::power(bool reset) -> void { auto PPU::normalize() -> void { if(width256 && width512) { //this frame contains mixed resolutions: normalize every scanline to 512-width - for(uint y : range(1, 240)) { + for(u32 y : range(1, 240)) { auto line = screen->pixels().data() + 1024 * y + (interlace() && field() ? 512 : 0); if(widths[y] == 256) { auto source = &line[256]; auto target = &line[512]; - for(uint x : range(256)) { + for(u32 x : range(256)) { auto color = *--source; *--target = color; *--target = color; diff --git a/ares/sfc/ppu-performance/ppu.hpp b/ares/sfc/ppu-performance/ppu.hpp index 12bf6256a4..062441cc1f 100644 --- a/ares/sfc/ppu-performance/ppu.hpp +++ b/ares/sfc/ppu-performance/ppu.hpp @@ -25,140 +25,140 @@ struct PPU : Thread, PPUcounter { auto hires() const -> bool { return io.pseudoHires || io.bgMode == 5 || io.bgMode == 6; } auto interlace() const -> bool { return state.interlace; } auto overscan() const -> bool { return state.overscan; } - auto vdisp() const -> uint { return state.vdisp; } + auto vdisp() const -> u32 { return state.vdisp; } //ppu.cpp auto load(Node::Object parent) -> void; auto unload() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto main() -> void; auto map() -> void; auto power(bool reset) -> void; auto normalize() -> void; - auto draw(uint32_t* output) -> void; + auto draw(u32* output) -> void; //io.cpp auto latchCounters() -> void; - auto addressVRAM() const -> uint16; - auto readVRAM() -> uint16; - auto writeVRAM(uint1 byte, uint8 data) -> void; - auto readOAM(uint10 address) -> uint8; - auto writeOAM(uint10 address, uint8 data) -> void; - auto readCGRAM(uint1 byte, uint8 address) -> uint8; - auto writeCGRAM(uint8 address, uint15 data) -> void; - auto readIO(uint24 address, uint8 data) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto addressVRAM() const -> n16; + auto readVRAM() -> n16; + auto writeVRAM(n1 byte, n8 data) -> void; + auto readOAM(n10 address) -> n8; + auto writeOAM(n10 address, n8 data) -> void; + auto readCGRAM(n1 byte, n8 address) -> n8; + auto writeCGRAM(n8 address, n15 data) -> void; + auto readIO(n24 address, n8 data) -> n8; + auto writeIO(n24 address, n8 data) -> void; auto updateVideoMode() -> void; //color.cpp - auto color(uint32 color) -> uint64; + auto color(n32 color) -> n64; //serialization.cpp auto serialize(serializer&) -> void; private: - struct Source { enum : uint { BG1, BG2, BG3, BG4, OBJ1, OBJ2, COL }; }; + struct Source { enum : u32 { BG1, BG2, BG3, BG4, OBJ1, OBJ2, COL }; }; - uint32 renderingCycle; + n32 renderingCycle; struct { - uint4 version; - uint8 mdr; + n4 version; + n8 mdr; } ppu1, ppu2; struct VRAM { - auto& operator[](uint address) { return data[address & mask]; } - uint16 data[64_KiB]; - uint16 mask = 0x7fff; - uint16 address; - uint8 increment; - uint2 mapping; - uint1 mode; + auto& operator[](u32 address) { return data[address & mask]; } + n16 data[64_KiB]; + n16 mask = 0x7fff; + n16 address; + n8 increment; + n2 mapping; + n1 mode; } vram; struct State { - uint1 interlace; - uint1 overscan; - uint9 vdisp; + n1 interlace; + n1 overscan; + n9 vdisp; } state; struct Latches { - uint16 vram; - uint8 oam; - uint8 cgram; - uint8 bgofsPPU1; - uint8 bgofsPPU2; - uint8 mode7; - uint1 counters; - uint1 hcounter; - uint1 vcounter; - - uint10 oamAddress; - uint8 cgramAddress; + n16 vram; + n8 oam; + n8 cgram; + n8 bgofsPPU1; + n8 bgofsPPU2; + n8 mode7; + n1 counters; + n1 hcounter; + n1 vcounter; + + n10 oamAddress; + n8 cgramAddress; } latch; struct IO { //$2100 INIDISP - uint4 displayBrightness; - uint1 displayDisable; + n4 displayBrightness; + n1 displayDisable; //$2102 OAMADDL //$2103 OAMADDH - uint10 oamBaseAddress; - uint10 oamAddress; - uint1 oamPriority; + n10 oamBaseAddress; + n10 oamAddress; + n1 oamPriority; //$2105 BGMODE - uint3 bgMode; - uint1 bgPriority; + n3 bgMode; + n1 bgPriority; //$2121 CGADD - uint8 cgramAddress; - uint1 cgramAddressLatch; + n8 cgramAddress; + n1 cgramAddressLatch; //$2133 SETINI - uint1 interlace; - uint1 overscan; - uint1 pseudoHires; - uint1 extbg; + n1 interlace; + n1 overscan; + n1 pseudoHires; + n1 extbg; //$213c OPHCT - uint16 hcounter; + n16 hcounter; //$213d OPVCT - uint16 vcounter; + n16 vcounter; } io; struct Mode7 { //$210d BG1HOFS - uint16 hoffset; + n16 hoffset; //$210e BG1VOFS - uint16 voffset; + n16 voffset; //$211a M7SEL - uint1 hflip; - uint1 vflip; - uint2 repeat; + n1 hflip; + n1 vflip; + n2 repeat; //$211b M7A - uint16 a; + n16 a; //$211c M7B - uint16 b; + n16 b; //$211d M7C - uint16 c; + n16 c; //$211e M7D - uint16 d; + n16 d; //$211f M7X - uint16 hcenter; + n16 hcenter; //$2120 M7Y - uint16 vcenter; + n16 vcenter; } mode7; #include "window.hpp" @@ -177,9 +177,9 @@ struct PPU : Thread, PPUcounter { Object obj; DAC dac; - uint1 width256; - uint1 width512; - uint16 widths[240]; + n1 width256; + n1 width512; + n16 widths[240]; friend class PPU::Window; friend class PPU::Mosaic; diff --git a/ares/sfc/ppu-performance/serialization.cpp b/ares/sfc/ppu-performance/serialization.cpp index 4e9133186e..e159c714d2 100644 --- a/ares/sfc/ppu-performance/serialization.cpp +++ b/ares/sfc/ppu-performance/serialization.cpp @@ -8,7 +8,7 @@ auto PPU::serialize(serializer& s) -> void { s(ppu2.version); s(ppu2.mdr); - s(array_span{vram.data, vram.mask + 1}); + s(array_span{vram.data, vram.mask + 1}); s(vram.address); s(vram.increment); s(vram.mapping); diff --git a/ares/sfc/ppu-performance/window.cpp b/ares/sfc/ppu-performance/window.cpp index fb00bb3f85..e091eed969 100644 --- a/ares/sfc/ppu-performance/window.cpp +++ b/ares/sfc/ppu-performance/window.cpp @@ -6,7 +6,7 @@ auto PPU::Window::render(Layer& layer, bool enable, bool output[256]) -> void { if(layer.oneEnable && !layer.twoEnable) { bool set = 1 ^ layer.oneInvert, clear = !set; - for(uint x : range(256)) { + for(u32 x : range(256)) { output[x] = x >= io.oneLeft && x <= io.oneRight ? set : clear; } return; @@ -14,13 +14,13 @@ auto PPU::Window::render(Layer& layer, bool enable, bool output[256]) -> void { if(layer.twoEnable && !layer.oneEnable) { bool set = 1 ^ layer.twoInvert, clear = !set; - for(uint x : range(256)) { + for(u32 x : range(256)) { output[x] = x >= io.twoLeft && x <= io.twoRight ? set : clear; } return; } - for(uint x : range(256)) { + for(u32 x : range(256)) { bool oneMask = (x >= io.oneLeft && x <= io.oneRight) ^ layer.oneInvert; bool twoMask = (x >= io.twoLeft && x <= io.twoRight) ^ layer.twoInvert; switch(layer.mask) { @@ -32,7 +32,7 @@ auto PPU::Window::render(Layer& layer, bool enable, bool output[256]) -> void { } } -auto PPU::Window::render(Color& color, uint mask, bool output[256]) -> void { +auto PPU::Window::render(Color& color, u32 mask, bool output[256]) -> void { bool set, clear; switch(mask) { case 0: memory::fill(output, 256, 1); return; //always @@ -48,7 +48,7 @@ auto PPU::Window::render(Color& color, uint mask, bool output[256]) -> void { if(color.oneEnable && !color.twoEnable) { if(color.oneInvert) set ^= 1, clear ^= 1; - for(uint x : range(256)) { + for(u32 x : range(256)) { output[x] = x >= io.oneLeft && x <= io.oneRight ? set : clear; } return; @@ -56,13 +56,13 @@ auto PPU::Window::render(Color& color, uint mask, bool output[256]) -> void { if(!color.oneEnable && color.twoEnable) { if(color.twoInvert) set ^= 1, clear ^= 1; - for(uint x : range(256)) { + for(u32 x : range(256)) { output[x] = x >= io.twoLeft && x <= io.twoRight ? set : clear; } return; } - for(uint x : range(256)) { + for(u32 x : range(256)) { bool oneMask = (x >= io.oneLeft && x <= io.oneRight) ^ color.oneInvert; bool twoMask = (x >= io.twoLeft && x <= io.twoRight) ^ color.twoInvert; switch(color.mask) { diff --git a/ares/sfc/ppu-performance/window.hpp b/ares/sfc/ppu-performance/window.hpp index d7d3543c5c..e35d12c4aa 100644 --- a/ares/sfc/ppu-performance/window.hpp +++ b/ares/sfc/ppu-performance/window.hpp @@ -4,33 +4,33 @@ struct Window { //window.cpp auto render(Layer&, bool enable, bool output[256]) -> void; - auto render(Color&, uint mask, bool output[256]) -> void; + auto render(Color&, u32 mask, bool output[256]) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; struct Layer { - uint1 oneInvert; - uint1 oneEnable; - uint1 twoInvert; - uint1 twoEnable; - uint2 mask; - uint1 aboveEnable; - uint1 belowEnable; + n1 oneInvert; + n1 oneEnable; + n1 twoInvert; + n1 twoEnable; + n2 mask; + n1 aboveEnable; + n1 belowEnable; //serialization.cpp auto serialize(serializer&) -> void; }; struct Color { - uint1 oneInvert; - uint1 oneEnable; - uint1 twoInvert; - uint1 twoEnable; - uint2 mask; - uint2 aboveMask; - uint2 belowMask; + n1 oneInvert; + n1 oneEnable; + n1 twoInvert; + n1 twoEnable; + n2 mask; + n2 aboveMask; + n2 belowMask; //serialization.cpp auto serialize(serializer&) -> void; @@ -38,16 +38,16 @@ struct Window { struct IO { //$2126 WH0 - uint8 oneLeft; + n8 oneLeft; //$2127 WH1 - uint8 oneRight; + n8 oneRight; //$2128 WH2 - uint8 twoLeft; + n8 twoLeft; //$2129 WH3 - uint8 twoRight; + n8 twoRight; } io; friend class PPU; diff --git a/ares/sfc/ppu/background.cpp b/ares/sfc/ppu/background.cpp index 497ff038f3..8ed9638827 100644 --- a/ares/sfc/ppu/background.cpp +++ b/ares/sfc/ppu/background.cpp @@ -27,13 +27,13 @@ auto PPU::Background::begin() -> void { auto PPU::Background::fetchNameTable() -> void { if(ppu.vcounter() == 0) return; - uint nameTableIndex = ppu.hcounter() >> 5 << hires(); - int x = (ppu.hcounter() & ~31) >> 2; + u32 nameTableIndex = ppu.hcounter() >> 5 << hires(); + s32 x = (ppu.hcounter() & ~31) >> 2; - uint hpixel = x << hires(); - uint vpixel = ppu.vcounter(); - uint hscroll = io.hoffset; - uint vscroll = io.voffset; + u32 hpixel = x << hires(); + u32 vpixel = ppu.vcounter(); + u32 hscroll = io.hoffset; + u32 vscroll = io.voffset; if(hires()) { hscroll <<= 1; @@ -46,13 +46,13 @@ auto PPU::Background::fetchNameTable() -> void { bool repeated = false; repeat: - uint hoffset = hpixel + hscroll; - uint voffset = vpixel + vscroll; + u32 hoffset = hpixel + hscroll; + u32 voffset = vpixel + vscroll; if(ppu.io.bgMode == 2 || ppu.io.bgMode == 4 || ppu.io.bgMode == 6) { auto hlookup = ppu.bg3.opt.hoffset; auto vlookup = ppu.bg3.opt.voffset; - uint valid = 13 + id; + u32 valid = 13 + id; if(ppu.io.bgMode == 4) { if(hlookup.bit(valid)) { @@ -68,28 +68,28 @@ auto PPU::Background::fetchNameTable() -> void { } } - uint width = 256 << hires(); - uint hsize = width << io.tileSize << io.screenSize.bit(0); - uint vsize = width << io.tileSize << io.screenSize.bit(1); + u32 width = 256 << hires(); + u32 hsize = width << io.tileSize << io.screenSize.bit(0); + u32 vsize = width << io.tileSize << io.screenSize.bit(1); hoffset &= hsize - 1; voffset &= vsize - 1; - uint vtiles = 3 + io.tileSize; - uint htiles = !hires() ? vtiles : 4; + u32 vtiles = 3 + io.tileSize; + u32 htiles = !hires() ? vtiles : 4; - uint htile = hoffset >> htiles; - uint vtile = voffset >> vtiles; + u32 htile = hoffset >> htiles; + u32 vtile = voffset >> vtiles; - uint hscreen = io.screenSize.bit(0) ? 32 << 5 : 0; - uint vscreen = io.screenSize.bit(1) ? 32 << 5 + io.screenSize.bit(0) : 0; + u32 hscreen = io.screenSize.bit(0) ? 32 << 5 : 0; + u32 vscreen = io.screenSize.bit(1) ? 32 << 5 + io.screenSize.bit(0) : 0; - uint16 offset = (uint5)htile << 0 | (uint5)vtile << 5; + n16 offset = (n5)htile << 0 | (n5)vtile << 5; if(htile & 0x20) offset += hscreen; if(vtile & 0x20) offset += vscreen; - uint16 address = io.screenAddress + offset; - uint16 attributes = ppu.vram[address]; + n16 address = io.screenAddress + offset; + n16 attributes = ppu.vram[address]; auto& tile = tiles[nameTableIndex]; tile.character = attributes.bit(0,9); @@ -101,15 +101,15 @@ auto PPU::Background::fetchNameTable() -> void { if(htiles == 4 && bool(hoffset & 8) != tile.hmirror) tile.character += 1; if(vtiles == 4 && bool(voffset & 8) != tile.vmirror) tile.character += 16; - uint characterMask = ppu.vram.mask >> 3 + io.mode; - uint characterIndex = io.tiledataAddress >> 3 + io.mode; - uint16 origin = tile.character + characterIndex & characterMask; + u32 characterMask = ppu.vram.mask >> 3 + io.mode; + u32 characterIndex = io.tiledataAddress >> 3 + io.mode; + n16 origin = tile.character + characterIndex & characterMask; if(tile.vmirror) voffset ^= 7; tile.address = (origin << 3 + io.mode) + (voffset & 7); - uint paletteOffset = ppu.io.bgMode == 0 ? id << 5 : 0; - uint paletteSize = 2 << io.mode; + u32 paletteOffset = ppu.io.bgMode == 0 ? id << 5 : 0; + u32 paletteSize = 2 << io.mode; tile.palette = paletteOffset + (tile.paletteGroup << paletteSize); nameTableIndex++; @@ -120,40 +120,40 @@ auto PPU::Background::fetchNameTable() -> void { } } -auto PPU::Background::fetchOffset(uint y) -> void { +auto PPU::Background::fetchOffset(u32 y) -> void { if(ppu.vcounter() == 0) return; - uint characterIndex = ppu.hcounter() >> 5 << hires(); - uint x = characterIndex << 3; + u32 characterIndex = ppu.hcounter() >> 5 << hires(); + u32 x = characterIndex << 3; - uint hoffset = x + (io.hoffset & ~7); - uint voffset = y + (io.voffset); + u32 hoffset = x + (io.hoffset & ~7); + u32 voffset = y + (io.voffset); - uint vtiles = 3 + io.tileSize; - uint htiles = !hires() ? vtiles : 4; + u32 vtiles = 3 + io.tileSize; + u32 htiles = !hires() ? vtiles : 4; - uint htile = hoffset >> htiles; - uint vtile = voffset >> vtiles; + u32 htile = hoffset >> htiles; + u32 vtile = voffset >> vtiles; - uint hscreen = io.screenSize.bit(0) ? 32 << 5 : 0; - uint vscreen = io.screenSize.bit(1) ? 32 << 5 + io.screenSize.bit(0) : 0; + u32 hscreen = io.screenSize.bit(0) ? 32 << 5 : 0; + u32 vscreen = io.screenSize.bit(1) ? 32 << 5 + io.screenSize.bit(0) : 0; - uint16 offset = (uint5)htile << 0 | (uint5)vtile << 5; + n16 offset = (n5)htile << 0 | (n5)vtile << 5; if(htile & 0x20) offset += hscreen; if(vtile & 0x20) offset += vscreen; - uint16 address = io.screenAddress + offset; + n16 address = io.screenAddress + offset; if(y == 0) opt.hoffset = ppu.vram[address]; if(y == 8) opt.voffset = ppu.vram[address]; } -auto PPU::Background::fetchCharacter(uint index, bool half) -> void { +auto PPU::Background::fetchCharacter(u32 index, bool half) -> void { if(ppu.vcounter() == 0) return; - uint characterIndex = (ppu.hcounter() >> 5 << hires()) + half; + u32 characterIndex = (ppu.hcounter() >> 5 << hires()) + half; auto& tile = tiles[characterIndex]; - uint16 data = ppu.vram[tile.address + (index << 3)]; + n16 data = ppu.vram[tile.address + (index << 3)]; //reverse bits so that the lowest bit is the left-most pixel if(!tile.hmirror) { @@ -164,8 +164,8 @@ auto PPU::Background::fetchCharacter(uint index, bool half) -> void { //interleave two bitplanes for faster planar decoding later tile.data[index] = ( - ((uint8(data >> 0) * 0x0101010101010101ull & 0x8040201008040201ull) * 0x0102040810204081ull >> 49) & 0x5555 - | ((uint8(data >> 8) * 0x0101010101010101ull & 0x8040201008040201ull) * 0x0102040810204081ull >> 48) & 0xaaaa + ((n8(data >> 0) * 0x0101010101010101ull & 0x8040201008040201ull) * 0x0102040810204081ull >> 49) & 0x5555 + | ((n8(data >> 8) * 0x0101010101010101ull & 0x8040201008040201ull) * 0x0102040810204081ull >> 48) & 0xaaaa ); } @@ -181,7 +181,7 @@ auto PPU::Background::run(bool screen) -> void { if(io.mode == Mode::Mode7) return runMode7(); auto& tile = tiles[renderingIndex]; - uint8 color; + n8 color; if(io.mode >= Mode::BPP2) color.bit(0,1) = tile.data[0] & 3; tile.data[0] >>= 2; if(io.mode >= Mode::BPP4) color.bit(2,3) = tile.data[1] & 3; tile.data[1] >>= 2; if(io.mode >= Mode::BPP8) color.bit(4,5) = tile.data[2] & 3; tile.data[2] >>= 2; @@ -189,11 +189,11 @@ auto PPU::Background::run(bool screen) -> void { Pixel pixel; pixel.priority = tile.priority; - pixel.palette = color ? uint(tile.palette + color) : 0; + pixel.palette = color ? u32(tile.palette + color) : 0; pixel.paletteGroup = tile.paletteGroup; if(++pixelCounter == 0) renderingIndex++; - uint x = ppu.hcounter() - 56 >> 2; + u32 x = ppu.hcounter() - 56 >> 2; if(x == 0 && (!hires() || screen == Screen::Below)) { mosaic.hcounter = ppu.mosaic.size; mosaic.pixel = pixel; diff --git a/ares/sfc/ppu/background.hpp b/ares/sfc/ppu/background.hpp index a972ea6acb..99b9c070a4 100644 --- a/ares/sfc/ppu/background.hpp +++ b/ares/sfc/ppu/background.hpp @@ -1,7 +1,7 @@ struct Background { - struct ID { enum : uint { BG1, BG2, BG3, BG4 }; }; - const uint id; - Background(uint id) : id(id) {} + struct ID { enum : u32 { BG1, BG2, BG3, BG4 }; }; + const u32 id; + Background(u32 id) : id(id) {} //background.cpp auto hires() const -> bool; @@ -9,8 +9,8 @@ struct Background { auto scanline() -> void; auto begin() -> void; auto fetchNameTable() -> void; - auto fetchOffset(uint y) -> void; - auto fetchCharacter(uint index, bool half = 0) -> void; + auto fetchOffset(u32 y) -> void; + auto fetchCharacter(u32 index, bool half = 0) -> void; auto run(bool screen) -> void; auto power() -> void; @@ -19,32 +19,32 @@ struct Background { auto serialize(serializer&) -> void; - struct Mode { enum : uint { BPP2, BPP4, BPP8, Mode7, Inactive }; }; - struct ScreenSize { enum : uint { Size32x32, Size32x64, Size64x32, Size64x64 }; }; - struct TileSize { enum : uint { Size8x8, Size16x16 }; }; - struct Screen { enum : uint { Above, Below }; }; + struct Mode { enum : u32 { BPP2, BPP4, BPP8, Mode7, Inactive }; }; + struct ScreenSize { enum : u32 { Size32x32, Size32x64, Size64x32, Size64x64 }; }; + struct TileSize { enum : u32 { Size8x8, Size16x16 }; }; + struct Screen { enum : u32 { Above, Below }; }; struct IO { - uint2 screenSize; - uint16 screenAddress; + n2 screenSize; + n16 screenAddress; - uint16 tiledataAddress; - uint1 tileSize; + n16 tiledataAddress; + n1 tileSize; - uint8 mode; - uint8 priority[2]; + n8 mode; + n8 priority[2]; - uint1 aboveEnable; - uint1 belowEnable; + n1 aboveEnable; + n1 belowEnable; - uint16 hoffset; - uint16 voffset; + n16 hoffset; + n16 voffset; } io; struct Pixel { - uint8 priority; //0 = none (transparent) - uint8 palette; - uint3 paletteGroup; + n8 priority; //0 = none (transparent) + n8 palette; + n3 paletteGroup; } above, below; struct Output { @@ -53,31 +53,31 @@ struct Background { } output; struct Mosaic { - uint1 enable; - uint16 hcounter; - uint16 hoffset; - Pixel pixel; + n1 enable; + n16 hcounter; + n16 hoffset; + Pixel pixel; } mosaic; struct OffsetPerTile { //set in BG3 only; used by BG1 and BG2 - uint16 hoffset; - uint16 voffset; + n16 hoffset; + n16 voffset; } opt; struct Tile { - uint16 address; - uint10 character; - uint8 palette; - uint3 paletteGroup; - uint8 priority; - uint1 hmirror; - uint1 vmirror; - uint16 data[4]; + n16 address; + n10 character; + n8 palette; + n3 paletteGroup; + n8 priority; + n1 hmirror; + n1 vmirror; + n16 data[4]; } tiles[66]; - uint7 renderingIndex; - uint3 pixelCounter; + n7 renderingIndex; + n3 pixelCounter; friend class PPU; }; diff --git a/ares/sfc/ppu/color.cpp b/ares/sfc/ppu/color.cpp index 1a8795910f..de2b38c2a8 100644 --- a/ares/sfc/ppu/color.cpp +++ b/ares/sfc/ppu/color.cpp @@ -1,18 +1,18 @@ -auto PPU::color(uint32 color) -> uint64 { - uint r = color.bit( 0, 4); - uint g = color.bit( 5, 9); - uint b = color.bit(10,14); - uint l = color.bit(15,18); +auto PPU::color(n32 color) -> n64 { + n32 r = color.bit( 0, 4); + n32 g = color.bit( 5, 9); + n32 b = color.bit(10,14); + n32 l = color.bit(15,18); //luma=0 is not 100% black; but it's much darker than normal linear scaling. //exact effect seems to be analog; requires > 24-bit color depth to represent accurately. - double L = (1.0 + l) / 16.0 * (l ? 1.0 : 0.25); - uint64 R = L * image::normalize(r, 5, 16); - uint64 G = L * image::normalize(g, 5, 16); - uint64 B = L * image::normalize(b, 5, 16); + f64 L = (1.0 + l) / 16.0 * (l ? 1.0 : 0.25); + n64 R = L * image::normalize(r, 5, 16); + n64 G = L * image::normalize(g, 5, 16); + n64 B = L * image::normalize(b, 5, 16); if(colorEmulation->value()) { - static const uint8 gammaRamp[32] = { + static const n8 gammaRamp[32] = { 0x00, 0x01, 0x03, 0x06, 0x0a, 0x0f, 0x15, 0x1c, 0x24, 0x2d, 0x37, 0x42, 0x4e, 0x5b, 0x69, 0x78, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0, diff --git a/ares/sfc/ppu/counter/counter-inline.hpp b/ares/sfc/ppu/counter/counter-inline.hpp index 63197e6579..90b081fb8b 100644 --- a/ares/sfc/ppu/counter/counter-inline.hpp +++ b/ares/sfc/ppu/counter/counter-inline.hpp @@ -7,7 +7,7 @@ alwaysinline auto PPUcounter::tick() -> void { } } -alwaysinline auto PPUcounter::tick(uint clocks) -> void { +alwaysinline auto PPUcounter::tick(u32 clocks) -> void { time.hcounter += clocks; if(time.hcounter >= hperiod()) { last.hperiod = hperiod(); @@ -42,18 +42,18 @@ alwaysinline auto PPUcounter::tickScanline() -> void { alwaysinline auto PPUcounter::interlace() const -> bool { return time.interlace; } alwaysinline auto PPUcounter::field() const -> bool { return time.field; } -alwaysinline auto PPUcounter::vcounter() const -> uint { return time.vcounter; } -alwaysinline auto PPUcounter::hcounter() const -> uint { return time.hcounter; } -alwaysinline auto PPUcounter::vperiod() const -> uint { return time.vperiod; } -alwaysinline auto PPUcounter::hperiod() const -> uint { return time.hperiod; } +alwaysinline auto PPUcounter::vcounter() const -> u32 { return time.vcounter; } +alwaysinline auto PPUcounter::hcounter() const -> u32 { return time.hcounter; } +alwaysinline auto PPUcounter::vperiod() const -> u32 { return time.vperiod; } +alwaysinline auto PPUcounter::hperiod() const -> u32 { return time.hperiod; } -alwaysinline auto PPUcounter::vcounter(uint offset) const -> uint { +alwaysinline auto PPUcounter::vcounter(u32 offset) const -> u32 { if(offset <= hcounter()) return vcounter(); if(vcounter() > 0) return vcounter() - 1; return last.vperiod - 1; } -alwaysinline auto PPUcounter::hcounter(uint offset) const -> uint { +alwaysinline auto PPUcounter::hcounter(u32 offset) const -> u32 { if(offset <= hcounter()) return hcounter() - offset; return hcounter() + last.hperiod - offset; } @@ -68,7 +68,7 @@ alwaysinline auto PPUcounter::hcounter(uint offset) const -> uint { //dot 323 range = {1292, 1294, 1296} //dot 327 range = {1310, 1312, 1314} -alwaysinline auto PPUcounter::hdot() const -> uint { +alwaysinline auto PPUcounter::hdot() const -> u32 { if(hperiod() == 1360) { return hcounter() >> 2; } else { diff --git a/ares/sfc/ppu/counter/counter.hpp b/ares/sfc/ppu/counter/counter.hpp index 544a849acb..8668f0990d 100644 --- a/ares/sfc/ppu/counter/counter.hpp +++ b/ares/sfc/ppu/counter/counter.hpp @@ -12,19 +12,19 @@ struct PPUcounter { auto tick() -> void; - auto tick(uint clocks) -> void; private: + auto tick(u32 clocks) -> void; private: auto tickScanline() -> void; public: auto interlace() const -> bool; auto field() const -> bool; - auto vcounter() const -> uint; - auto hcounter() const -> uint; - auto hdot() const -> uint; private: - auto vperiod() const -> uint; public: - auto hperiod() const -> uint; + auto vcounter() const -> u32; + auto hcounter() const -> u32; + auto hdot() const -> u32; private: + auto vperiod() const -> u32; public: + auto hperiod() const -> u32; - auto vcounter(uint offset) const -> uint; - auto hcounter(uint offset) const -> uint; + auto vcounter(u32 offset) const -> u32; + auto hcounter(u32 offset) const -> u32; auto reset() -> void; auto serialize(serializer&) -> void; @@ -35,14 +35,14 @@ struct PPUcounter { struct { bool interlace = 0; bool field = 0; - uint vperiod = 0; - uint hperiod = 0; - uint vcounter = 0; - uint hcounter = 0; + u32 vperiod = 0; + u32 hperiod = 0; + u32 vcounter = 0; + u32 hcounter = 0; } time; struct { - uint vperiod = 0; - uint hperiod = 0; + u32 vperiod = 0; + u32 hperiod = 0; } last; }; diff --git a/ares/sfc/ppu/dac.cpp b/ares/sfc/ppu/dac.cpp index 205126b405..735d39853b 100644 --- a/ares/sfc/ppu/dac.cpp +++ b/ares/sfc/ppu/dac.cpp @@ -34,10 +34,10 @@ auto PPU::DAC::run() -> void { *line++ = ppu.io.displayBrightness << 15 | (aboveColor); } -auto PPU::DAC::below(bool hires) -> uint16 { +auto PPU::DAC::below(bool hires) -> n16 { if(ppu.io.displayDisable || (!ppu.io.overscan && ppu.vcounter() >= 225)) return 0; - uint priority = 0; + u32 priority = 0; if(ppu.bg1.output.below.priority) { priority = ppu.bg1.output.below.priority; if(io.directColor && (ppu.io.bgMode == 3 || ppu.io.bgMode == 4 || ppu.io.bgMode == 7)) { @@ -65,18 +65,18 @@ auto PPU::DAC::below(bool hires) -> uint16 { if(math.transparent = (priority == 0)) math.below.color = paletteColor(0); if(!hires) return 0; - if(!math.below.colorEnable) return math.above.colorEnable ? math.below.color : (uint15)0; + if(!math.below.colorEnable) return math.above.colorEnable ? math.below.color : (n15)0; return blend( - math.above.colorEnable ? math.below.color : (uint15)0, + math.above.colorEnable ? math.below.color : (n15)0, math.blendMode ? math.above.color : fixedColor() ); } -auto PPU::DAC::above() -> uint16 { +auto PPU::DAC::above() -> n16 { if(ppu.io.displayDisable || (!ppu.io.overscan && ppu.vcounter() >= 225)) return 0; - uint priority = 0; + u32 priority = 0; if(ppu.bg1.output.above.priority) { priority = ppu.bg1.output.above.priority; if(io.directColor && (ppu.io.bgMode == 3 || ppu.io.bgMode == 4 || ppu.io.bgMode == 7)) { @@ -113,7 +113,7 @@ auto PPU::DAC::above() -> uint16 { if(!ppu.window.output.below.colorEnable) math.below.colorEnable = false; math.above.colorEnable = ppu.window.output.above.colorEnable; - if(!math.below.colorEnable) return math.above.colorEnable ? math.above.color : (uint15)0; + if(!math.below.colorEnable) return math.above.colorEnable ? math.above.color : (n15)0; if(io.blendMode && math.transparent) { math.blendMode = false; @@ -124,23 +124,23 @@ auto PPU::DAC::above() -> uint16 { } return blend( - math.above.colorEnable ? math.above.color : (uint15)0, + math.above.colorEnable ? math.above.color : (n15)0, math.blendMode ? math.below.color : fixedColor() ); } -auto PPU::DAC::blend(uint x, uint y) const -> uint15 { +auto PPU::DAC::blend(u32 x, u32 y) const -> n15 { if(!io.colorMode) { //add if(!math.colorHalve) { - uint sum = x + y; - uint carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; + u32 sum = x + y; + u32 carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; return (sum - carry) | (carry - (carry >> 5)); } else { return (x + y - ((x ^ y) & 0x0421)) >> 1; } } else { //sub - uint diff = x - y + 0x8420; - uint borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; + u32 diff = x - y + 0x8420; + u32 borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; if(!math.colorHalve) { return (diff - borrow) & (borrow - (borrow >> 5)); } else { @@ -149,12 +149,12 @@ auto PPU::DAC::blend(uint x, uint y) const -> uint15 { } } -alwaysinline auto PPU::DAC::paletteColor(uint8 palette) const -> uint15 { +alwaysinline auto PPU::DAC::paletteColor(n8 palette) const -> n15 { ppu.latch.cgramAddress = palette; return cgram[palette]; } -alwaysinline auto PPU::DAC::directColor(uint8 palette, uint3 paletteGroup) const -> uint15 { +alwaysinline auto PPU::DAC::directColor(n8 palette, n3 paletteGroup) const -> n15 { //palette = -------- BBGGGRRR //group = -------- -----bgr //output = 0BBb00GG Gg0RRRr0 @@ -163,12 +163,12 @@ alwaysinline auto PPU::DAC::directColor(uint8 palette, uint3 paletteGroup) const + (palette << 2 & 0x001c) + (paletteGroup << 1 & 0x0002); } -alwaysinline auto PPU::DAC::fixedColor() const -> uint15 { +alwaysinline auto PPU::DAC::fixedColor() const -> n15 { return io.colorRed << 0 | io.colorGreen << 5 | io.colorBlue << 10; } auto PPU::DAC::power() -> void { - random.array((uint8*)cgram, sizeof(cgram)); + random.array({cgram, sizeof(cgram)}); for(auto& word : cgram) word &= 0x7fff; io.blendMode = random(); diff --git a/ares/sfc/ppu/dac.hpp b/ares/sfc/ppu/dac.hpp index ea5dded590..e58c853ef4 100644 --- a/ares/sfc/ppu/dac.hpp +++ b/ares/sfc/ppu/dac.hpp @@ -3,41 +3,41 @@ struct DAC { auto run() -> void; auto power() -> void; - auto below(bool hires) -> uint16; - auto above() -> uint16; + auto below(bool hires) -> n16; + auto above() -> n16; - auto blend(uint x, uint y) const -> uint15; - auto paletteColor(uint8 palette) const -> uint15; - auto directColor(uint8 palette, uint3 paletteGroup) const -> uint15; - auto fixedColor() const -> uint15; + auto blend(u32 x, u32 y) const -> n15; + auto paletteColor(n8 palette) const -> n15; + auto directColor(n8 palette, n3 paletteGroup) const -> n15; + auto fixedColor() const -> n15; auto serialize(serializer&) -> void; - uint15 cgram[256]; + n15 cgram[256]; struct IO { - uint1 directColor; - uint1 blendMode; + n1 directColor; + n1 blendMode; struct Layer { - uint1 colorEnable; + n1 colorEnable; } bg1, bg2, bg3, bg4, obj, back; - uint1 colorHalve; - uint1 colorMode; + n1 colorHalve; + n1 colorMode; - uint5 colorRed; - uint5 colorGreen; - uint5 colorBlue; + n5 colorRed; + n5 colorGreen; + n5 colorBlue; } io; struct Math { struct Screen { - uint15 color; - uint1 colorEnable; + n15 color; + n1 colorEnable; } above, below; - uint1 transparent; - uint1 blendMode; - uint1 colorHalve; + n1 transparent; + n1 blendMode; + n1 colorHalve; } math; friend class PPU; diff --git a/ares/sfc/ppu/debugger.cpp b/ares/sfc/ppu/debugger.cpp index 194cfddb9d..52df1019df 100644 --- a/ares/sfc/ppu/debugger.cpp +++ b/ares/sfc/ppu/debugger.cpp @@ -29,15 +29,15 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles2bpp = parent->append("2 BPP Tiles"); graphics.tiles2bpp->setSize(512, 512); graphics.tiles2bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 512); - for(uint tileY : range(64)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 3; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y]; - for(uint x : range(8)) { - uint2 color; + for(u32 tileY : range(64)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 3; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y]; + for(u32 x : range(8)) { + n2 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); output[(tileY * 8 + y) * 512 + (tileX * 8 + x)] = color * 0x555555; @@ -51,16 +51,16 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles4bpp = parent->append("4 BPP Tiles"); graphics.tiles4bpp->setSize(512, 256); graphics.tiles4bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 256); - for(uint tileY : range(32)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 4; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y + 0]; - uint16 d1 = ppu.vram.data[address + y + 8]; - for(uint x : range(8)) { - uint4 color; + for(u32 tileY : range(32)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 4; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y + 0]; + n16 d1 = ppu.vram.data[address + y + 8]; + for(u32 x : range(8)) { + n4 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); color.bit(2) = d1.bit( 7 - x); @@ -76,18 +76,18 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tiles8bpp = parent->append("8 BPP Tiles"); graphics.tiles8bpp->setSize(512, 128); graphics.tiles8bpp->setCapture([&]() -> vector { - vector output; + vector output; output.resize(512 * 128); - for(uint tileY : range(16)) { - for(uint tileX : range(64)) { - uint15 address = tileY * 64 + tileX << 5; - for(uint y : range(8)) { - uint16 d0 = ppu.vram.data[address + y + 0]; - uint16 d1 = ppu.vram.data[address + y + 8]; - uint16 d2 = ppu.vram.data[address + y + 16]; - uint16 d3 = ppu.vram.data[address + y + 24]; - for(uint x : range(8)) { - uint8 color; + for(u32 tileY : range(16)) { + for(u32 tileX : range(64)) { + n15 address = tileY * 64 + tileX << 5; + for(u32 y : range(8)) { + n16 d0 = ppu.vram.data[address + y + 0]; + n16 d1 = ppu.vram.data[address + y + 8]; + n16 d2 = ppu.vram.data[address + y + 16]; + n16 d3 = ppu.vram.data[address + y + 24]; + for(u32 x : range(8)) { + n8 color; color.bit(0) = d0.bit( 7 - x); color.bit(1) = d0.bit(15 - x); color.bit(2) = d1.bit( 7 - x); @@ -107,14 +107,14 @@ auto PPU::Debugger::load(Node::Object parent) -> void { graphics.tilesMode7 = parent->append("Mode 7 Tiles"); graphics.tilesMode7->setSize(128, 128); graphics.tilesMode7->setCapture([&]() -> vector { - vector output; + vector output; output.resize(128 * 128); - for(uint tileY : range(16)) { - for(uint tileX : range(16)) { - uint15 address = tileY * 16 + tileX << 6; - for(uint y : range(8)) { - for(uint x : range(8)) { - uint8 color = ppu.vram.data[address + y * 8 + x].byte(1); + for(u32 tileY : range(16)) { + for(u32 tileX : range(16)) { + n15 address = tileY * 16 + tileX << 6; + for(u32 y : range(8)) { + for(u32 x : range(8)) { + n8 color = ppu.vram.data[address + y * 8 + x].byte(1); output[(tileY * 8 + y) * 128 + (tileX * 8 + x)] = color << 16 | color << 8 | color << 0; } } diff --git a/ares/sfc/ppu/io.cpp b/ares/sfc/ppu/io.cpp index adb4f1cd79..9659f9b34c 100644 --- a/ares/sfc/ppu/io.cpp +++ b/ares/sfc/ppu/io.cpp @@ -5,8 +5,8 @@ auto PPU::latchCounters() -> void { latch.counters = 1; } -alwaysinline auto PPU::addressVRAM() const -> uint16 { - uint16 address = io.vramAddress; +alwaysinline auto PPU::addressVRAM() const -> n16 { + n16 address = io.vramAddress; switch(io.vramMapping) { case 0: return address; case 1: return address.bit( 8,15) << 8 | address.bit(0,4) << 3 | address.bit(5,7); @@ -16,19 +16,19 @@ alwaysinline auto PPU::addressVRAM() const -> uint16 { unreachable; } -alwaysinline auto PPU::readVRAM() -> uint16 { +alwaysinline auto PPU::readVRAM() -> n16 { if(!io.displayDisable && vcounter() < vdisp()) return 0x0000; auto address = addressVRAM(); return vram[address]; } -alwaysinline auto PPU::writeVRAM(uint1 byte, uint8 data) -> void { +alwaysinline auto PPU::writeVRAM(n1 byte, n8 data) -> void { if(!io.displayDisable && vcounter() < vdisp()) return; auto address = addressVRAM(); vram[address].byte(byte) = data; } -alwaysinline auto PPU::readOAM(uint10 address) -> uint8 { +alwaysinline auto PPU::readOAM(n10 address) -> n8 { if(!io.displayDisable && vcounter() < vdisp()) { if(address.bit(9) == 0) return obj.oam.read(0x000 | latch.oamAddress << 2 | address & 1); if(address.bit(9) == 1) return obj.oam.read(0x200 | latch.oamAddress >> 2); @@ -36,7 +36,7 @@ alwaysinline auto PPU::readOAM(uint10 address) -> uint8 { return obj.oam.read(address); } -alwaysinline auto PPU::writeOAM(uint10 address, uint8 data) -> void { +alwaysinline auto PPU::writeOAM(n10 address, n8 data) -> void { if(!io.displayDisable && vcounter() < vdisp()) { if(address.bit(9) == 0) return obj.oam.write(0x000 | latch.oamAddress << 2 | address & 1, data); if(address.bit(9) == 1) return obj.oam.write(0x200 | latch.oamAddress >> 2, data); @@ -44,7 +44,7 @@ alwaysinline auto PPU::writeOAM(uint10 address, uint8 data) -> void { return obj.oam.write(address, data); } -alwaysinline auto PPU::readCGRAM(uint1 byte, uint8 address) -> uint8 { +alwaysinline auto PPU::readCGRAM(n1 byte, n8 address) -> n8 { if(!io.displayDisable && vcounter() > 0 && vcounter() < vdisp() && hcounter() >= 88 && hcounter() < 1096 @@ -52,7 +52,7 @@ alwaysinline auto PPU::readCGRAM(uint1 byte, uint8 address) -> uint8 { return dac.cgram[address].byte(byte); } -alwaysinline auto PPU::writeCGRAM(uint8 address, uint15 data) -> void { +alwaysinline auto PPU::writeCGRAM(n8 address, n15 data) -> void { if(!io.displayDisable && vcounter() > 0 && vcounter() < vdisp() && hcounter() >= 88 && hcounter() < 1096 @@ -60,10 +60,10 @@ alwaysinline auto PPU::writeCGRAM(uint8 address, uint15 data) -> void { dac.cgram[address] = data; } -auto PPU::readIO(uint24 address, uint8 data) -> uint8 { +auto PPU::readIO(n24 address, n8 data) -> n8 { cpu.synchronize(ppu); - switch((uint16)address) { + switch((n16)address) { case 0x2104: case 0x2105: case 0x2106: case 0x2108: case 0x2109: case 0x210a: case 0x2114: case 0x2115: @@ -75,19 +75,19 @@ auto PPU::readIO(uint24 address, uint8 data) -> uint8 { //MPYL case 0x2134: { - uint24 result = (int16)io.m7a * (int8)(io.m7b >> 8); + n24 result = (i16)io.m7a * (i8)(io.m7b >> 8); return ppu1.mdr = result.byte(0); } //MPYM case 0x2135: { - uint24 result = (int16)io.m7a * (int8)(io.m7b >> 8); + n24 result = (i16)io.m7a * (i8)(io.m7b >> 8); return ppu1.mdr = result.byte(1); } //MPYH case 0x2136: { - uint24 result = (int16)io.m7a * (int8)(io.m7b >> 8); + n24 result = (i16)io.m7a * (i8)(io.m7b >> 8); return ppu1.mdr = result.byte(2); } @@ -184,10 +184,10 @@ auto PPU::readIO(uint24 address, uint8 data) -> uint8 { return data; } -auto PPU::writeIO(uint24 address, uint8 data) -> void { +auto PPU::writeIO(n24 address, n8 data) -> void { cpu.synchronize(ppu); - switch((uint16)address) { + switch((n16)address) { //INIDISP case 0x2100: { @@ -222,8 +222,8 @@ auto PPU::writeIO(uint24 address, uint8 data) -> void { //OAMDATA case 0x2104: { - uint1 latchBit = io.oamAddress.bit(0); - uint10 address = io.oamAddress++; + n1 latchBit = io.oamAddress.bit(0); + n10 address = io.oamAddress++; if(latchBit == 0) latch.oam = data; if(address.bit(9)) { writeOAM(address, data); @@ -372,7 +372,7 @@ auto PPU::writeIO(uint24 address, uint8 data) -> void { //VMAIN case 0x2115: { - static const uint size[4] = {1, 32, 128, 128}; + static constexpr u32 size[4] = {1, 32, 128, 128}; io.vramIncrementSize = size[data.bit(0,1)]; io.vramMapping = data.bit(2,3); io.vramIncrementMode = data.bit(7); diff --git a/ares/sfc/ppu/main.cpp b/ares/sfc/ppu/main.cpp index 15645b4637..76beb73de6 100644 --- a/ares/sfc/ppu/main.cpp +++ b/ares/sfc/ppu/main.cpp @@ -78,7 +78,7 @@ auto PPU::cycleObjectEvaluate() -> void { obj.evaluate(hcounter() >> 3); } -template +template auto PPU::cycleBackgroundFetch() -> void { switch(io.bgMode) { case 0: @@ -184,7 +184,7 @@ auto PPU::cycleRenderPixel() -> void { dac.run(); } -template +template auto PPU::cycle() -> void { if constexpr(Cycle >= 0 && Cycle <= 1016 && (Cycle - 0) % 8 == 0) cycleObjectEvaluate(); if constexpr(Cycle >= 0 && Cycle <= 1054 && (Cycle - 0) % 4 == 0) cycleBackgroundFetch<(Cycle - 0) / 4 & 7>(); diff --git a/ares/sfc/ppu/mode7.cpp b/ares/sfc/ppu/mode7.cpp index 5cd320a760..d51d35d9a7 100644 --- a/ares/sfc/ppu/mode7.cpp +++ b/ares/sfc/ppu/mode7.cpp @@ -1,16 +1,16 @@ auto PPU::Background::runMode7() -> void { - int a = (int16)ppu.io.m7a; - int b = (int16)ppu.io.m7b; - int c = (int16)ppu.io.m7c; - int d = (int16)ppu.io.m7d; + s32 a = (i16)ppu.io.m7a; + s32 b = (i16)ppu.io.m7b; + s32 c = (i16)ppu.io.m7c; + s32 d = (i16)ppu.io.m7d; - int hcenter = (int13)ppu.io.m7x; - int vcenter = (int13)ppu.io.m7y; - int hoffset = (int13)ppu.io.hoffsetMode7; - int voffset = (int13)ppu.io.voffsetMode7; + s32 hcenter = (i13)ppu.io.m7x; + s32 vcenter = (i13)ppu.io.m7y; + s32 hoffset = (i13)ppu.io.hoffsetMode7; + s32 voffset = (i13)ppu.io.voffsetMode7; - uint x = mosaic.hoffset; - uint y = ppu.vcounter(); + u32 x = mosaic.hoffset; + u32 y = ppu.vcounter(); if(ppu.bg1.mosaic.enable) y -= ppu.mosaic.voffset(); //BG2 vertical mosaic uses BG1 mosaic enable if(!mosaic.enable) { @@ -24,24 +24,24 @@ auto PPU::Background::runMode7() -> void { if(ppu.io.vflipMode7) y = 255 - y; //13-bit sign extend: --s---nnnnnnnnnn -> ssssssnnnnnnnnnn - auto clip = [](int n) -> int { return n & 0x2000 ? (n | ~1023) : (n & 1023); }; - int originX = (a * clip(hoffset - hcenter) & ~63) + (b * clip(voffset - vcenter) & ~63) + (b * y & ~63) + (hcenter << 8); - int originY = (c * clip(hoffset - hcenter) & ~63) + (d * clip(voffset - vcenter) & ~63) + (d * y & ~63) + (vcenter << 8); + auto clip = [](s32 n) -> s32 { return n & 0x2000 ? (n | ~1023) : (n & 1023); }; + s32 originX = (a * clip(hoffset - hcenter) & ~63) + (b * clip(voffset - vcenter) & ~63) + (b * y & ~63) + (hcenter << 8); + s32 originY = (c * clip(hoffset - hcenter) & ~63) + (d * clip(voffset - vcenter) & ~63) + (d * y & ~63) + (vcenter << 8); - int pixelX = originX + a * x >> 8; - int pixelY = originY + c * x >> 8; - uint16 paletteAddress = (uint3)pixelY << 3 | (uint3)pixelX; + s32 pixelX = originX + a * x >> 8; + s32 pixelY = originY + c * x >> 8; + n16 paletteAddress = (n3)pixelY << 3 | (n3)pixelX; - uint7 tileX = pixelX >> 3; - uint7 tileY = pixelY >> 3; - uint16 tileAddress = tileY << 7 | tileX; + n7 tileX = pixelX >> 3; + n7 tileY = pixelY >> 3; + n16 tileAddress = tileY << 7 | tileX; bool outOfBounds = (pixelX | pixelY) & ~1023; - uint8 tile = ppu.io.repeatMode7 == 3 && outOfBounds ? 0 : ppu.vram[tileAddress] >> 0; - uint8 palette = ppu.io.repeatMode7 == 2 && outOfBounds ? 0 : ppu.vram[tile << 6 | paletteAddress] >> 8; + n8 tile = ppu.io.repeatMode7 == 3 && outOfBounds ? 0 : ppu.vram[tileAddress] >> 0; + n8 palette = ppu.io.repeatMode7 == 2 && outOfBounds ? 0 : ppu.vram[tile << 6 | paletteAddress] >> 8; - uint priority; + u32 priority; if(id == ID::BG1) { priority = io.priority[0]; } else if(id == ID::BG2) { diff --git a/ares/sfc/ppu/mosaic.cpp b/ares/sfc/ppu/mosaic.cpp index b0f596a713..ead390e9fb 100644 --- a/ares/sfc/ppu/mosaic.cpp +++ b/ares/sfc/ppu/mosaic.cpp @@ -6,7 +6,7 @@ alwaysinline auto PPU::Mosaic::enable() const -> bool { return false; } -alwaysinline auto PPU::Mosaic::voffset() const -> uint { +alwaysinline auto PPU::Mosaic::voffset() const -> u32 { return size - vcounter; } @@ -21,6 +21,6 @@ auto PPU::Mosaic::scanline() -> void { } auto PPU::Mosaic::power() -> void { - size = (uint4)random() + 1; + size = (n4)random() + 1; vcounter = 0; } diff --git a/ares/sfc/ppu/mosaic.hpp b/ares/sfc/ppu/mosaic.hpp index 957d74e683..88ae090cb7 100644 --- a/ares/sfc/ppu/mosaic.hpp +++ b/ares/sfc/ppu/mosaic.hpp @@ -1,13 +1,13 @@ struct Mosaic { //mosaic.cpp auto enable() const -> bool; - auto voffset() const -> uint; + auto voffset() const -> u32; auto scanline() -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint5 size; - uint5 vcounter; + n5 size; + n5 vcounter; }; diff --git a/ares/sfc/ppu/oam.cpp b/ares/sfc/ppu/oam.cpp index 275fe7e66d..183b33f683 100644 --- a/ares/sfc/ppu/oam.cpp +++ b/ares/sfc/ppu/oam.cpp @@ -1,8 +1,8 @@ -auto PPU::OAM::read(uint10 address) -> uint8 { - uint8 data; +auto PPU::OAM::read(n10 address) -> n8 { + n8 data; if(!address.bit(9)) { - uint7 n = address >> 2; //object# + n7 n = address >> 2; //object# address &= 3; if(address == 0) return object[n].x.bit(0,7); if(address == 1) return object[n].y; @@ -15,7 +15,7 @@ auto PPU::OAM::read(uint10 address) -> uint8 { return data; } - uint7 n = (uint5)address << 2; //object# + n7 n = (n5)address << 2; //object# data.bit(0) = object[n + 0].x.bit(8); data.bit(1) = object[n + 0].size; data.bit(2) = object[n + 1].x.bit(8); @@ -27,9 +27,9 @@ auto PPU::OAM::read(uint10 address) -> uint8 { return data; } -auto PPU::OAM::write(uint10 address, uint8 data) -> void { +auto PPU::OAM::write(n10 address, n8 data) -> void { if(!address.bit(9)) { - uint7 n = address >> 2; //object# + n7 n = address >> 2; //object# address &= 3; if(address == 0) { object[n].x.bit(0,7) = data; return; } if(address == 1) { object[n].y = data; return; } @@ -40,7 +40,7 @@ auto PPU::OAM::write(uint10 address, uint8 data) -> void { object[n].hflip = data.bit(6); object[n].vflip = data.bit(7); } else { - uint7 n = (uint5)address << 2; //object# + n7 n = (n5)address << 2; //object# object[n + 0].x.bit(8) = data.bit(0); object[n + 0].size = data.bit(1); object[n + 1].x.bit(8) = data.bit(2); @@ -52,23 +52,23 @@ auto PPU::OAM::write(uint10 address, uint8 data) -> void { } } -alwaysinline auto PPU::OAM::Object::width() const -> uint { +alwaysinline auto PPU::OAM::Object::width() const -> u32 { if(size == 0) { - static const uint width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; + static constexpr u32 width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; return width[ppu.obj.io.baseSize]; } else { - static const uint width[] = {16, 32, 64, 32, 64, 64, 32, 32}; + static constexpr u32 width[] = {16, 32, 64, 32, 64, 64, 32, 32}; return width[ppu.obj.io.baseSize]; } } -alwaysinline auto PPU::OAM::Object::height() const -> uint { +alwaysinline auto PPU::OAM::Object::height() const -> u32 { if(size == 0) { if(ppu.obj.io.interlace && ppu.obj.io.baseSize >= 6) return 16; //hardware quirk - static const uint height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; + static constexpr u32 height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; return height[ppu.obj.io.baseSize]; } else { - static const uint height[] = {16, 32, 64, 32, 64, 64, 64, 32}; + static constexpr u32 height[] = {16, 32, 64, 32, 64, 64, 64, 32}; return height[ppu.obj.io.baseSize]; } } diff --git a/ares/sfc/ppu/oam.hpp b/ares/sfc/ppu/oam.hpp index 09d86a0952..be4ea167df 100644 --- a/ares/sfc/ppu/oam.hpp +++ b/ares/sfc/ppu/oam.hpp @@ -1,19 +1,19 @@ struct OAM { - auto read(uint10 address) -> uint8; - auto write(uint10 address, uint8 data) -> void; + auto read(n10 address) -> n8; + auto write(n10 address, n8 data) -> void; struct Object { auto width() const -> uint; auto height() const -> uint; - uint9 x; - uint8 y; - uint8 character; - uint1 nameselect; - uint1 vflip; - uint1 hflip; - uint2 priority; - uint3 palette; - uint1 size; + n9 x; + n8 y; + n8 character; + n1 nameselect; + n1 vflip; + n1 hflip; + n2 priority; + n3 palette; + n1 size; } object[128]; }; diff --git a/ares/sfc/ppu/object.cpp b/ares/sfc/ppu/object.cpp index 86b1334caa..b1e2c106f2 100644 --- a/ares/sfc/ppu/object.cpp +++ b/ares/sfc/ppu/object.cpp @@ -25,21 +25,21 @@ auto PPU::Object::scanline() -> void { auto oamItem = t.item[t.active]; auto oamTile = t.tile[t.active]; - for(uint n : range(32)) oamItem[n].valid = false; - for(uint n : range(34)) oamTile[n].valid = false; + for(u32 n : range(32)) oamItem[n].valid = false; + for(u32 n : range(34)) oamTile[n].valid = false; if(t.y == ppu.vdisp() && !ppu.io.displayDisable) addressReset(); if(t.y >= ppu.vdisp() - 1 || ppu.io.displayDisable) return; } -auto PPU::Object::evaluate(uint7 index) -> void { +auto PPU::Object::evaluate(n7 index) -> void { if(ppu.io.displayDisable) return; if(t.itemCount > 32) return; auto oamItem = t.item[t.active]; auto oamTile = t.tile[t.active]; - uint7 sprite = latch.firstSprite + index; + n7 sprite = latch.firstSprite + index; if(!onScanline(oam.object[sprite])) return; ppu.latch.oamAddress = sprite; @@ -50,7 +50,7 @@ auto PPU::Object::evaluate(uint7 index) -> void { auto PPU::Object::onScanline(PPU::OAM::Object& sprite) -> bool { if(sprite.x > 256 && sprite.x + sprite.width() - 1 < 512) return false; - uint height = sprite.height() >> io.interlace; + u32 height = sprite.height() >> io.interlace; if(t.y >= sprite.y && t.y < sprite.y + height) return true; if(sprite.y + height >= 256 && t.y < (sprite.y + height & 255)) return true; return false; @@ -61,16 +61,16 @@ auto PPU::Object::run() -> void { output.below.priority = 0; auto oamTile = t.tile[!t.active]; - uint x = t.x++; + u32 x = t.x++; - for(uint n : range(34)) { + for(u32 n : range(34)) { const auto& tile = oamTile[n]; if(!tile.valid) break; - int px = x - (int9)tile.x; + s32 px = x - (i9)tile.x; if(px & ~7) continue; - uint color = 0, shift = tile.hflip ? px : 7 - px; + u32 color = 0, shift = tile.hflip ? px : 7 - px; color += tile.data >> shift + 0 & 1; color += tile.data >> shift + 7 & 2; color += tile.data >> shift + 14 & 4; @@ -94,7 +94,7 @@ auto PPU::Object::fetch() -> void { auto oamItem = t.item[t.active]; auto oamTile = t.tile[t.active]; - for(uint i : reverse(range(32))) { + for(u32 i : reverse(range(32))) { if(!oamItem[i].valid) continue; if(ppu.io.displayDisable || ppu.vcounter() >= ppu.vdisp() - 1) { @@ -105,9 +105,9 @@ auto PPU::Object::fetch() -> void { ppu.latch.oamAddress = oamItem[i].index; const auto& sprite = oam.object[ppu.latch.oamAddress]; - uint tileWidth = sprite.width() >> 3; - int x = sprite.x; - int y = t.y - sprite.y & 255; + u32 tileWidth = sprite.width() >> 3; + s32 x = sprite.x; + s32 y = t.y - sprite.y & 255; if(io.interlace) y <<= 1; if(sprite.vflip) { @@ -127,26 +127,26 @@ auto PPU::Object::fetch() -> void { x &= 511; y &= 255; - uint16 tiledataAddress = io.tiledataAddress; + n16 tiledataAddress = io.tiledataAddress; if(sprite.nameselect) tiledataAddress += 1 + io.nameselect << 12; - uint16 chrx = sprite.character.bit(0,3); - uint16 chry = (sprite.character.bit(4,7) + (y >> 3) & 15) << 4; + n16 chrx = sprite.character.bit(0,3); + n16 chry = (sprite.character.bit(4,7) + (y >> 3) & 15) << 4; - for(uint tx : range(tileWidth)) { - uint sx = x + (tx << 3) & 511; + for(u32 tx : range(tileWidth)) { + u32 sx = x + (tx << 3) & 511; if(x != 256 && sx >= 256 && sx + 7 < 512) continue; if(t.tileCount++ >= 34) break; - uint n = t.tileCount - 1; + u32 n = t.tileCount - 1; oamTile[n].valid = true; oamTile[n].x = sx; oamTile[n].priority = sprite.priority; oamTile[n].palette = 128 + (sprite.palette << 4); oamTile[n].hflip = sprite.hflip; - uint mx = !sprite.hflip ? tx : tileWidth - 1 - tx; - uint pos = tiledataAddress + ((chry + (chrx + mx & 15)) << 4); - uint16 address = (pos & 0xfff0) + (y & 7); + u32 mx = !sprite.hflip ? tx : tileWidth - 1 - tx; + u32 pos = tiledataAddress + ((chry + (chrx + mx & 15)) << 4); + n16 address = (pos & 0xfff0) + (y & 7); if(!ppu.io.displayDisable) oamTile[n].data.bit( 0,15) = ppu.vram[address + 0]; @@ -182,12 +182,12 @@ auto PPU::Object::power() -> void { t.tileCount = 0; t.active = 0; - for(uint p : range(2)) { - for(uint n : range(32)) { + for(u32 p : range(2)) { + for(u32 n : range(32)) { t.item[p][n].valid = false; t.item[p][n].index = 0; } - for(uint n : range(34)) { + for(u32 n : range(34)) { t.tile[p][n].valid = false; t.tile[p][n].x = 0; t.tile[p][n].priority = 0; diff --git a/ares/sfc/ppu/object.hpp b/ares/sfc/ppu/object.hpp index f1126be83d..48d92908f9 100644 --- a/ares/sfc/ppu/object.hpp +++ b/ares/sfc/ppu/object.hpp @@ -3,7 +3,7 @@ struct Object { auto setFirstSprite() -> void; auto frame() -> void; auto scanline() -> void; - auto evaluate(uint7 index) -> void; + auto evaluate(n7 index) -> void; auto run() -> void; auto fetch() -> void; auto power() -> void; @@ -15,45 +15,45 @@ struct Object { OAM oam; struct IO { - uint1 aboveEnable; - uint1 belowEnable; - uint1 interlace; + n1 aboveEnable; + n1 belowEnable; + n1 interlace; - uint16 tiledataAddress; - uint2 nameselect; - uint3 baseSize; - uint7 firstSprite; + n16 tiledataAddress; + n2 nameselect; + n3 baseSize; + n7 firstSprite; - uint8 priority[4]; + n8 priority[4]; - uint1 rangeOver; - uint1 timeOver; + n1 rangeOver; + n1 timeOver; } io; struct Latch { - uint7 firstSprite; + n7 firstSprite; } latch; struct Item { - uint1 valid; - uint7 index; + n1 valid; + n7 index; }; struct Tile { - uint1 valid; - uint9 x; - uint2 priority; - uint8 palette; - uint1 hflip; - uint32 data; + n1 valid; + n9 x; + n2 priority; + n8 palette; + n1 hflip; + n32 data; }; struct State { - uint x; - uint y; + u32 x; + u32 y; - uint itemCount; - uint tileCount; + u32 itemCount; + u32 tileCount; bool active; Item item[2][32]; @@ -62,8 +62,8 @@ struct Object { struct Output { struct Pixel { - uint8 priority; //0 = none (transparent) - uint8 palette; + n8 priority; //0 = none (transparent) + n8 palette; } above, below; } output; diff --git a/ares/sfc/ppu/ppu.cpp b/ares/sfc/ppu/ppu.cpp index 515e376864..cb0176bfc0 100644 --- a/ares/sfc/ppu/ppu.cpp +++ b/ares/sfc/ppu/ppu.cpp @@ -71,8 +71,8 @@ auto PPU::unload() -> void { } auto PPU::map() -> void { - function reader{&PPU::readIO, this}; - function writer{&PPU::writeIO, this}; + function reader{&PPU::readIO, this}; + function writer{&PPU::writeIO, this}; bus.map(reader, writer, "00-3f,80-bf:2100-213f"); } @@ -82,7 +82,7 @@ inline auto PPU::step() -> void { Thread::synchronize(cpu); } -inline auto PPU::step(uint clocks) -> void { +inline auto PPU::step(u32 clocks) -> void { clocks >>= 1; while(clocks--) { tick(2); @@ -96,7 +96,7 @@ auto PPU::power(bool reset) -> void { PPUcounter::reset(); screen->power(); - if(!reset) random.array((uint8*)vram.data, sizeof(vram.data)); + if(!reset) random.array({vram.data, sizeof(vram.data)}); ppu1.version = versionPPU1->value(); ppu1.mdr = random.bias(0xff); @@ -104,7 +104,7 @@ auto PPU::power(bool reset) -> void { ppu2.version = versionPPU2->value(); ppu2.mdr = random.bias(0xff); - vram.mask = vramSize->value() / sizeof(uint16) - 1; + vram.mask = vramSize->value() / sizeof(n16) - 1; if(vram.mask != 0xffff) vram.mask = 0x7fff; latch.vram = random(); diff --git a/ares/sfc/ppu/ppu.hpp b/ares/sfc/ppu/ppu.hpp index cbc268b19b..3c4c5aebdf 100644 --- a/ares/sfc/ppu/ppu.hpp +++ b/ares/sfc/ppu/ppu.hpp @@ -36,7 +36,7 @@ struct PPU : Thread, PPUcounter { auto interlace() const -> bool { return self.interlace; } auto overscan() const -> bool { return self.overscan; } - auto vdisp() const -> uint { return self.vdisp; } + auto vdisp() const -> u32 { return self.vdisp; } //ppu.cpp auto load(Node::Object) -> void; @@ -48,18 +48,18 @@ struct PPU : Thread, PPUcounter { //main.cpp auto main() -> void; noinline auto cycleObjectEvaluate() -> void; - template noinline auto cycleBackgroundFetch() -> void; + template noinline auto cycleBackgroundFetch() -> void; noinline auto cycleBackgroundBegin() -> void; noinline auto cycleBackgroundBelow() -> void; noinline auto cycleBackgroundAbove() -> void; noinline auto cycleRenderPixel() -> void; - template auto cycle() -> void; + template auto cycle() -> void; //io.cpp auto latchCounters() -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; @@ -67,120 +67,120 @@ struct PPU : Thread, PPUcounter { private: //ppu.cpp auto step() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; //io.cpp - auto addressVRAM() const -> uint16; - auto readVRAM() -> uint16; - auto writeVRAM(uint1 byte, uint8 data) -> void; - auto readOAM(uint10 address) -> uint8; - auto writeOAM(uint10 address, uint8 data) -> void; - auto readCGRAM(uint1 byte, uint8 address) -> uint8; - auto writeCGRAM(uint8 address, uint15 data) -> void; - auto readIO(uint24 address, uint8 data) -> uint8; - auto writeIO(uint24 address, uint8 data) -> void; + auto addressVRAM() const -> n16; + auto readVRAM() -> n16; + auto writeVRAM(n1 byte, n8 data) -> void; + auto readOAM(n10 address) -> n8; + auto writeOAM(n10 address, n8 data) -> void; + auto readCGRAM(n1 byte, n8 address) -> n8; + auto writeCGRAM(n8 address, n15 data) -> void; + auto readIO(n24 address, n8 data) -> n8; + auto writeIO(n24 address, n8 data) -> void; auto updateVideoMode() -> void; struct VRAM { - auto& operator[](uint address) { return data[address & mask]; } - uint16 data[64_KiB]; - uint16 mask = 0x7fff; + auto& operator[](u32 address) { return data[address & mask]; } + n16 data[64_KiB]; + n16 mask = 0x7fff; } vram; struct { - uint1 interlace; - uint1 overscan; - uint9 vdisp; + n1 interlace; + n1 overscan; + n9 vdisp; } self; struct { - uint4 version; - uint8 mdr; + n4 version; + n8 mdr; } ppu1, ppu2; struct Latches { - uint16 vram; - uint8 oam; - uint8 cgram; - uint8 bgofsPPU1; - uint3 bgofsPPU2; - uint8 mode7; - uint1 counters; - uint1 hcounter; - uint1 vcounter; - - uint10 oamAddress; - uint8 cgramAddress; + n16 vram; + n8 oam; + n8 cgram; + n8 bgofsPPU1; + n3 bgofsPPU2; + n8 mode7; + n1 counters; + n1 hcounter; + n1 vcounter; + + n10 oamAddress; + n8 cgramAddress; } latch; struct IO { //$2100 INIDISP - uint4 displayBrightness; - uint1 displayDisable; + n4 displayBrightness; + n1 displayDisable; //$2102 OAMADDL //$2103 OAMADDH - uint10 oamBaseAddress; - uint10 oamAddress; - uint1 oamPriority; + n10 oamBaseAddress; + n10 oamAddress; + n1 oamPriority; //$2105 BGMODE - uint3 bgMode; - uint1 bgPriority; + n3 bgMode; + n1 bgPriority; //$210d BG1HOFS - uint16 hoffsetMode7; + n16 hoffsetMode7; //$210e BG1VOFS - uint16 voffsetMode7; + n16 voffsetMode7; //$2115 VMAIN - uint8 vramIncrementSize; - uint2 vramMapping; - uint1 vramIncrementMode; + n8 vramIncrementSize; + n2 vramMapping; + n1 vramIncrementMode; //$2116 VMADDL //$2117 VMADDH - uint16 vramAddress; + n16 vramAddress; //$211a M7SEL - uint1 hflipMode7; - uint1 vflipMode7; - uint2 repeatMode7; + n1 hflipMode7; + n1 vflipMode7; + n2 repeatMode7; //$211b M7A - uint16 m7a; + n16 m7a; //$211c M7B - uint16 m7b; + n16 m7b; //$211d M7C - uint16 m7c; + n16 m7c; //$211e M7D - uint16 m7d; + n16 m7d; //$211f M7X - uint16 m7x; + n16 m7x; //$2120 M7Y - uint16 m7y; + n16 m7y; //$2121 CGADD - uint8 cgramAddress; - uint1 cgramAddressLatch; + n8 cgramAddress; + n1 cgramAddressLatch; //$2133 SETINI - uint1 interlace; - uint1 overscan; - uint1 pseudoHires; - uint1 extbg; + n1 interlace; + n1 overscan; + n1 pseudoHires; + n1 extbg; //$213c OPHCT - uint16 hcounter; + n16 hcounter; //$213d OPVCT - uint16 vcounter; + n16 vcounter; } io; #include "mosaic.hpp" diff --git a/ares/sfc/ppu/serialization.cpp b/ares/sfc/ppu/serialization.cpp index 5d16223d67..79a56bc428 100644 --- a/ares/sfc/ppu/serialization.cpp +++ b/ares/sfc/ppu/serialization.cpp @@ -6,7 +6,7 @@ auto PPU::serialize(serializer& s) -> void { s(self.overscan); s(self.vdisp); - s(array_span{vram.data, vram.mask + 1}); + s(array_span{vram.data, vram.mask + 1}); s(ppu1.version); s(ppu1.mdr); @@ -165,12 +165,12 @@ auto PPU::Object::serialize(serializer& s) -> void { s(t.tileCount); s(t.active); - for(uint p : range(2)) { - for(uint n : range(32)) { + for(u32 p : range(2)) { + for(u32 n : range(32)) { s(t.item[p][n].valid); s(t.item[p][n].index); } - for(uint n : range(34)) { + for(u32 n : range(34)) { s(t.tile[p][n].valid); s(t.tile[p][n].x); s(t.tile[p][n].priority); diff --git a/ares/sfc/ppu/window.cpp b/ares/sfc/ppu/window.cpp index 96d83d513e..110db2a58d 100644 --- a/ares/sfc/ppu/window.cpp +++ b/ares/sfc/ppu/window.cpp @@ -38,7 +38,7 @@ auto PPU::Window::run() -> void { output.below.colorEnable = array[io.col.belowMask]; } -auto PPU::Window::test(bool oneEnable, bool one, bool twoEnable, bool two, uint mask) -> bool { +auto PPU::Window::test(bool oneEnable, bool one, bool twoEnable, bool two, u32 mask) -> bool { if(!oneEnable) return two && twoEnable; if(!twoEnable) return one; if(mask == 0) return (one | two); diff --git a/ares/sfc/ppu/window.hpp b/ares/sfc/ppu/window.hpp index 1ce85beba8..0333ae40d8 100644 --- a/ares/sfc/ppu/window.hpp +++ b/ares/sfc/ppu/window.hpp @@ -2,46 +2,46 @@ struct Window { //window.cpp auto scanline() -> void; auto run() -> void; - auto test(bool oneEnable, bool one, bool twoEnable, bool two, uint mask) -> bool; + auto test(bool oneEnable, bool one, bool twoEnable, bool two, u32 mask) -> bool; auto power() -> void; auto serialize(serializer&) -> void; struct IO { struct Layer { - uint1 oneInvert; - uint1 oneEnable; - uint1 twoInvert; - uint1 twoEnable; - uint2 mask; - uint1 aboveEnable; - uint1 belowEnable; + n1 oneInvert; + n1 oneEnable; + n1 twoInvert; + n1 twoEnable; + n2 mask; + n1 aboveEnable; + n1 belowEnable; } bg1, bg2, bg3, bg4, obj; struct Color { - uint1 oneEnable; - uint1 oneInvert; - uint1 twoEnable; - uint1 twoInvert; - uint2 mask; - uint2 aboveMask; - uint2 belowMask; + n1 oneEnable; + n1 oneInvert; + n1 twoEnable; + n1 twoInvert; + n2 mask; + n2 aboveMask; + n2 belowMask; } col; - uint8 oneLeft; - uint8 oneRight; - uint8 twoLeft; - uint8 twoRight; + n8 oneLeft; + n8 oneRight; + n8 twoLeft; + n8 twoRight; } io; struct Output { struct Pixel { - uint1 colorEnable; + n1 colorEnable; } above, below; } output; struct { - uint x; + u32 x; }; friend class PPU; diff --git a/ares/sfc/sfc.hpp b/ares/sfc/sfc.hpp index 17768eeb74..eecd3bd67d 100644 --- a/ares/sfc/sfc.hpp +++ b/ares/sfc/sfc.hpp @@ -16,6 +16,7 @@ namespace ares::SuperFamicom { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; struct Region { diff --git a/ares/sfc/slot/bsmemory/bsmemory.cpp b/ares/sfc/slot/bsmemory/bsmemory.cpp index 106a1a7761..8fb983624c 100644 --- a/ares/sfc/slot/bsmemory/bsmemory.cpp +++ b/ares/sfc/slot/bsmemory/bsmemory.cpp @@ -60,7 +60,7 @@ auto BSMemoryCartridge::connect() -> void { if(auto node = document["flash/serial"]) { chip.serial = node.natural(); } - for(uint id : range(block.count())) { + for(u32 id : range(block.count())) { if(auto node = document[{"flash/block(id=", id, ")"}]) { if(auto erased = node["erased"]) { block(id).erased = erased.natural(); @@ -85,10 +85,10 @@ auto BSMemoryCartridge::disconnect() -> void { manifest.append(" vendor: 0x", hex(chip.vendor, 4L), "\n"); manifest.append(" device: 0x", hex(chip.device, 4L), "\n"); manifest.append(" serial: 0x", hex(chip.serial, 12L), "\n"); - for(uint6 id : range(block.count())) { + for(n6 id : range(block.count())) { manifest.append(" block\n"); manifest.append(" id: ", id, "\n"); - manifest.append(" erased: ", (uint)block(id).erased, "\n"); + manifest.append(" erased: ", (u32)block(id).erased, "\n"); manifest.append(" locked: ", (bool)block(id).locked, "\n"); } fp->writes(manifest); @@ -103,13 +103,13 @@ auto BSMemoryCartridge::disconnect() -> void { BSMemoryCartridge::BSMemoryCartridge() { page.self = this; - uint blockID = 0; + u32 blockID = 0; for(auto& block : blocks) block.self = this, block.id = blockID++; block.self = this; } auto BSMemoryCartridge::main() -> void { - for(uint6 id : range(block.count())) { + for(n6 id : range(block.count())) { if(block(id).erasing) return block(id).erase(); block(id).status.ready = 1; } @@ -119,7 +119,7 @@ auto BSMemoryCartridge::main() -> void { Thread::step(10'000); //10 milliseconds } -auto BSMemoryCartridge::step(uint clocks) -> void { +auto BSMemoryCartridge::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -152,14 +152,14 @@ auto BSMemoryCartridge::save() -> void { } } -auto BSMemoryCartridge::read(uint24 address, uint8 data) -> uint8 { +auto BSMemoryCartridge::read(n24 address, n8 data) -> n8 { if(!memory) return data; if(ROM) return memory.read(bus.mirror(address, size())); if(mode == Mode::Chip) { if(address == 0) return chip.vendor.byte(0); //only appears once if(address == 1) return chip.device.byte(0); //only appears once - if((uint3)address == 2) return 0x63; //unknown constant: repeats every eight bytes + if((n3)address == 2) return 0x63; //unknown constant: repeats every eight bytes return 0x20; //unknown constant: fills in all remaining bytes } @@ -172,25 +172,25 @@ auto BSMemoryCartridge::read(uint24 address, uint8 data) -> uint8 { } if(mode == Mode::ExtendedStatus) { - if((uint16)address == 0x0002) return block(address >> block.bits()).status(); - if((uint16)address == 0x0004) return global.status(); + if((n16)address == 0x0002) return block(address >> block.bits()).status(); + if((n16)address == 0x0004) return global.status(); return 0x00; //reserved: always zero } return block(address >> block.bits()).read(address); //Mode::Flash } -auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { +auto BSMemoryCartridge::write(n24 address, n8 data) -> void { if(!memory || ROM) return; queue.push(address, data); //write page to flash if(queue.data(0) == 0x0c) { if(queue.size() < 3) return; - uint16 count; //1 - 65536 + n16 count; //1 - 65536 count.byte(0) = queue.data(!queue.address(1).bit(0) ? 1 : 2); count.byte(1) = queue.data(!queue.address(1).bit(0) ? 2 : 1); - uint24 address = queue.address(2); + n24 address = queue.address(2); do { block(address >> block.bits()).write(address, page.read(address)); address++; @@ -225,7 +225,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { page.write(0x00, 0x4d); //'M' (memory) page.write(0x02, 0x50); //'P' (pack) page.write(0x04, 0x04); //unknown constant (maybe block count? eg 1<<4 = 16 blocks) - page.write(0x06, 0x10 | (uint4)log2(size() >> 10)); //d0-d3 = size; d4-d7 = type (1) + page.write(0x06, 0x10 | (n4)log2(size() >> 10)); //d0-d3 = size; d4-d7 = type (1) page.write(0x08, chip.serial >> 40); //serial# (big endian; BCD format) page.write(0x0a, chip.serial >> 32); //smallest observed value: page.write(0x0c, chip.serial >> 24); // 0x00'00'10'62'62'39 @@ -246,7 +246,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { //clear status register if(queue.data(0) == 0x50) { - for(uint6 id : range(block.count())) { + for(n6 id : range(block.count())) { block(id).status.vppLow = 0; block(id).status.failed = 0; } @@ -324,7 +324,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { if(queue.data(0) == 0x97) { if(queue.size() < 2) return; if(queue.data(1) != 0xd0) return failed(), queue.flush(); - for(uint6 id : range(block.count())) block(id).update(); + for(n6 id : range(block.count())) block(id).update(); return queue.flush(); } @@ -334,14 +334,14 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { if(queue.data(1) != 0xd0) return failed(), queue.flush(); page.write(0x06, 0x06); //unknown constant page.write(0x07, 0x00); //unknown constant - for(uint6 id : range(block.count())) { - uint8 address; + for(n6 id : range(block.count())) { + n8 address; address += id.bit(0,1) * 0x08; //verified for LH28F800SUT-ZI address += id.bit(2,3) * 0x40; //verified for LH28F800SUT-ZI address += id.bit(4) * 0x20; //guessed for LH28F016SU address += id.bit(5) * 0x04; //guessed for LH28F032SU; will overwrite unknown constants - uint32 erased = 1 << 31 | block(id).erased; //unknown if d31 is set when erased == 0 - for(uint2 byte : range(4)) { + n32 erased = 1 << 31 | block(id).erased; //unknown if d31 is set when erased == 0 + for(n2 byte : range(4)) { page.write(address + byte, erased >> byte * 8); //little endian } } @@ -353,7 +353,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { if(queue.data(0) == 0xa7) { if(queue.size() < 2) return; if(queue.data(1) != 0xd0) return failed(), queue.flush(); - for(uint6 id : range(block.count())) block(id).erase(); + for(n6 id : range(block.count())) block(id).erase(); mode = Mode::CompatibleStatus; return queue.flush(); } @@ -370,7 +370,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { //sequential load to page buffer if(queue.data(0) == 0xe0) { if(queue.size() < 4) return; //command length = 3 + count - uint16 count; //1 - 65536 + n16 count; //1 - 65536 count.byte(0) = queue.data(1); //endian order not affected by queue.address(1).field(0) count.byte(1) = queue.data(2); page.write(queue.address(3), queue.data(3)); @@ -394,7 +394,7 @@ auto BSMemoryCartridge::write(uint24 address, uint8 data) -> void { //write word if(queue.data(0) == 0xfb) { if(queue.size() < 3) return; - uint16 value; + n16 value; value.byte(0) = queue.data(!queue.address(1).bit(0) ? 1 : 2); value.byte(1) = queue.data(!queue.address(1).bit(0) ? 2 : 1); //writes are always word-aligned: a0 toggles, rather than increments @@ -428,28 +428,28 @@ auto BSMemoryCartridge::Page::swap() -> void { self->global.status.page ^= 1; } -auto BSMemoryCartridge::Page::read(uint8 address) -> uint8 { +auto BSMemoryCartridge::Page::read(n8 address) -> n8 { return buffer[self->global.status.page][address]; } -auto BSMemoryCartridge::Page::write(uint8 address, uint8 data) -> void { +auto BSMemoryCartridge::Page::write(n8 address, n8 data) -> void { buffer[self->global.status.page][address] = data; } // -inline auto BSMemoryCartridge::BlockInformation::bits() const -> uint { return 16; } -inline auto BSMemoryCartridge::BlockInformation::bytes() const -> uint { return 1 << bits(); } -inline auto BSMemoryCartridge::BlockInformation::count() const -> uint { return self->size() >> bits(); } +inline auto BSMemoryCartridge::BlockInformation::bits() const -> u32 { return 16; } +inline auto BSMemoryCartridge::BlockInformation::bytes() const -> u32 { return 1 << bits(); } +inline auto BSMemoryCartridge::BlockInformation::count() const -> u32 { return self->size() >> bits(); } // -auto BSMemoryCartridge::Block::read(uint24 address) -> uint8 { +auto BSMemoryCartridge::Block::read(n24 address) -> n8 { address &= bytes() - 1; return self->memory.read(id << bits() | address); } -auto BSMemoryCartridge::Block::write(uint24 address, uint8 data) -> void { +auto BSMemoryCartridge::Block::write(n24 address, n8 data) -> void { if(!self->writable() && status.locked) { status.failed = 1; return self->failed(); @@ -479,7 +479,7 @@ auto BSMemoryCartridge::Block::erase() -> void { return; } - for(uint24 address : range(bytes())) { + for(n24 address : range(bytes())) { self->memory.write(id << bits() | address, 0xff); } @@ -507,13 +507,13 @@ auto BSMemoryCartridge::Block::update() -> void { // -auto BSMemoryCartridge::Blocks::operator()(uint6 id) -> Block& { +auto BSMemoryCartridge::Blocks::operator()(n6 id) -> Block& { return self->blocks[id & count() - 1]; } // -auto BSMemoryCartridge::Block::Status::operator()() -> uint8 { +auto BSMemoryCartridge::Block::Status::operator()() -> n8 { return ( //d0-d1 are reserved; always return zero vppLow << 2 | queueFull << 3 @@ -526,7 +526,7 @@ auto BSMemoryCartridge::Block::Status::operator()() -> uint8 { // -auto BSMemoryCartridge::Compatible::Status::operator()() -> uint8 { +auto BSMemoryCartridge::Compatible::Status::operator()() -> n8 { return ( //d0-d2 are reserved; always return zero vppLow << 3 | writeFailed << 4 @@ -538,7 +538,7 @@ auto BSMemoryCartridge::Compatible::Status::operator()() -> uint8 { // -auto BSMemoryCartridge::Global::Status::operator()() -> uint8 { +auto BSMemoryCartridge::Global::Status::operator()() -> n8 { return ( page << 0 | pageReady << 1 @@ -567,14 +567,14 @@ auto BSMemoryCartridge::Queue::pop() -> void { if(history[0].valid) { history[0] = {}; return; } } -auto BSMemoryCartridge::Queue::push(uint24 address, uint8 data) -> void { +auto BSMemoryCartridge::Queue::push(n24 address, n8 data) -> void { if(!history[0].valid) { history[0] = {true, address, data}; return; } if(!history[1].valid) { history[1] = {true, address, data}; return; } if(!history[2].valid) { history[2] = {true, address, data}; return; } if(!history[3].valid) { history[3] = {true, address, data}; return; } } -auto BSMemoryCartridge::Queue::size() -> uint { +auto BSMemoryCartridge::Queue::size() -> u32 { if(history[3].valid) return 4; if(history[2].valid) return 3; if(history[1].valid) return 2; @@ -582,12 +582,12 @@ auto BSMemoryCartridge::Queue::size() -> uint { return 0; } -auto BSMemoryCartridge::Queue::address(uint index) -> uint24 { +auto BSMemoryCartridge::Queue::address(u32 index) -> n24 { if(index > 3 || !history[index].valid) return 0; return history[index].address; } -auto BSMemoryCartridge::Queue::data(uint index) -> uint8 { +auto BSMemoryCartridge::Queue::data(u32 index) -> n8 { if(index > 3 || !history[index].valid) return 0; return history[index].data; } diff --git a/ares/sfc/slot/bsmemory/bsmemory.hpp b/ares/sfc/slot/bsmemory/bsmemory.hpp index 0f927f9dd9..6b9df1dcd8 100644 --- a/ares/sfc/slot/bsmemory/bsmemory.hpp +++ b/ares/sfc/slot/bsmemory/bsmemory.hpp @@ -17,11 +17,11 @@ struct BSMemoryCartridge : Thread { Node::Peripheral node; - uint ROM = 1; + u32 ROM = 1; auto manifest() const -> string { return information.manifest; } auto name() const -> string { return information.name; } - auto size() const -> uint { return memory.size(); } + auto size() const -> u32 { return memory.size(); } auto writable() const { return pin.writable; } auto writable(bool writable) { pin.writable = !ROM && writable; } @@ -32,13 +32,13 @@ struct BSMemoryCartridge : Thread { BSMemoryCartridge(); auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; auto save() -> void; - auto read(uint24 address, uint8 data) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address, n8 data) -> n8; + auto write(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; @@ -52,120 +52,120 @@ struct BSMemoryCartridge : Thread { private: struct Pin { - uint1 writable; // => /WP + n1 writable; // => /WP } pin; struct Chip { - uint16 vendor; - uint16 device; - uint48 serial; + n16 vendor; + n16 device; + n48 serial; } chip; struct Page { BSMemoryCartridge* self = nullptr; auto swap() -> void; - auto read(uint8 address) -> uint8; - auto write(uint8 address, uint8 data) -> void; + auto read(n8 address) -> n8; + auto write(n8 address, n8 data) -> void; - uint8 buffer[2][256]; + n8 buffer[2][256]; } page; struct BlockInformation { BSMemoryCartridge* self = nullptr; - auto bits() const -> uint; - auto bytes() const -> uint; - auto count() const -> uint; + auto bits() const -> u32; + auto bytes() const -> u32; + auto count() const -> u32; }; struct Block : BlockInformation { - auto read(uint24 address) -> uint8; - auto write(uint24 address, uint8 data) -> void; + auto read(n24 address) -> n8; + auto write(n24 address, n8 data) -> void; auto erase() -> void; auto lock() -> void; auto update() -> void; - uint4 id; - uint32 erased; - uint1 locked; - uint1 erasing; + n4 id; + n32 erased; + n1 locked; + n1 erasing; struct Status { - auto operator()() -> uint8; - - uint1 vppLow; - uint1 queueFull; - uint1 aborted; - uint1 failed; - uint1 locked = 1; - uint1 ready = 1; + auto operator()() -> n8; + + n1 vppLow; + n1 queueFull; + n1 aborted; + n1 failed; + n1 locked = 1; + n1 ready = 1; } status; } blocks[64]; //8mbit = 16; 16mbit = 32; 32mbit = 64 struct Blocks : BlockInformation { - auto operator()(uint6 id) -> Block&; + auto operator()(n6 id) -> Block&; } block; struct Compatible { struct Status { - auto operator()() -> uint8; + auto operator()() -> n8; - uint1 vppLow; - uint1 writeFailed; - uint1 eraseFailed; - uint1 eraseSuspended; - uint1 ready = 1; + n1 vppLow; + n1 writeFailed; + n1 eraseFailed; + n1 eraseSuspended; + n1 ready = 1; } status; } compatible; struct Global { struct Status { - auto operator()() -> uint8; - - uint1 page; - uint1 pageReady = 1; - uint1 pageAvailable = 1; - uint1 queueFull; - uint1 sleeping; - uint1 failed; - uint1 suspended; - uint1 ready = 1; + auto operator()() -> n8; + + n1 page; + n1 pageReady = 1; + n1 pageAvailable = 1; + n1 queueFull; + n1 sleeping; + n1 failed; + n1 suspended; + n1 ready = 1; } status; } global; - struct Mode { enum : uint { + struct Mode { enum : u32 { Flash, Chip, Page, CompatibleStatus, ExtendedStatus, };}; - uint3 mode; + n3 mode; - struct ReadyBusyMode { enum : uint { + struct ReadyBusyMode { enum : u32 { EnableToLevelMode, PulseOnWrite, PulseOnErase, Disable, };}; - uint2 readyBusyMode; + n2 readyBusyMode; struct Queue { auto flush() -> void; auto pop() -> void; - auto push(uint24 address, uint8 data) -> void; - auto size() -> uint; - auto address(uint index) -> uint24; - auto data(uint index) -> uint8; + auto push(n24 address, n8 data) -> void; + auto size() -> u32; + auto address(u32 index) -> n24; + auto data(u32 index) -> n8; //serialization.cpp auto serialize(serializer&) -> void; struct History { - uint1 valid; - uint24 address; - uint8 data; + n1 valid; + n24 address; + n8 data; } history[4]; } queue; diff --git a/ares/sfc/slot/sufamiturbo/memory.cpp b/ares/sfc/slot/sufamiturbo/memory.cpp index 0aece9bd6e..bdaa50deed 100644 --- a/ares/sfc/slot/sufamiturbo/memory.cpp +++ b/ares/sfc/slot/sufamiturbo/memory.cpp @@ -1,19 +1,19 @@ -auto SufamiTurboCartridge::readROM(uint24 address, uint8 data) -> uint8 { +auto SufamiTurboCartridge::readROM(n24 address, n8 data) -> n8 { if(!rom) return data; return rom.read(address & rom.size() - 1, data); } -auto SufamiTurboCartridge::writeROM(uint24 address, uint8 data) -> void { +auto SufamiTurboCartridge::writeROM(n24 address, n8 data) -> void { if(!rom) return; return rom.write(address & rom.size() - 1, data); } -auto SufamiTurboCartridge::readRAM(uint24 address, uint8 data) -> uint8 { +auto SufamiTurboCartridge::readRAM(n24 address, n8 data) -> n8 { if(!ram) return data; return ram.read(address & ram.size() - 1, data); } -auto SufamiTurboCartridge::writeRAM(uint24 address, uint8 data) -> void { +auto SufamiTurboCartridge::writeRAM(n24 address, n8 data) -> void { if(!ram) return; return ram.write(address & ram.size() - 1, data); } diff --git a/ares/sfc/slot/sufamiturbo/sufamiturbo.hpp b/ares/sfc/slot/sufamiturbo/sufamiturbo.hpp index 5e04fbd9dd..58c6aad2ba 100644 --- a/ares/sfc/slot/sufamiturbo/sufamiturbo.hpp +++ b/ares/sfc/slot/sufamiturbo/sufamiturbo.hpp @@ -13,11 +13,11 @@ struct SufamiTurboCartridge { auto save() -> void; //memory.cpp - auto readROM(uint24 address, uint8 data) -> uint8; - auto writeROM(uint24 address, uint8 data) -> void; + auto readROM(n24 address, n8 data) -> n8; + auto writeROM(n24 address, n8 data) -> void; - auto readRAM(uint24 address, uint8 data) -> uint8; - auto writeRAM(uint24 address, uint8 data) -> void; + auto readRAM(n24 address, n8 data) -> n8; + auto writeRAM(n24 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/sfc/smp/io.cpp b/ares/sfc/smp/io.cpp index ad40e23aeb..c1eefb3140 100644 --- a/ares/sfc/smp/io.cpp +++ b/ares/sfc/smp/io.cpp @@ -1,4 +1,4 @@ -auto SMP::portRead(uint2 port) const -> uint8 { +auto SMP::portRead(n2 port) const -> n8 { if(port == 0) return io.cpu0; if(port == 1) return io.cpu1; if(port == 2) return io.cpu2; @@ -6,15 +6,15 @@ auto SMP::portRead(uint2 port) const -> uint8 { unreachable; } -auto SMP::portWrite(uint2 port, uint8 data) -> void { +auto SMP::portWrite(n2 port, n8 data) -> void { if(port == 0) io.apu0 = data; if(port == 1) io.apu1 = data; if(port == 2) io.apu2 = data; if(port == 3) io.apu3 = data; } -inline auto SMP::readIO(uint16 address) -> uint8 { - uint8 data; +inline auto SMP::readIO(n16 address) -> n8 { + n8 data; switch(address) { case 0xf0: //TEST (write-only register) @@ -76,7 +76,7 @@ inline auto SMP::readIO(uint16 address) -> uint8 { return data; //unreachable } -inline auto SMP::writeIO(uint16 address, uint8 data) -> void { +inline auto SMP::writeIO(n16 address, n8 data) -> void { switch(address) { case 0xf0: //TEST if(r.p.p) break; //writes only valid when P flag is clear diff --git a/ares/sfc/smp/memory.cpp b/ares/sfc/smp/memory.cpp index 999207a29e..8a6d7c3f3b 100644 --- a/ares/sfc/smp/memory.cpp +++ b/ares/sfc/smp/memory.cpp @@ -1,10 +1,10 @@ -inline auto SMP::readRAM(uint16 address) -> uint8 { +inline auto SMP::readRAM(n16 address) -> n8 { if(address >= 0xffc0 && io.iplromEnable) return iplrom[address & 0x3f]; if(io.ramDisable) return 0x5a; //0xff on mini-SNES return dsp.apuram[address]; } -inline auto SMP::writeRAM(uint16 address, uint8 data) -> void { +inline auto SMP::writeRAM(n16 address, n8 data) -> void { //writes to $ffc0-$ffff always go to apuram, even if the iplrom is enabled if(io.ramWritable && !io.ramDisable) dsp.apuram[address] = data; } @@ -13,29 +13,29 @@ auto SMP::idle() -> void { wait(0); } -auto SMP::read(uint16 address) -> uint8 { +auto SMP::read(n16 address) -> n8 { if((address & 0xfffc) == 0x00f4) { //reads from $00f4-$00f7 require more time than internal reads wait(1, address); - uint8 data = readRAM(address); + n8 data = readRAM(address); if((address & 0xfff0) == 0x00f0) data = readIO(address); wait(1, address); return data; } else { wait(0, address); - uint8 data = readRAM(address); + n8 data = readRAM(address); if((address & 0xfff0) == 0x00f0) data = readIO(address); return data; } } -auto SMP::write(uint16 address, uint8 data) -> void { +auto SMP::write(n16 address, n8 data) -> void { wait(0, address); writeRAM(address, data); //even IO writes affect underlying RAM if((address & 0xfff0) == 0x00f0) writeIO(address, data); } -auto SMP::readDisassembler(uint16 address) -> uint8 { +auto SMP::readDisassembler(n16 address) -> n8 { if((address & 0xfff0) == 0x00f0) return 0x00; return readRAM(address); } diff --git a/ares/sfc/smp/serialization.cpp b/ares/sfc/smp/serialization.cpp index ca8e531ec1..a17d5a5ac0 100644 --- a/ares/sfc/smp/serialization.cpp +++ b/ares/sfc/smp/serialization.cpp @@ -34,7 +34,7 @@ auto SMP::serialize(serializer& s) -> void { s(timer2); } -template +template auto SMP::Timer::serialize(serializer& s) -> void { s(stage0); s(stage1); diff --git a/ares/sfc/smp/smp.hpp b/ares/sfc/smp/smp.hpp index 6401f574d0..dce768cf1b 100644 --- a/ares/sfc/smp/smp.hpp +++ b/ares/sfc/smp/smp.hpp @@ -23,77 +23,77 @@ struct SMP : SPC700, Thread { auto power(bool reset) -> void; //io.cpp - auto portRead(uint2 port) const -> uint8; - auto portWrite(uint2 port, uint8 data) -> void; + auto portRead(n2 port) const -> n8; + auto portWrite(n2 port, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; - uint8 iplrom[64]; + n8 iplrom[64]; private: struct IO { //timing - uint clockCounter = 0; - uint dspCounter = 0; + u32 clockCounter = 0; + u32 dspCounter = 0; //external - uint8 apu0; - uint8 apu1; - uint8 apu2; - uint8 apu3; + n8 apu0; + n8 apu1; + n8 apu2; + n8 apu3; //$00f0 - uint1 timersDisable; - uint1 ramWritable = true; - uint1 ramDisable; - uint1 timersEnable = true; - uint2 externalWaitStates; - uint2 internalWaitStates; + n1 timersDisable; + n1 ramWritable = true; + n1 ramDisable; + n1 timersEnable = true; + n2 externalWaitStates; + n2 internalWaitStates; //$00f1 - uint1 iplromEnable = true; + n1 iplromEnable = true; //$00f2 - uint8 dspAddress; + n8 dspAddress; //$00f4-00f7 - uint8 cpu0; - uint8 cpu1; - uint8 cpu2; - uint8 cpu3; + n8 cpu0; + n8 cpu1; + n8 cpu2; + n8 cpu3; //$00f8-00f9 - uint8 aux4; - uint8 aux5; + n8 aux4; + n8 aux5; } io; //memory.cpp - auto readRAM(uint16 address) -> uint8; - auto writeRAM(uint16 address, uint8 data) -> void; + auto readRAM(n16 address) -> n8; + auto writeRAM(n16 address, n8 data) -> void; auto idle() -> void override; - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto readDisassembler(uint16 address) -> uint8 override; + auto readDisassembler(n16 address) -> n8 override; //io.cpp - auto readIO(uint16 address) -> uint8; - auto writeIO(uint16 address, uint8 data) -> void; + auto readIO(n16 address) -> n8; + auto writeIO(n16 address, n8 data) -> void; - template + template struct Timer { - uint8 stage0; - uint8 stage1; - uint8 stage2; - uint4 stage3; - boolean line; - boolean enable; - uint8 target; + n8 stage0; + n8 stage1; + n8 stage2; + n4 stage3; + b1 line; + b1 enable; + n8 target; //timing.cpp - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto synchronizeStage1() -> void; //serialization.cpp @@ -105,9 +105,9 @@ struct SMP : SPC700, Thread { Timer< 16> timer2; //timing.cpp - auto wait(bool halve, maybe address = nothing) -> void; - auto step(uint clocks) -> void; - auto stepTimers(uint clocks) -> void; + auto wait(bool halve, maybe address = nothing) -> void; + auto step(u32 clocks) -> void; + auto stepTimers(u32 clocks) -> void; }; extern SMP smp; diff --git a/ares/sfc/smp/timing.cpp b/ares/sfc/smp/timing.cpp index 99c13729c5..fe27c9cf7f 100644 --- a/ares/sfc/smp/timing.cpp +++ b/ares/sfc/smp/timing.cpp @@ -6,11 +6,11 @@ //sometimes the SMP will run far slower than expected //other times (and more likely), the SMP will deadlock until the system is reset //the timers are not affected by this and advance by their expected values -inline auto SMP::wait(bool halve, maybe address) -> void { - static const uint cycleWaitStates[4] = {2, 4, 10, 20}; - static const uint timerWaitStates[4] = {2, 4, 8, 16}; +inline auto SMP::wait(bool halve, maybe address) -> void { + static constexpr u32 cycleWaitStates[4] = {2, 4, 10, 20}; + static constexpr u32 timerWaitStates[4] = {2, 4, 8, 16}; - uint waitStates = io.externalWaitStates; + u32 waitStates = io.externalWaitStates; if(!address) waitStates = io.internalWaitStates; //idle cycles else if((*address & 0xfff0) == 0x00f0) waitStates = io.internalWaitStates; //IO registers else if(*address >= 0xffc0 && io.iplromEnable) waitStates = io.internalWaitStates; //IPLROM @@ -19,19 +19,19 @@ inline auto SMP::wait(bool halve, maybe address) -> void { stepTimers(timerWaitStates[waitStates] >> halve); } -inline auto SMP::step(uint clocks) -> void { +inline auto SMP::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); Thread::synchronize(dsp); } -inline auto SMP::stepTimers(uint clocks) -> void { +inline auto SMP::stepTimers(u32 clocks) -> void { timer0.step(clocks); timer1.step(clocks); timer2.step(clocks); } -template auto SMP::Timer::step(uint clocks) -> void { +template auto SMP::Timer::step(u32 clocks) -> void { //stage 0 increment stage0 += clocks; if(stage0 < Frequency) return; @@ -42,7 +42,7 @@ template auto SMP::Timer::step(uint clocks) -> void { synchronizeStage1(); } -template auto SMP::Timer::synchronizeStage1() -> void { +template auto SMP::Timer::synchronizeStage1() -> void { bool level = stage1; if(!smp.io.timersEnable) level = false; if(smp.io.timersDisable) level = false; diff --git a/ares/sfc/system/serialization.cpp b/ares/sfc/system/serialization.cpp index e33c0fd798..a694092881 100644 --- a/ares/sfc/system/serialization.cpp +++ b/ares/sfc/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/sfc/system/system.cpp b/ares/sfc/system/system.cpp index 4c975ae625..f84ba5b876 100644 --- a/ares/sfc/system/system.cpp +++ b/ares/sfc/system/system.cpp @@ -2,7 +2,16 @@ namespace ares::SuperFamicom { +auto enumerate() -> vector { + //todo: lucia can't distinguish "Super Famicom (NTSC)" from "Super Nintendo (NTSC)" + return { + "[Nintendo] Super Famicom (NTSC)", + "[Nintendo] Super Famicom (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -53,8 +62,22 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("Super Famicom")) { + information.name = "Super Famicom"; + } + if(name.find("Super Nintendo")) { + information.name = "Super Nintendo"; + } + if(name.find("NTSC")) { + information.region = Region::NTSC; + information.cpuFrequency = Constants::Colorburst::NTSC * 6.0; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.cpuFrequency = Constants::Colorburst::PAL * 4.8; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -64,14 +87,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC → PAL"); - regionNode->setAllowedValues({ - "NTSC → PAL", - "PAL → NTSC", - "NTSC", - "PAL" - }); - scheduler.reset(); bus.reset(); controls.load(node); @@ -108,22 +123,6 @@ auto System::save() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC") { - information.region = Region::NTSC; - information.cpuFrequency = Constants::Colorburst::NTSC * 6.0; - } - if(region == "PAL") { - information.region = Region::PAL; - information.cpuFrequency = Constants::Colorburst::PAL * 4.8; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - random.entropy(Random::Entropy::Low); cpu.power(reset); diff --git a/ares/sfc/system/system.hpp b/ares/sfc/system/system.hpp index 4fd02e8098..c93ef2fb67 100644 --- a/ares/sfc/system/system.hpp +++ b/ares/sfc/system/system.hpp @@ -2,7 +2,6 @@ extern Random random; struct System { Node::System node; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -13,9 +12,9 @@ struct System { auto poll() -> void; } controls; - enum class Region : uint { NTSC, PAL }; + enum class Region : u32 { NTSC, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto region() const -> Region { return information.region; } auto cpuFrequency() const -> double { return information.cpuFrequency; } auto apuFrequency() const -> double { return information.apuFrequency; } @@ -34,9 +33,10 @@ struct System { private: struct Information { + string name = "Super Famicom"; Region region = Region::NTSC; - double cpuFrequency = Constants::Colorburst::NTSC * 6.0; - double apuFrequency = 32040.0 * 768.0; + f64 cpuFrequency = Constants::Colorburst::NTSC * 6.0; + f64 apuFrequency = 32040.0 * 768.0; } information; //serialization.cpp diff --git a/ares/sg/cartridge/cartridge.cpp b/ares/sg/cartridge/cartridge.cpp index c5605130b6..138f2eb255 100644 --- a/ares/sg/cartridge/cartridge.cpp +++ b/ares/sg/cartridge/cartridge.cpp @@ -64,7 +64,7 @@ auto Cartridge::save() -> void { auto Cartridge::power() -> void { } -auto Cartridge::read(uint16 address) -> maybe { +auto Cartridge::read(n16 address) -> maybe { if(!node) return nothing; if(address >= 0x0000 && address <= 0x7fff) { @@ -78,7 +78,7 @@ auto Cartridge::read(uint16 address) -> maybe { return nothing; } -auto Cartridge::write(uint16 address, uint8 data) -> bool { +auto Cartridge::write(n16 address, n8 data) -> bool { if(!node) return false; if(address >= 0x0000 && address <= 0x7fff) { diff --git a/ares/sg/cartridge/cartridge.hpp b/ares/sg/cartridge/cartridge.hpp index eef7e8c02a..928dd74694 100644 --- a/ares/sg/cartridge/cartridge.hpp +++ b/ares/sg/cartridge/cartridge.hpp @@ -1,7 +1,7 @@ struct Cartridge { Node::Peripheral node; - Memory::Readable rom; - Memory::Writable ram; + Memory::Readable rom; + Memory::Writable ram; auto manifest() const -> string { return information.manifest; } auto name() const -> string { return information.name; } @@ -15,8 +15,8 @@ struct Cartridge { auto save() -> void; auto power() -> void; - auto read(uint16 address) -> maybe; - auto write(uint16 address, uint8 data) -> bool; + auto read(n16 address) -> maybe; + auto write(n16 address, n8 data) -> bool; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/sg/controller/controller.hpp b/ares/sg/controller/controller.hpp index b8f7163d14..3d37fd8ce7 100644 --- a/ares/sg/controller/controller.hpp +++ b/ares/sg/controller/controller.hpp @@ -3,8 +3,8 @@ struct Controller { virtual ~Controller() = default; - virtual auto read() -> uint8 { return 0xff; } - virtual auto write(uint8 data) -> void {} + virtual auto read() -> n8 { return 0xff; } + virtual auto write(n8 data) -> void {} }; #include "port.hpp" diff --git a/ares/sg/controller/gamepad/gamepad.cpp b/ares/sg/controller/gamepad/gamepad.cpp index e25195723a..3376d88451 100644 --- a/ares/sg/controller/gamepad/gamepad.cpp +++ b/ares/sg/controller/gamepad/gamepad.cpp @@ -9,7 +9,7 @@ Gamepad::Gamepad(Node::Port parent) { two = node->append("2"); } -auto Gamepad::read() -> uint8 { +auto Gamepad::read() -> n8 { platform->input(up); platform->input(down); platform->input(left); @@ -29,7 +29,7 @@ auto Gamepad::read() -> uint8 { xHold = 1, swap(leftLatch, rightLatch); } - uint8 data = 0xff; + n8 data = 0xff; data.bit(0) = !upLatch; data.bit(1) = !downLatch; data.bit(2) = !leftLatch; diff --git a/ares/sg/controller/gamepad/gamepad.hpp b/ares/sg/controller/gamepad/gamepad.hpp index 8c4f62c821..c9087cf8c4 100644 --- a/ares/sg/controller/gamepad/gamepad.hpp +++ b/ares/sg/controller/gamepad/gamepad.hpp @@ -8,13 +8,13 @@ struct Gamepad : Controller { Gamepad(Node::Port); - auto read() -> uint8 override; + auto read() -> n8 override; private: - bool yHold = 0; - bool upLatch = 0; - bool downLatch = 0; - bool xHold = 0; - bool leftLatch = 0; - bool rightLatch = 0; + b1 yHold; + b1 upLatch; + b1 downLatch; + b1 xHold; + b1 leftLatch; + b1 rightLatch; }; diff --git a/ares/sg/controller/port.hpp b/ares/sg/controller/port.hpp index 95f7b22225..808004bcee 100644 --- a/ares/sg/controller/port.hpp +++ b/ares/sg/controller/port.hpp @@ -8,8 +8,8 @@ struct ControllerPort { auto unload() -> void; auto allocate(string name) -> Node::Peripheral; - auto read() -> uint8 { if(device) return device->read(); return 0xff; } - auto write(uint8 data) -> void { if(device) return device->write(data); } + auto read() -> n8 { if(device) return device->read(); return 0xff; } + auto write(n8 data) -> void { if(device) return device->write(data); } auto serialize(serializer&) -> void; diff --git a/ares/sg/cpu/cpu.hpp b/ares/sg/cpu/cpu.hpp index dfa255916d..a5a820a168 100644 --- a/ares/sg/cpu/cpu.hpp +++ b/ares/sg/cpu/cpu.hpp @@ -1,6 +1,6 @@ struct CPU : Z80, Z80::Bus, Thread { Node::Object node; - Memory::Writable ram; //SG-1000 = 1KB, SC-3000 = 2KB + Memory::Writable ram; //SG-1000 = 1KB, SC-3000 = 2KB struct Debugger { //debugger.cpp @@ -25,7 +25,7 @@ struct CPU : Z80, Z80::Bus, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto setNMI(bool value) -> void; auto setIRQ(bool value) -> void; @@ -33,14 +33,14 @@ struct CPU : Z80, Z80::Bus, Thread { auto power() -> void; //memory.cpp - auto read(uint16 address) -> uint8 override; - auto write(uint16 address, uint8 data) -> void override; + auto read(n16 address) -> n8 override; + auto write(n16 address, n8 data) -> void override; - auto in(uint16 address) -> uint8 override; - auto out(uint16 address, uint8 data) -> void override; + auto in(n16 address) -> n8 override; + auto out(n16 address, n8 data) -> void override; //serialization.cpp - auto serialize(serializer&) -> void; + auto serialize(serializer&) -> void override; private: struct State { diff --git a/ares/sg/cpu/memory.cpp b/ares/sg/cpu/memory.cpp index 7b5c157a9d..4d38493327 100644 --- a/ares/sg/cpu/memory.cpp +++ b/ares/sg/cpu/memory.cpp @@ -1,5 +1,5 @@ -auto CPU::read(uint16 address) -> uint8 { - uint8 data = 0xff; +auto CPU::read(n16 address) -> n8 { + n8 data = 0xff; if(auto result = cartridge.read(address)) { data = result(); } else if(address >= 0xc000) { @@ -8,14 +8,14 @@ auto CPU::read(uint16 address) -> uint8 { return data; } -auto CPU::write(uint16 address, uint8 data) -> void { +auto CPU::write(n16 address, n8 data) -> void { if(cartridge.write(address, data)) { } else if(address >= 0xc000) { ram.write(address, data); } } -auto CPU::in(uint16 address) -> uint8 { +auto CPU::in(n16 address) -> n8 { switch(address.bit(6,7)) { case 0: { @@ -45,7 +45,7 @@ auto CPU::in(uint16 address) -> uint8 { return 0xff; } -auto CPU::out(uint16 address, uint8 data) -> void { +auto CPU::out(n16 address, n8 data) -> void { switch(address.bit(6,7)) { case 1: { diff --git a/ares/sg/psg/psg.cpp b/ares/sg/psg/psg.cpp index 099499fa19..692abaf4f9 100644 --- a/ares/sg/psg/psg.cpp +++ b/ares/sg/psg/psg.cpp @@ -30,7 +30,7 @@ auto PSG::main() -> void { step(1); } -auto PSG::step(uint clocks) -> void { +auto PSG::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } @@ -39,7 +39,7 @@ auto PSG::power() -> void { SN76489::power(); Thread::create(system.colorburst() / 16.0, {&PSG::main, this}); - for(uint level : range(15)) { + for(u32 level : range(15)) { volume[level] = pow(2, level * -2.0 / 6.0); } volume[15] = 0; diff --git a/ares/sg/psg/psg.hpp b/ares/sg/psg/psg.hpp index 3d7b6e995a..ff29a18ac0 100644 --- a/ares/sg/psg/psg.hpp +++ b/ares/sg/psg/psg.hpp @@ -7,14 +7,14 @@ struct PSG : SN76489, Thread { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //serialization.cpp auto serialize(serializer&) -> void; private: - double volume[16]; + f64 volume[16]; }; extern PSG psg; diff --git a/ares/sg/sg.hpp b/ares/sg/sg.hpp index b6379cc797..19d0a5c3be 100644 --- a/ares/sg/sg.hpp +++ b/ares/sg/sg.hpp @@ -9,6 +9,8 @@ namespace ares::SG1000 { #include + auto enumerate() -> vector; + auto load(Node::System& node, string name) -> bool; struct Model { inline static auto SG1000() -> bool; diff --git a/ares/sg/system/serialization.cpp b/ares/sg/system/serialization.cpp index ed8ceeb25c..47586f0c73 100644 --- a/ares/sg/system/serialization.cpp +++ b/ares/sg/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/sg/system/system.cpp b/ares/sg/system/system.cpp index 58680da3b2..b80733b442 100644 --- a/ares/sg/system/system.cpp +++ b/ares/sg/system/system.cpp @@ -2,7 +2,17 @@ namespace ares::SG1000 { +auto enumerate() -> vector { + return { + "[Sega] SG-1000 (NTSC)", + "[Sega] SG-1000 (PAL)", + "[Sega] SC-3000 (NTSC)", + "[Sega] SC-3000 (PAL)", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -28,10 +38,24 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; - if(name == "SG-1000") information.model = Model::SG1000; - if(name == "SC-3000") information.model = Model::SC3000; + if(name.find("SG-1000")) { + information.name = "SG-1000"; + information.model = Model::SG1000; + } + if(name.find("SC-3000")) { + information.name = "SC-3000"; + information.model = Model::SC3000; + } + if(name.find("NTSC")) { + information.region = Region::NTSC; + information.colorburst = Constants::Colorburst::NTSC; + } + if(name.find("PAL")) { + information.region = Region::PAL; + information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; + } - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -41,14 +65,6 @@ auto System::load(Node::System& root, string name) -> bool { node->setUnserialize({&System::unserialize, this}); root = node; - regionNode = node->append("Region", "NTSC → PAL"); - regionNode->setAllowedValues({ - "NTSC → PAL", - "PAL → NTSC", - "NTSC", - "PAL" - }); - scheduler.reset(); controls.load(node); cpu.load(node); @@ -80,22 +96,6 @@ auto System::unload() -> void { auto System::power(bool reset) -> void { for(auto& setting : node->find()) setting->setLatch(); - auto setRegion = [&](string region) { - if(region == "NTSC") { - information.region = Region::NTSC; - information.colorburst = Constants::Colorburst::NTSC; - } - if(region == "PAL") { - information.region = Region::PAL; - information.colorburst = Constants::Colorburst::PAL * 4.0 / 5.0; - } - }; - auto regionsHave = regionNode->latch().split("→").strip(); - setRegion(regionsHave.first()); - for(auto& have : reverse(regionsHave)) { - if(have == cartridge.region()) setRegion(have); - } - cartridge.power(); cpu.power(); vdp.power(); diff --git a/ares/sg/system/system.hpp b/ares/sg/system/system.hpp index f189ec2b61..caefd073d0 100644 --- a/ares/sg/system/system.hpp +++ b/ares/sg/system/system.hpp @@ -1,6 +1,5 @@ struct System { Node::System node; - Node::Setting::String regionNode; struct Controls { Node::Object node; @@ -11,10 +10,10 @@ struct System { auto poll() -> void; } controls; - enum class Model : uint { SG1000, SC3000 }; - enum class Region : uint { NTSC, PAL }; + enum class Model : u32 { SG1000, SC3000 }; + enum class Region : u32 { NTSC, PAL }; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto region() const -> Region { return information.region; } auto colorburst() const -> double { return information.colorburst; } @@ -34,9 +33,10 @@ struct System { private: struct Information { + string name = "SG-1000"; Model model = Model::SG1000; Region region = Region::NTSC; - double colorburst = Constants::Colorburst::NTSC; + f64 colorburst = Constants::Colorburst::NTSC; } information; //serialization.cpp diff --git a/ares/sg/vdp/color.cpp b/ares/sg/vdp/color.cpp index a4baba508e..53f3dd7ccf 100644 --- a/ares/sg/vdp/color.cpp +++ b/ares/sg/vdp/color.cpp @@ -1,4 +1,4 @@ -auto VDP::color(uint32 color) -> uint64 { +auto VDP::color(n32 color) -> n64 { switch(color.bit(0,3)) { case 0: return 0x0000'0000'0000ull; //transparent case 1: return 0x0000'0000'0000ull; //black diff --git a/ares/sg/vdp/vdp.cpp b/ares/sg/vdp/vdp.cpp index 5edbf6e8be..c5a7905574 100644 --- a/ares/sg/vdp/vdp.cpp +++ b/ares/sg/vdp/vdp.cpp @@ -26,7 +26,7 @@ auto VDP::unload() -> void { node.reset(); } -auto VDP::step(uint clocks) -> void { +auto VDP::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } diff --git a/ares/sg/vdp/vdp.hpp b/ares/sg/vdp/vdp.hpp index 7af96b8cea..af5a7e4321 100644 --- a/ares/sg/vdp/vdp.hpp +++ b/ares/sg/vdp/vdp.hpp @@ -6,13 +6,13 @@ struct VDP : TMS9918, Thread { auto load(Node::Object) -> void; auto unload() -> void; - auto step(uint clocks) -> void override; + auto step(u32 clocks) -> void override; auto irq(bool line) -> void override; auto frame() -> void override; auto power() -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; diff --git a/ares/ws/apu/apu.cpp b/ares/ws/apu/apu.cpp index 76be0f8419..cc535d0671 100644 --- a/ares/ws/apu/apu.cpp +++ b/ares/ws/apu/apu.cpp @@ -38,15 +38,15 @@ auto APU::main() -> void { step(1); } -auto APU::sample(uint channel, uint5 index) -> uint4 { - uint8 data = iram.read((r.waveBase << 6) + (--channel << 4) + (index >> 1)); +auto APU::sample(u32 channel, n5 index) -> n4 { + n8 data = iram.read((r.waveBase << 6) + (--channel << 4) + (index >> 1)); if(index.bit(0) == 0) return data.bit(0,3); if(index.bit(0) == 1) return data.bit(4,7); unreachable; } auto APU::dacRun() -> void { - int left = 0; + s32 left = 0; if(channel1.r.enable) left += channel1.o.left; if(channel2.r.enable) left += channel2.o.left; if(channel3.r.enable) left += channel3.o.left; @@ -54,7 +54,7 @@ auto APU::dacRun() -> void { if(channel5.r.enable) left += channel5.o.left * r.headphonesConnected; left = sclamp<16>(left << 5); - int right = 0; + s32 right = 0; if(channel1.r.enable) right += channel1.o.right; if(channel2.r.enable) right += channel2.o.right; if(channel3.r.enable) right += channel3.o.right; @@ -80,7 +80,7 @@ auto APU::dacRun() -> void { stream->frame(left / 32768.0 * amplitude, right / 32768.0 * amplitude); } -auto APU::step(uint clocks) -> void { +auto APU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } diff --git a/ares/ws/apu/apu.hpp b/ares/ws/apu/apu.hpp index c4c3289784..bd6b347eca 100644 --- a/ares/ws/apu/apu.hpp +++ b/ares/ws/apu/apu.hpp @@ -7,59 +7,59 @@ struct APU : Thread, IO { auto unload() -> void; auto main() -> void; - auto sample(uint channel, uint5 index) -> uint4; + auto sample(u32 channel, n5 index) -> n4; auto dacRun() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; //io.cpp - auto portRead(uint16 address) -> uint8; - auto portWrite(uint16 address, uint8 data) -> void; + auto portRead(n16 address) -> n8; + auto portWrite(n16 address, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; struct State { - uint13 sweepClock; + n13 sweepClock; } s; struct Registers { //$008f SND_WAVE_BASE - uint8 waveBase; + n8 waveBase; //$0091 SND_OUTPUT - uint1 speakerEnable; - uint2 speakerShift; - uint1 headphonesEnable; - uint1 headphonesConnected; + n1 speakerEnable; + n2 speakerShift; + n1 headphonesEnable; + n1 headphonesConnected; //$009e SND_VOLUME - uint2 masterVolume; + n2 masterVolume; } r; struct DMA { auto run() -> void; struct State { - uint clock; - uint20 source; - uint20 length; + u32 clock; + n20 source; + n20 length; } s; struct Registers { //$004a-$004c SDMA_SRC - uint20 source; + n20 source; //$004e-$0050 SDMA_LEN - uint20 length; + n20 length; //$0052 SDMA_CTRL - uint2 rate; - uint1 unknown; - uint1 loop; - uint1 target; - uint1 direction; - uint1 enable; + n2 rate; + n1 unknown; + n1 loop; + n1 target; + n1 direction; + n1 enable; } r; } dma; @@ -67,25 +67,25 @@ struct APU : Thread, IO { auto run() -> void; struct Output { - uint8 left; - uint8 right; + n8 left; + n8 right; } o; struct State { - uint11 period; - uint5 sampleOffset; + n11 period; + n5 sampleOffset; } s; struct Registers { //$0080-0081 SND_CH1_PITCH - uint11 pitch; + n11 pitch; //$0088 SND_CH1_VOL - uint4 volumeLeft; - uint4 volumeRight; + n4 volumeLeft; + n4 volumeRight; //$0090 SND_CTRL - uint1 enable; + n1 enable; } r; } channel1; @@ -93,30 +93,30 @@ struct APU : Thread, IO { auto run() -> void; struct Output { - uint8 left; - uint8 right; + n8 left; + n8 right; } o; struct State { - uint11 period; - uint5 sampleOffset; + n11 period; + n5 sampleOffset; } s; struct Registers { //$0082-0083 SND_CH2_PITCH - uint11 pitch; + n11 pitch; //$0089 SND_CH2_VOL - uint4 volumeLeft; - uint4 volumeRight; + n4 volumeLeft; + n4 volumeRight; //$0090 SND_CTRL - uint1 enable; - uint1 voice; + n1 enable; + n1 voice; //$0094 SND_VOICE_CTRL - uint2 voiceEnableLeft; - uint2 voiceEnableRight; + n2 voiceEnableLeft; + n2 voiceEnableRight; } r; } channel2; @@ -125,70 +125,70 @@ struct APU : Thread, IO { auto run() -> void; struct Output { - uint8 left; - uint8 right; + n8 left; + n8 right; } o; struct State { - uint11 period; - uint5 sampleOffset; + n11 period; + n5 sampleOffset; - int sweepCounter; + s32 sweepCounter; } s; struct Registers { //$0084-0085 SND_CH3_PITCH - uint11 pitch; + n11 pitch; //$008a SND_CH3_VOL - uint4 volumeLeft; - uint4 volumeRight; + n4 volumeLeft; + n4 volumeRight; //$008c SND_SWEEP_VALUE - int8 sweepValue; + i8 sweepValue; //$008d SND_SWEEP_TIME - uint5 sweepTime; + n5 sweepTime; //$0090 SND_CTRL - uint1 enable; - uint1 sweep; + n1 enable; + n1 sweep; } r; } channel3; struct Channel4 { - auto noiseSample() -> uint4; + auto noiseSample() -> n4; auto run() -> void; struct Output { - uint8 left; - uint8 right; + n8 left; + n8 right; } o; struct State { - uint11 period; - uint5 sampleOffset; + n11 period; + n5 sampleOffset; - uint1 noiseOutput; - uint15 noiseLFSR; + n1 noiseOutput; + n15 noiseLFSR; } s; struct Registers { //$0086-0087 SND_CH4_PITCH - uint11 pitch; + n11 pitch; //$008b SND_CH4_VOL - uint4 volumeLeft; - uint4 volumeRight; + n4 volumeLeft; + n4 volumeRight; //$008e SND_NOISE - uint3 noiseMode; - uint1 noiseReset; - uint1 noiseUpdate; + n3 noiseMode; + n1 noiseReset; + n1 noiseUpdate; //$0090 SND_CTRL - uint1 enable; - uint1 noise; + n1 enable; + n1 noise; } r; } channel4; @@ -196,26 +196,26 @@ struct APU : Thread, IO { auto run() -> void; struct Output { - int11 left; - int11 right; + i11 left; + i11 right; } o; struct State { - uint clock; - int8 data; + u32 clock; + i8 data; } s; struct Registers { //$006a HYPER_CTRL - uint2 volume; - uint2 scale; - uint3 speed; - uint1 enable; + n2 volume; + n2 scale; + n3 speed; + n1 enable; //$006b HYPER_CHAN_CTRL - uint4 unknown; - uint1 leftEnable; - uint1 rightEnable; + n4 unknown; + n1 leftEnable; + n1 rightEnable; } r; } channel5; }; diff --git a/ares/ws/apu/channel2.cpp b/ares/ws/apu/channel2.cpp index 42cf8fc0c1..bad824c56c 100644 --- a/ares/ws/apu/channel2.cpp +++ b/ares/ws/apu/channel2.cpp @@ -1,8 +1,8 @@ auto APU::Channel2::run() -> void { if(r.voice) { - uint8 volume = r.volumeLeft << 4 | r.volumeRight << 0; - o.left = r.voiceEnableLeft ? volume : (uint8)0; - o.right = r.voiceEnableRight ? volume : (uint8)0; + n8 volume = r.volumeLeft << 4 | r.volumeRight << 0; + o.left = r.voiceEnableLeft ? volume : (n8)0; + o.right = r.voiceEnableRight ? volume : (n8)0; } else if(--s.period == r.pitch) { s.period = 0; auto output = apu.sample(2, s.sampleOffset++); diff --git a/ares/ws/apu/channel4.cpp b/ares/ws/apu/channel4.cpp index c71da08d90..f8ea1db0e5 100644 --- a/ares/ws/apu/channel4.cpp +++ b/ares/ws/apu/channel4.cpp @@ -1,4 +1,4 @@ -auto APU::Channel4::noiseSample() -> uint4 { +auto APU::Channel4::noiseSample() -> n4 { return s.noiseOutput ? 0xf : 0x0; } @@ -17,7 +17,7 @@ auto APU::Channel4::run() -> void { } if(r.noiseUpdate) { - static const int taps[8] = {14, 10, 13, 4, 8, 6, 9, 11}; + static const s32 taps[8] = {14, 10, 13, 4, 8, 6, 9, 11}; auto tap = taps[r.noiseMode]; s.noiseOutput = (1 ^ (s.noiseLFSR >> 7) ^ (s.noiseLFSR >> tap)) & 1; diff --git a/ares/ws/apu/channel5.cpp b/ares/ws/apu/channel5.cpp index 4c05145174..1c398b0b6b 100644 --- a/ares/ws/apu/channel5.cpp +++ b/ares/ws/apu/channel5.cpp @@ -1,12 +1,12 @@ auto APU::Channel5::run() -> void { - int11 output; + i11 output; switch(r.scale) { - case 0: output = (uint8)s.data << 3 - r.volume; break; - case 1: output = (uint8)s.data - 0x100 << 3 - r.volume; break; - case 2: output = (int8)s.data << 3 - r.volume; break; - case 3: output = (uint8)s.data << 3; break; + case 0: output = (n8)s.data << 3 - r.volume; break; + case 1: output = (n8)s.data - 0x100 << 3 - r.volume; break; + case 2: output = (i8)s.data << 3 - r.volume; break; + case 3: output = (n8)s.data << 3; break; } - o.left = r.leftEnable ? output : (int11)0; - o.right = r.rightEnable ? output : (int11)0; + o.left = r.leftEnable ? output : (i11)0; + o.right = r.rightEnable ? output : (i11)0; } diff --git a/ares/ws/apu/dma.cpp b/ares/ws/apu/dma.cpp index d907ec8bf6..41d75821bf 100644 --- a/ares/ws/apu/dma.cpp +++ b/ares/ws/apu/dma.cpp @@ -7,7 +7,7 @@ auto APU::DMA::run() -> void { if(r.rate == 3 && ++s.clock < 128) return; //24000hz s.clock = 0; - uint8 data = bus.read(s.source); + n8 data = bus.read(s.source); if(r.direction == 0) s.source++; if(r.direction == 1) s.source--; diff --git a/ares/ws/apu/io.cpp b/ares/ws/apu/io.cpp index f20b826086..30624f6efa 100644 --- a/ares/ws/apu/io.cpp +++ b/ares/ws/apu/io.cpp @@ -1,5 +1,5 @@ -auto APU::portRead(uint16 address) -> uint8 { - uint8 data; +auto APU::portRead(n16 address) -> n8 { + n8 data; //SDMA_SRC if(address == 0x004a) return dma.s.source.bit( 0, 7); @@ -154,7 +154,7 @@ auto APU::portRead(uint16 address) -> uint8 { return data; } -auto APU::portWrite(uint16 address, uint8 data) -> void { +auto APU::portWrite(n16 address, n8 data) -> void { //SDMA_SRC if(address == 0x004a) { dma.r.source.bit( 0, 7) = data.bit(0,7); return; } if(address == 0x004b) { dma.r.source.bit( 8,15) = data.bit(0,7); return; } diff --git a/ares/ws/cartridge/cartridge.cpp b/ares/ws/cartridge/cartridge.cpp index 212d4705f8..39781ce16e 100644 --- a/ares/ws/cartridge/cartridge.cpp +++ b/ares/ws/cartridge/cartridge.cpp @@ -30,8 +30,8 @@ auto Cartridge::connect() -> void { if(auto memory = document["game/board/memory(type=ROM,content=Program)"]) { rom.size = memory["size"].natural(); rom.mask = bit::round(rom.size) - 1; - rom.data = new uint8[rom.mask + 1]; - memory::fill(rom.data, rom.mask + 1, 0xff); + rom.data = new n8[rom.mask + 1]; + memory::fill(rom.data, rom.mask + 1, 0xff); if(auto fp = platform->open(node, "program.rom", File::Read, File::Required)) { fp->read(rom.data, rom.size); } @@ -40,8 +40,8 @@ auto Cartridge::connect() -> void { if(auto memory = document["game/board/memory(type=RAM,content=Save)"]) { ram.size = memory["size"].natural(); ram.mask = bit::round(ram.size) - 1; - ram.data = new uint8[ram.mask + 1]; - memory::fill(ram.data, ram.mask + 1, 0xff); + ram.data = new n8[ram.mask + 1]; + memory::fill(ram.data, ram.mask + 1, 0xff); if(!memory["volatile"]) { if(auto fp = platform->open(node, "save.ram", File::Read)) { fp->read(ram.data, ram.size); @@ -59,8 +59,8 @@ auto Cartridge::connect() -> void { if(auto memory = document["game/board/memory(type=RTC,content=Time)"]) { rtc.size = memory["size"].natural(); rtc.mask = bit::round(rtc.size) - 1; - rtc.data = new uint8[rtc.mask + 1]; - memory::fill(rtc.data, rtc.mask + 1, 0x00); + rtc.data = new n8[rtc.mask + 1]; + memory::fill(rtc.data, rtc.mask + 1, 0x00); if(!memory["volatile"]) { if(auto fp = platform->open(node, "time.rtc", File::Read)) { fp->read(rtc.data, rtc.size); @@ -130,7 +130,7 @@ auto Cartridge::main() -> void { step(3'072'000); } -auto Cartridge::step(uint clocks) -> void { +auto Cartridge::step(u32 clocks) -> void { Thread::step(clocks); synchronize(cpu); } diff --git a/ares/ws/cartridge/cartridge.hpp b/ares/ws/cartridge/cartridge.hpp index 519f8282ea..104bddf675 100644 --- a/ares/ws/cartridge/cartridge.hpp +++ b/ares/ws/cartridge/cartridge.hpp @@ -14,28 +14,28 @@ struct Cartridge : Thread, IO { auto power() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; //memory.cpp - auto romRead(uint20 address) -> uint8; - auto romWrite(uint20 address, uint8 data) -> void; + auto romRead(n20 address) -> n8; + auto romWrite(n20 address, n8 data) -> void; - auto ramRead(uint20 address) -> uint8; - auto ramWrite(uint20 address, uint8 data) -> void; + auto ramRead(n20 address) -> n8; + auto ramWrite(n20 address, n8 data) -> void; //rtc.cpp auto rtcLoad() -> void; auto rtcSave() -> void; auto rtcTickSecond() -> void; auto rtcCheckAlarm() -> void; - auto rtcStatus() -> uint8; - auto rtcCommand(uint8 data) -> void; - auto rtcRead() -> uint8; - auto rtcWrite(uint8 data) -> void; + auto rtcStatus() -> n8; + auto rtcCommand(n8 data) -> void; + auto rtcRead() -> n8; + auto rtcWrite(n8 data) -> void; //io.cpp - auto portRead(uint16 address) -> uint8 override; - auto portWrite(uint16 address, uint8 data) -> void override; + auto portRead(n16 address) -> n8 override; + auto portWrite(n16 address, n8 data) -> void override; //serialization.cpp auto serialize(serializer&) -> void; @@ -48,45 +48,45 @@ struct Cartridge : Thread, IO { struct Registers { //$00c0 BANK_ROM2 - uint8 romBank2 = 0xff; + n8 romBank2 = 0xff; //$00c1 BANK_SRAM - uint8 sramBank = 0xff; + n8 sramBank = 0xff; //$00c2 BANK_ROM0 - uint8 romBank0 = 0xff; + n8 romBank0 = 0xff; //$00c3 BANK_ROM1 - uint8 romBank1 = 0xff; + n8 romBank1 = 0xff; //$00cc GPO_EN - uint8 gpoEnable; + n8 gpoEnable; //$00cd GPO_DATA - uint8 gpoData; + n8 gpoData; } r; struct Memory { - uint8* data = nullptr; - uint size = 0; - uint mask = 0; + n8* data = nullptr; + u32 size = 0; + u32 mask = 0; }; struct RTC : Memory { - uint8 command; - uint4 index; - - uint8 alarm; - uint8 alarmHour; - uint8 alarmMinute; - - auto year() -> uint8& { return data[0]; } - auto month() -> uint8& { return data[1]; } - auto day() -> uint8& { return data[2]; } - auto weekday() -> uint8& { return data[3]; } - auto hour() -> uint8& { return data[4]; } - auto minute() -> uint8& { return data[5]; } - auto second() -> uint8& { return data[6]; } + n8 command; + n4 index; + + n8 alarm; + n8 alarmHour; + n8 alarmMinute; + + auto year() -> n8& { return data[0]; } + auto month() -> n8& { return data[1]; } + auto day() -> n8& { return data[2]; } + auto weekday() -> n8& { return data[3]; } + auto hour() -> n8& { return data[4]; } + auto minute() -> n8& { return data[5]; } + auto second() -> n8& { return data[6]; } }; Memory rom; diff --git a/ares/ws/cartridge/io.cpp b/ares/ws/cartridge/io.cpp index 19d4b98451..83585fa37d 100644 --- a/ares/ws/cartridge/io.cpp +++ b/ares/ws/cartridge/io.cpp @@ -1,5 +1,5 @@ -auto Cartridge::portRead(uint16 address) -> uint8 { - uint8 data; +auto Cartridge::portRead(n16 address) -> n8 { + n8 data; //BANK_ROM2 if(address == 0x00c0) return r.romBank2; @@ -39,7 +39,7 @@ auto Cartridge::portRead(uint16 address) -> uint8 { return data; } -auto Cartridge::portWrite(uint16 address, uint8 data) -> void { +auto Cartridge::portWrite(n16 address, n8 data) -> void { //BANK_ROM2 if(address == 0x00c0) r.romBank2 = data; diff --git a/ares/ws/cartridge/memory.cpp b/ares/ws/cartridge/memory.cpp index 9bfe5719e1..afa4ed99d1 100644 --- a/ares/ws/cartridge/memory.cpp +++ b/ares/ws/cartridge/memory.cpp @@ -1,27 +1,27 @@ //20000-fffff -auto Cartridge::romRead(uint20 address) -> uint8 { +auto Cartridge::romRead(n20 address) -> n8 { if(!rom.data) return 0x00; - uint28 offset; + n28 offset; switch(address.byte(2)) { - case 2: offset = r.romBank0 << 16 | (uint16)address; break; //20000-2ffff - case 3: offset = r.romBank1 << 16 | (uint16)address; break; //30000-3ffff - default: offset = r.romBank2 << 20 | (uint20)address; break; //40000-fffff + case 2: offset = r.romBank0 << 16 | (n16)address; break; //20000-2ffff + case 3: offset = r.romBank1 << 16 | (n16)address; break; //30000-3ffff + default: offset = r.romBank2 << 20 | (n20)address; break; //40000-fffff } return rom.data[offset & rom.mask]; } -auto Cartridge::romWrite(uint20 address, uint8 data) -> void { +auto Cartridge::romWrite(n20 address, n8 data) -> void { } //10000-1ffff -auto Cartridge::ramRead(uint20 address) -> uint8 { +auto Cartridge::ramRead(n20 address) -> n8 { if(!ram.data) return 0x00; - uint24 offset = r.sramBank << 16 | (uint16)address; + n24 offset = r.sramBank << 16 | (n16)address; return ram.data[offset & ram.mask]; } -auto Cartridge::ramWrite(uint20 address, uint8 data) -> void { +auto Cartridge::ramWrite(n20 address, n8 data) -> void { if(!ram.data) return; - uint24 offset = r.sramBank << 16 | (uint16)address; + n24 offset = r.sramBank << 16 | (n16)address; ram.data[offset & ram.mask] = data; } diff --git a/ares/ws/cartridge/rtc.cpp b/ares/ws/cartridge/rtc.cpp index b083a559ee..fd36200eed 100644 --- a/ares/ws/cartridge/rtc.cpp +++ b/ares/ws/cartridge/rtc.cpp @@ -1,7 +1,7 @@ //calculate time between last play of game and current time; //increment RTC by said amount of seconds auto Cartridge::rtcLoad() -> void { - uint64 timestamp = 0; + n64 timestamp = 0; for(auto n : range(8)) timestamp.byte(n) = rtc.data[8 + n]; if(!timestamp) return; //new save file @@ -11,7 +11,7 @@ auto Cartridge::rtcLoad() -> void { //save time when game is unloaded auto Cartridge::rtcSave() -> void { - uint64 timestamp = time(0); + n64 timestamp = time(0); for(auto n : range(8)) rtc.data[8 + n] = timestamp.byte(n); } @@ -28,7 +28,7 @@ auto Cartridge::rtcTickSecond() -> void { rtc.weekday() += 1; rtc.weekday() %= 7; - uint daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + u32 daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if(rtc.year() && (rtc.year() % 100) && !(rtc.year() % 4)) daysInMonth[1]++; if(++rtc.day() < daysInMonth[rtc.month()]) return; @@ -50,11 +50,11 @@ auto Cartridge::rtcCheckAlarm() -> void { } } -auto Cartridge::rtcStatus() -> uint8 { +auto Cartridge::rtcStatus() -> n8 { return 0x80; } -auto Cartridge::rtcCommand(uint8 data) -> void { +auto Cartridge::rtcCommand(n8 data) -> void { rtc.command = data; //RESET @@ -89,10 +89,10 @@ auto Cartridge::rtcCommand(uint8 data) -> void { } } -auto Cartridge::rtcRead() -> uint8 { - uint8 data = 0; +auto Cartridge::rtcRead() -> n8 { + n8 data = 0; - static auto encode = [](uint8 data) -> uint8 { + static auto encode = [](n8 data) -> n8 { return ((data / 10) << 4) + (data % 10); }; @@ -113,8 +113,8 @@ auto Cartridge::rtcRead() -> uint8 { return data; } -auto Cartridge::rtcWrite(uint8 data) -> void { - static auto decode = [](uint8 data) -> uint8 { +auto Cartridge::rtcWrite(n8 data) -> void { + static auto decode = [](n8 data) -> n8 { return (data >> 4) * 10 + (data & 0x0f); }; diff --git a/ares/ws/cartridge/serialization.cpp b/ares/ws/cartridge/serialization.cpp index a08dc11475..34716e44da 100644 --- a/ares/ws/cartridge/serialization.cpp +++ b/ares/ws/cartridge/serialization.cpp @@ -1,9 +1,9 @@ auto Cartridge::serialize(serializer& s) -> void { Thread::serialize(s); - s(array_span{ram.data, ram.size}); + s(array_span{ram.data, ram.size}); s(eeprom); - s(array_span{rtc.data, rtc.size}); + s(array_span{rtc.data, rtc.size}); if(rtc.size) { s(rtc.command); diff --git a/ares/ws/cpu/cpu.cpp b/ares/ws/cpu/cpu.cpp index f3f2a6238a..5c89a55c38 100644 --- a/ares/ws/cpu/cpu.cpp +++ b/ares/ws/cpu/cpu.cpp @@ -27,28 +27,28 @@ auto CPU::main() -> void { exec(); } -auto CPU::step(uint clocks) -> void { +auto CPU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(); } -auto CPU::wait(uint clocks) -> void { +auto CPU::wait(u32 clocks) -> void { step(clocks); } -auto CPU::read(uint20 addr) -> uint8 { +auto CPU::read(n20 addr) -> n8 { return bus.read(addr); } -auto CPU::write(uint20 addr, uint8 data) -> void { +auto CPU::write(n20 addr, n8 data) -> void { return bus.write(addr, data); } -auto CPU::in(uint16 port) -> uint8 { +auto CPU::in(n16 port) -> n8 { return bus.portRead(port); } -auto CPU::out(uint16 port, uint8 data) -> void { +auto CPU::out(n16 port, n8 data) -> void { return bus.portWrite(port, data); } diff --git a/ares/ws/cpu/cpu.hpp b/ares/ws/cpu/cpu.hpp index 455cde7148..a1d738bea5 100644 --- a/ares/ws/cpu/cpu.hpp +++ b/ares/ws/cpu/cpu.hpp @@ -17,7 +17,7 @@ struct CPU : V30MZ, Thread, IO { } tracer; } debugger; - enum class Interrupt : uint { + enum class Interrupt : u32 { SerialSend, Input, Cartridge, @@ -33,20 +33,20 @@ struct CPU : V30MZ, Thread, IO { auto unload() -> void; auto main() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; - auto wait(uint clocks = 1) -> void override; - auto read(uint20 addr) -> uint8 override; - auto write(uint20 addr, uint8 data) -> void override; - auto in(uint16 port) -> uint8 override; - auto out(uint16 port, uint8 data) -> void override; + auto wait(u32 clocks = 1) -> void override; + auto read(n20 addr) -> n8 override; + auto write(n20 addr, n8 data) -> void override; + auto in(n16 port) -> n8 override; + auto out(n16 port, n8 data) -> void override; auto power() -> void; //io.cpp - auto keypadRead() -> uint4; - auto portRead(uint16 address) -> uint8 override; - auto portWrite(uint16 address, uint8 data) -> void override; + auto keypadRead() -> n4; + auto portRead(n16 address) -> n8 override; + auto portWrite(n16 address, n8 data) -> void override; //interrupt.cpp auto poll() -> void; @@ -61,39 +61,39 @@ struct CPU : V30MZ, Thread, IO { struct Registers { //$0040-0042 DMA_SRC - uint20 dmaSource; + n20 dmaSource; //$0044-0045 DMA_DST - uint16 dmaTarget; + n16 dmaTarget; //$0046-0047 DMA_LEN - uint16 dmaLength; + n16 dmaLength; //$0048 DMA_CTRL - uint1 dmaEnable; - uint1 dmaMode; //0 = increment; 1 = decrement + n1 dmaEnable; + n1 dmaMode; //0 = increment; 1 = decrement //$00a0 HW_FLAGS - uint1 cartridgeEnable; + n1 cartridgeEnable; //$00b0 INT_BASE - uint8 interruptBase; + n8 interruptBase; //$00b1 SER_DATA - uint8 serialData; + n8 serialData; //$00b2 INT_ENABLE - uint8 interruptEnable; + n8 interruptEnable; //$00b3 SER_STATUS - uint1 serialBaudRate; //0 = 9600; 1 = 38400 - uint1 serialEnable; + n1 serialBaudRate; //0 = 9600; 1 = 38400 + n1 serialEnable; //$00b4 INT_STATUS - uint8 interruptStatus; + n8 interruptStatus; //$00b5 KEYPAD - uint3 keypadMatrix; + n3 keypadMatrix; } r; }; diff --git a/ares/ws/cpu/debugger.cpp b/ares/ws/cpu/debugger.cpp index b33bbb23e9..10e6122b4a 100644 --- a/ares/ws/cpu/debugger.cpp +++ b/ares/ws/cpu/debugger.cpp @@ -15,7 +15,7 @@ auto CPU::Debugger::load(Node::Object parent) -> void { } auto CPU::Debugger::instruction() -> void { - if(tracer.instruction->enabled() && tracer.instruction->address(uint20(cpu.V30MZ::r.cs * 16 + cpu.V30MZ::r.ip))) { + if(tracer.instruction->enabled() && tracer.instruction->address(n20(cpu.V30MZ::r.cs * 16 + cpu.V30MZ::r.ip))) { if(auto instruction = cpu.disassembleInstruction()) { tracer.instruction->notify(instruction, cpu.disassembleContext()); } diff --git a/ares/ws/cpu/dma.cpp b/ares/ws/cpu/dma.cpp index c32fcd013a..c2c1c6c513 100644 --- a/ares/ws/cpu/dma.cpp +++ b/ares/ws/cpu/dma.cpp @@ -8,7 +8,7 @@ auto CPU::dmaTransfer() -> void { wait(5); while(r.dmaLength) { wait(2); - uint16 data = 0; + n16 data = 0; //once DMA is started; SRAM reads still incur time penalty, but do not transfer if(r.dmaSource.byte(2) != 1) { data |= read(r.dmaSource + 0) << 0; diff --git a/ares/ws/cpu/interrupt.cpp b/ares/ws/cpu/interrupt.cpp index 6a3338f188..061f1da5bb 100644 --- a/ares/ws/cpu/interrupt.cpp +++ b/ares/ws/cpu/interrupt.cpp @@ -1,7 +1,7 @@ auto CPU::poll() -> void { if(!state.poll) return; - for(int n = 7; n >= 0; n--) { + for(s32 n = 7; n >= 0; n--) { if(!r.interruptEnable.bit(n)) continue; if(!r.interruptStatus.bit(n)) continue; state.halt = false; @@ -17,10 +17,10 @@ auto CPU::poll() -> void { } auto CPU::raise(Interrupt irq) -> void { - if(!r.interruptEnable.bit((uint)irq)) return; - r.interruptStatus.bit((uint)irq) = 1; + if(!r.interruptEnable.bit((u32)irq)) return; + r.interruptStatus.bit((u32)irq) = 1; } auto CPU::lower(Interrupt irq) -> void { - r.interruptStatus.bit((uint)irq) = 0; + r.interruptStatus.bit((u32)irq) = 0; } diff --git a/ares/ws/cpu/io.cpp b/ares/ws/cpu/io.cpp index 374cc02d86..0251bddd59 100644 --- a/ares/ws/cpu/io.cpp +++ b/ares/ws/cpu/io.cpp @@ -1,5 +1,5 @@ -auto CPU::keypadRead() -> uint4 { - uint4 data; +auto CPU::keypadRead() -> n4 { + n4 data; bool horizontal = ppu.screen->rotation() == 0; if(Model::WonderSwan() || Model::WonderSwanColor() || Model::SwanCrystal()) { @@ -64,8 +64,8 @@ auto CPU::keypadRead() -> uint4 { return data; } -auto CPU::portRead(uint16 address) -> uint8 { - uint8 data; +auto CPU::portRead(n16 address) -> n8 { + n8 data; //DMA_SRC if(address == 0x0040) return r.dmaSource.byte(0); @@ -142,7 +142,7 @@ auto CPU::portRead(uint16 address) -> uint8 { return data; } -auto CPU::portWrite(uint16 address, uint8 data) -> void { +auto CPU::portWrite(n16 address, n8 data) -> void { //DMA_SRC if(address == 0x0040) { r.dmaSource.byte(0) = data & ~1; return; } if(address == 0x0041) { r.dmaSource.byte(1) = data; return; } diff --git a/ares/ws/eeprom/eeprom.cpp b/ares/ws/eeprom/eeprom.cpp index 90f293afab..d078921e35 100644 --- a/ares/ws/eeprom/eeprom.cpp +++ b/ares/ws/eeprom/eeprom.cpp @@ -9,8 +9,8 @@ auto EEPROM::power() -> void { r = {}; } -auto EEPROM::read(uint port) -> uint8 { - uint8 data; +auto EEPROM::read(u32 port) -> n8 { + n8 data; if(!size) return data = 0xff; if(port == DataLo) return r.data.byte(0); @@ -34,7 +34,7 @@ auto EEPROM::read(uint port) -> uint8 { return data; } -auto EEPROM::write(uint port, uint8 data) -> void { +auto EEPROM::write(u32 port, n8 data) -> void { if(!size) return; if(port == DataLo) { @@ -73,17 +73,17 @@ auto EEPROM::write(uint port, uint8 data) -> void { } //start bit + command bits + address bits - for(uint index : reverse(range(1 + 2 + input.addressLength))) input.write(r.address.bit(index)); + for(u32 index : reverse(range(1 + 2 + input.addressLength))) input.write(r.address.bit(index)); if(r.readPending) { edge(); output.read(); //padding bit - for(uint index : reverse(range(input.dataLength))) r.data.bit(index) = output.read(); + for(u32 index : reverse(range(input.dataLength))) r.data.bit(index) = output.read(); r.readPending = 0; } if(r.writePending) { - for(uint index : reverse(range(input.dataLength))) input.write(r.data.bit(index)); + for(u32 index : reverse(range(input.dataLength))) input.write(r.data.bit(index)); edge(); r.writePending = 0; } diff --git a/ares/ws/eeprom/eeprom.hpp b/ares/ws/eeprom/eeprom.hpp index 818545e3ae..8d5d75a453 100644 --- a/ares/ws/eeprom/eeprom.hpp +++ b/ares/ws/eeprom/eeprom.hpp @@ -1,5 +1,5 @@ struct EEPROM : M93LCx6 { - enum : uint { + enum : u32 { DataLo, DataHi, AddressLo, @@ -10,25 +10,25 @@ struct EEPROM : M93LCx6 { //eeprom.cpp auto power() -> void; - auto read(uint port) -> uint8; - auto write(uint port, uint8 data) -> void; + auto read(u32 port) -> n8; + auto write(u32 port, n8 data) -> void; //serialization.cpp auto serialize(serializer&) -> void; private: struct Registers { - uint16 data; - uint16 address; + n16 data; + n16 address; //note: timing is not yet emulated; ready bits always remain set. - uint1 readReady = 1; - uint1 writeReady = 1; - uint1 eraseReady = 1; - uint1 resetReady = 1; - uint1 readPending; - uint1 writePending; - uint1 erasePending; - uint1 resetPending; + n1 readReady = 1; + n1 writeReady = 1; + n1 eraseReady = 1; + n1 resetReady = 1; + n1 readPending; + n1 writePending; + n1 erasePending; + n1 resetPending; } r; }; diff --git a/ares/ws/memory/memory.cpp b/ares/ws/memory/memory.cpp index 9d536aa7c5..36f0584518 100644 --- a/ares/ws/memory/memory.cpp +++ b/ares/ws/memory/memory.cpp @@ -10,15 +10,15 @@ auto InternalRAM::power() -> void { } auto InternalRAM::serialize(serializer& s) -> void { - s(array_span{memory, SoC::ASWAN() ? 16_KiB : 64_KiB}); + s(array_span{memory, SoC::ASWAN() ? 16_KiB : 64_KiB}); } -auto InternalRAM::read(uint16 address) -> uint8 { +auto InternalRAM::read(n16 address) -> n8 { if(address >= system.memory()) return 0x90; return memory[address]; } -auto InternalRAM::write(uint16 address, uint8 data) -> void { +auto InternalRAM::write(n16 address, n8 data) -> void { if(address >= system.memory()) return; memory[address] = data; } @@ -27,38 +27,38 @@ auto Bus::power() -> void { for(auto& io : port) io = nullptr; } -auto Bus::read(uint20 address) -> uint8 { +auto Bus::read(n20 address) -> n8 { if(!cpu.r.cartridgeEnable && address >= 0x100000 - system.bootROM.size()) { return system.bootROM.read(address); } - uint4 bank = address.bit(16,19); + n4 bank = address.bit(16,19); if(bank == 0x0) return iram.read(address); if(bank == 0x1) return cartridge.ramRead(address); if(bank >= 0x2) return cartridge.romRead(address); return 0x00; } -auto Bus::write(uint20 address, uint8 data) -> void { +auto Bus::write(n20 address, n8 data) -> void { if(!cpu.r.cartridgeEnable && address >= 0x100000 - system.bootROM.size()) { return system.bootROM.write(address, data); } - uint4 bank = address.bit(16,19); + n4 bank = address.bit(16,19); if(bank == 0x0) return iram.write(address, data); if(bank == 0x1) return cartridge.ramWrite(address, data); if(bank >= 0x2) return cartridge.romWrite(address, data); } -auto Bus::map(IO* io, uint16_t lo, maybe hi) -> void { - for(uint address = lo; address <= (hi ? hi() : lo); address++) port[address] = io; +auto Bus::map(IO* io, u16 lo, maybe hi) -> void { + for(u32 address = lo; address <= (hi ? hi() : lo); address++) port[address] = io; } -auto Bus::portRead(uint16 address) -> uint8 { +auto Bus::portRead(n16 address) -> n8 { if(auto io = port[address]) return io->portRead(address); if(address == 0x00ca) return 0x80; //Mama Mitte (unknown status bit) return 0x00; } -auto Bus::portWrite(uint16 address, uint8 data) -> void { +auto Bus::portWrite(n16 address, n8 data) -> void { if(auto io = port[address]) return io->portWrite(address, data); } diff --git a/ares/ws/memory/memory.hpp b/ares/ws/memory/memory.hpp index 42be96fc04..f25fde108b 100644 --- a/ares/ws/memory/memory.hpp +++ b/ares/ws/memory/memory.hpp @@ -1,49 +1,49 @@ struct IO { - virtual auto portRead(uint16 address) -> uint8 = 0; - virtual auto portWrite(uint16 address, uint8 data) -> void = 0; + virtual auto portRead(n16 address) -> n8 = 0; + virtual auto portWrite(n16 address, n8 data) -> void = 0; }; struct InternalRAM { auto power() -> void; auto serialize(serializer&) -> void; - auto read(uint16 address) -> uint8; - auto write(uint16 address, uint8 data) -> void; + auto read(n16 address) -> n8; + auto write(n16 address, n8 data) -> void; //PPU byte reads only: //WS: address is always < 0x4000 - auto read8(uint16 address) const -> uint16 { + auto read8(n16 address) const -> n16 { return memory[address]; } //PPU word reads only: //address & 1 is always 0 //WS: address is always < 0x4000 - auto read16(uint16 address) const -> uint16 { + auto read16(n16 address) const -> n16 { return memory[address + 0] << 0 | memory[address + 1] << 8; } //PPU long reads only: //address & 3 is always 0 //WS: address is always < 0x4000 - auto read32(uint16 address) const -> uint32 { + auto read32(n16 address) const -> n32 { return memory[address + 0] << 0 | memory[address + 1] << 8 | memory[address + 2] << 16 | memory[address + 3] << 24; } private: - uint8 memory[65536]; + n8 memory[65536]; }; struct Bus { auto power() -> void; - auto read(uint20 address) -> uint8; - auto write(uint20 address, uint8 data) -> void; + auto read(n20 address) -> n8; + auto write(n20 address, n8 data) -> void; - auto map(IO* io, uint16_t lo, maybe hi = nothing) -> void; - auto portRead(uint16 address) -> uint8; - auto portWrite(uint16 address, uint8 data) -> void; + auto map(IO* io, u16 lo, maybe hi = nothing) -> void; + auto portRead(n16 address) -> n8; + auto portWrite(n16 address, n8 data) -> void; private: IO* port[64 * 1024] = {nullptr}; diff --git a/ares/ws/ppu/color.cpp b/ares/ws/ppu/color.cpp index dcd2f97818..85399b162f 100644 --- a/ares/ws/ppu/color.cpp +++ b/ares/ws/ppu/color.cpp @@ -1,11 +1,11 @@ -auto PPU::color(uint32 color) -> uint64 { - uint b = color.bit(0, 3); - uint g = color.bit(4, 7); - uint r = color.bit(8,11); +auto PPU::color(n32 color) -> n64 { + u32 b = color.bit(0, 3); + u32 g = color.bit(4, 7); + u32 r = color.bit(8,11); - uint64_t R = image::normalize(r, 4, 16); - uint64_t G = image::normalize(g, 4, 16); - uint64_t B = image::normalize(b, 4, 16); + u64 R = image::normalize(r, 4, 16); + u64 G = image::normalize(g, 4, 16); + u64 B = image::normalize(b, 4, 16); if(colorEmulation->value()) { R = (r * 26 + g * 4 + b * 2); diff --git a/ares/ws/ppu/io.cpp b/ares/ws/ppu/io.cpp index b9ba203f74..0beb1d5ce3 100644 --- a/ares/ws/ppu/io.cpp +++ b/ares/ws/ppu/io.cpp @@ -1,5 +1,5 @@ -auto PPU::portRead(uint16 address) -> uint8 { - uint8 data; +auto PPU::portRead(n16 address) -> n8 { + n8 data; //DISP_CTRL if(address == 0x0000) { @@ -205,7 +205,7 @@ auto PPU::portRead(uint16 address) -> uint8 { return data; } -auto PPU::portWrite(uint16 address, uint8 data) -> void { +auto PPU::portWrite(n16 address, n8 data) -> void { //DISP_CTRL if(address == 0x0000) { r.screenOneEnable = data.bit(0); diff --git a/ares/ws/ppu/latch.cpp b/ares/ws/ppu/latch.cpp index 1554082b50..e5566fc8ec 100644 --- a/ares/ws/ppu/latch.cpp +++ b/ares/ws/ppu/latch.cpp @@ -25,12 +25,12 @@ auto PPU::latchRegisters() -> void { l.spriteWindowY1 = r.spriteWindowY1; } -auto PPU::latchSprites(uint8 y) -> void { +auto PPU::latchSprites(n8 y) -> void { l.spriteCount = 0; if(!l.spriteEnable) return; - for(uint index : range(l.oamCount)) { - uint32 attributes = l.oam[!s.field][index]; - if((uint8)(y - attributes.bit(16,23)) > 7) continue; + for(u32 index : range(l.oamCount)) { + n32 attributes = l.oam[!s.field][index]; + if((n8)(y - attributes.bit(16,23)) > 7) continue; l.sprite[l.spriteCount] = attributes; if(++l.spriteCount >= 32) break; } @@ -38,11 +38,11 @@ auto PPU::latchSprites(uint8 y) -> void { //note: this implicitly latches spriteBase, spriteFirst, spriteCount auto PPU::latchOAM() -> void { - uint7 spriteIndex = r.spriteFirst; - uint8 spriteCount = min(128, (uint)r.spriteCount); - uint16 spriteBase = r.spriteBase.bit(0, depth() == 2 ? 4 : 5) << 9; + n7 spriteIndex = r.spriteFirst; + n8 spriteCount = min(128, (u32)r.spriteCount); + n16 spriteBase = r.spriteBase.bit(0, depth() == 2 ? 4 : 5) << 9; l.oamCount = spriteCount; - for(uint index : range(spriteCount)) { + for(u32 index : range(spriteCount)) { l.oam[s.field][index] = iram.read32(spriteBase + (spriteIndex++ << 2)); } } diff --git a/ares/ws/ppu/ppu.cpp b/ares/ws/ppu/ppu.cpp index 258036fcef..669e89e16a 100644 --- a/ares/ws/ppu/ppu.cpp +++ b/ares/ws/ppu/ppu.cpp @@ -14,8 +14,8 @@ auto PPU::load(Node::Object parent) -> void { //LCD display icons are simulated as an extended part of the LCD screen using sprites //this isn't ideal as the display icons are vectors, but it's the best we can do for now - const uint width = 224 + (SoC::ASWAN() ? 0 : 13); - const uint height = 144 + (Model::WonderSwan() ? 13 : 0); + const u32 width = 224 + (SoC::ASWAN() ? 0 : 13); + const u32 height = 144 + (Model::WonderSwan() ? 13 : 0); screen = node->append("Screen", width, height); screen->colors(1 << 12, {&PPU::color, this}); @@ -175,11 +175,11 @@ auto PPU::main() -> void { } if(s.vtime < 144) { - uint y = s.vtime % (r.vtotal + 1); + u32 y = s.vtime % (r.vtotal + 1); auto line = screen->pixels().data() + y * screen->width(); latchRegisters(); latchSprites(y); - for(uint x : range(224)) { + for(u32 x : range(224)) { s.pixel = {Pixel::Source::Back, 0x000}; if(r.lcdEnable) { renderBack(); @@ -247,7 +247,7 @@ auto PPU::frame() -> void { scheduler.exit(Event::Frame); } -auto PPU::step(uint clocks) -> void { +auto PPU::step(u32 clocks) -> void { Thread::step(clocks); Thread::synchronize(cpu); } diff --git a/ares/ws/ppu/ppu.hpp b/ares/ws/ppu/ppu.hpp index 58515bb103..14a49bd2a9 100644 --- a/ares/ws/ppu/ppu.hpp +++ b/ares/ws/ppu/ppu.hpp @@ -27,9 +27,9 @@ struct PPU : Thread, IO { auto planar() const -> bool { return system.mode().bit(0) == 0; } auto packed() const -> bool { return system.mode().bit(0) == 1; } - auto depth() const -> uint { return system.mode().bit(1,2) != 3 ? 2 : 4; } + auto depth() const -> u32 { return system.mode().bit(1,2) != 3 ? 2 : 4; } auto grayscale() const -> bool { return system.mode().bit(1,2) == 0; } - auto tilemask() const -> uint { return 1023 >> !system.mode().bit(2); } + auto tilemask() const -> u32 { return 1023 >> !system.mode().bit(2); } //ppu.cpp auto load(Node::Object) -> void; @@ -38,197 +38,197 @@ struct PPU : Thread, IO { auto main() -> void; auto scanline() -> void; auto frame() -> void; - auto step(uint clocks) -> void; + auto step(u32 clocks) -> void; auto power() -> void; auto updateIcons() -> void; auto updateOrientation() -> void; //io.cpp - auto portRead(uint16 address) -> uint8 override; - auto portWrite(uint16 address, uint8 data) -> void override; + auto portRead(n16 address) -> n8 override; + auto portWrite(n16 address, n8 data) -> void override; //latch.cpp auto latchRegisters() -> void; - auto latchSprites(uint8 y) -> void; + auto latchSprites(n8 y) -> void; auto latchOAM() -> void; //render.cpp - auto renderFetch(uint10 tile, uint3 x, uint3 y) -> uint4; - auto renderTransparent(bool palette, uint4 color) -> bool; - auto renderPalette(uint4 palette, uint4 color) -> uint12; + auto renderFetch(n10 tile, n3 x, n3 y) -> n4; + auto renderTransparent(bool palette, n4 color) -> bool; + auto renderPalette(n4 palette, n4 color) -> n12; auto renderBack() -> void; - auto renderScreenOne(uint8 x, uint8 y) -> void; - auto renderScreenTwo(uint8 x, uint8 y) -> void; - auto renderSprite(uint8 x, uint8 y) -> void; + auto renderScreenOne(n8 x, n8 y) -> void; + auto renderScreenTwo(n8 x, n8 y) -> void; + auto renderSprite(n8 x, n8 y) -> void; //color.cpp - auto color(uint32) -> uint64; + auto color(n32) -> n64; //serialization.cpp auto serialize(serializer&) -> void; //state struct Pixel { - enum class Source : uint { Back, ScreenOne, ScreenTwo, Sprite }; + enum class Source : u32 { Back, ScreenOne, ScreenTwo, Sprite }; Source source; - uint12 color; + n12 color; }; struct State { - uint1 field = 0; - uint8 vtime = 0; + n1 field = 0; + n8 vtime = 0; Pixel pixel; } s; struct Latches { //latchRegisters() - uint8 backColor; - - uint1 screenOneEnable; - uint4 screenOneMapBase; - uint8 scrollOneX; - uint8 scrollOneY; - - uint1 screenTwoEnable; - uint4 screenTwoMapBase; - uint8 scrollTwoX; - uint8 scrollTwoY; - uint1 screenTwoWindowEnable; - uint1 screenTwoWindowInvert; - uint8 screenTwoWindowX0; - uint8 screenTwoWindowY0; - uint8 screenTwoWindowX1; - uint8 screenTwoWindowY1; - - uint1 spriteEnable; - uint1 spriteWindowEnable; - uint8 spriteWindowX0; - uint8 spriteWindowY0; - uint8 spriteWindowX1; - uint8 spriteWindowY1; + n8 backColor; + + n1 screenOneEnable; + n4 screenOneMapBase; + n8 scrollOneX; + n8 scrollOneY; + + n1 screenTwoEnable; + n4 screenTwoMapBase; + n8 scrollTwoX; + n8 scrollTwoY; + n1 screenTwoWindowEnable; + n1 screenTwoWindowInvert; + n8 screenTwoWindowX0; + n8 screenTwoWindowY0; + n8 screenTwoWindowX1; + n8 screenTwoWindowY1; + + n1 spriteEnable; + n1 spriteWindowEnable; + n8 spriteWindowX0; + n8 spriteWindowY0; + n8 spriteWindowX1; + n8 spriteWindowY1; //latchSprites() - uint32 sprite[32]; - uint spriteCount = 0; + n32 sprite[32]; + u32 spriteCount = 0; //latchOAM() - uint32 oam[2][128]; - uint oamCount = 0; + n32 oam[2][128]; + u32 oamCount = 0; //updateOrientation() - uint1 orientation; + n1 orientation; } l; struct Registers { //$0000 DISP_CTRL - uint1 screenOneEnable; - uint1 screenTwoEnable; - uint1 spriteEnable; - uint1 spriteWindowEnable; - uint1 screenTwoWindowInvert; - uint1 screenTwoWindowEnable; + n1 screenOneEnable; + n1 screenTwoEnable; + n1 spriteEnable; + n1 spriteWindowEnable; + n1 screenTwoWindowInvert; + n1 screenTwoWindowEnable; //$0001 BACK_COLOR - uint8 backColor; + n8 backColor; //$0003 LINE_CMP - uint8 lineCompare; + n8 lineCompare; //$0004 SPR_BASE - uint6 spriteBase; + n6 spriteBase; //$0005 SPR_FIRST - uint7 spriteFirst; + n7 spriteFirst; //$0006 SPR_COUNT - uint8 spriteCount; //0 - 128 + n8 spriteCount; //0 - 128 //$0007 MAP_BASE - uint4 screenOneMapBase; - uint4 screenTwoMapBase; + n4 screenOneMapBase; + n4 screenTwoMapBase; //$0008 SCR2_WIN_X0 - uint8 screenTwoWindowX0; + n8 screenTwoWindowX0; //$0009 SCR2_WIN_Y0 - uint8 screenTwoWindowY0; + n8 screenTwoWindowY0; //$000a SCR2_WIN_X1 - uint8 screenTwoWindowX1; + n8 screenTwoWindowX1; //$000b SCR2_WIN_Y1 - uint8 screenTwoWindowY1; + n8 screenTwoWindowY1; //$000c SPR_WIN_X0 - uint8 spriteWindowX0; + n8 spriteWindowX0; //$000d SPR_WIN_Y0 - uint8 spriteWindowY0; + n8 spriteWindowY0; //$000e SPR_WIN_X1 - uint8 spriteWindowX1; + n8 spriteWindowX1; //$000f SPR_WIN_Y1 - uint8 spriteWindowY1; + n8 spriteWindowY1; //$0010 SCR1_X - uint8 scrollOneX; + n8 scrollOneX; //$0011 SCR1_Y - uint8 scrollOneY; + n8 scrollOneY; //$0012 SCR2_X - uint8 scrollTwoX; + n8 scrollTwoX; //$0013 SCR2_Y - uint8 scrollTwoY; + n8 scrollTwoY; //$0014 LCD_CTRL - uint1 lcdEnable; - uint1 lcdContrast; //0 = low, 1 = high (WonderSwan Color only) - uint8 lcdUnknown; + n1 lcdEnable; + n1 lcdContrast; //0 = low, 1 = high (WonderSwan Color only) + n8 lcdUnknown; //$0015 LCD_ICON struct Icon { - uint1 sleeping; - uint1 orientation1; - uint1 orientation0; - uint1 auxiliary0; - uint1 auxiliary1; - uint1 auxiliary2; + n1 sleeping; + n1 orientation1; + n1 orientation0; + n1 auxiliary0; + n1 auxiliary1; + n1 auxiliary2; } icon; //$0016 LCD_VTOTAL - uint8 vtotal = 158; + n8 vtotal = 158; //$0017 LCD_VSYNC - uint8 vsync = 155; + n8 vsync = 155; //$001c-001f PALMONO_POOL - uint4 pool[8]; + n4 pool[8]; //$0020-003f PALMONO struct Palette { - uint3 color[4]; + n3 color[4]; } palette[16]; //$00a2 TMR_CTRL - uint1 htimerEnable; - uint1 htimerRepeat; - uint1 vtimerEnable; - uint1 vtimerRepeat; + n1 htimerEnable; + n1 htimerRepeat; + n1 vtimerEnable; + n1 vtimerRepeat; //$00a4,$00a5 HTMR_FREQ - uint16 htimerFrequency; + n16 htimerFrequency; //$00a6,$00a7 VTMR_FREQ - uint16 vtimerFrequency; + n16 vtimerFrequency; //$00a8,$00a9 HTMR_CTR - uint16 htimerCounter; + n16 htimerCounter; //$00aa,$00ab VTMR_CTR - uint16 vtimerCounter; + n16 vtimerCounter; } r; }; diff --git a/ares/ws/ppu/render.cpp b/ares/ws/ppu/render.cpp index e19538ba1c..2d04de9331 100644 --- a/ares/ws/ppu/render.cpp +++ b/ares/ws/ppu/render.cpp @@ -1,14 +1,14 @@ -auto PPU::renderFetch(uint10 tile, uint3 x, uint3 y) -> uint4 { - uint4 color; +auto PPU::renderFetch(n10 tile, n3 x, n3 y) -> n4 { + n4 color; if(planar() && depth() == 2) { - uint16 data = iram.read16(0x2000 + (tile << 4) + (y << 1)); + n16 data = iram.read16(0x2000 + (tile << 4) + (y << 1)); color.bit(0) = data.bit( 7 - x); color.bit(1) = data.bit(15 - x); } if(planar() && depth() == 4) { - uint32 data = iram.read32(0x4000 + (tile << 5) + (y << 2)); + n32 data = iram.read32(0x4000 + (tile << 5) + (y << 2)); color.bit(0) = data.bit( 7 - x); color.bit(1) = data.bit(15 - x); color.bit(2) = data.bit(23 - x); @@ -16,28 +16,28 @@ auto PPU::renderFetch(uint10 tile, uint3 x, uint3 y) -> uint4 { } if(packed() && depth() == 2) { - uint8 data = iram.read8(0x2000 + (tile << 4) + (y << 1) + (x >> 2)); + n8 data = iram.read8(0x2000 + (tile << 4) + (y << 1) + (x >> 2)); color.bit(0,1) = data >> 6 - (x.bit(0,1) << 1); } if(packed() && depth() == 4) { - uint8 data = iram.read8(0x4000 + (tile << 5) + (y << 2) + (x >> 1)); + n8 data = iram.read8(0x4000 + (tile << 5) + (y << 2) + (x >> 1)); color.bit(0,3) = data >> 4 - (x.bit(0) << 2); } return color; } -auto PPU::renderTransparent(bool palette, uint4 color) -> bool { +auto PPU::renderTransparent(bool palette, n4 color) -> bool { if(color) return false; if(depth() == 2 && !palette) return false; return true; } -auto PPU::renderPalette(uint4 palette, uint4 color) -> uint12 { +auto PPU::renderPalette(n4 palette, n4 color) -> n12 { if(grayscale()) { - uint3 paletteColor = r.palette[palette].color[color.bit(0,1)]; - uint4 poolColor = 15 - r.pool[paletteColor]; + n3 paletteColor = r.palette[palette].color[color.bit(0,1)]; + n4 poolColor = 15 - r.pool[paletteColor]; return poolColor << 0 | poolColor << 4 | poolColor << 8; } else { return iram.read16(0xfe00 + (palette << 5) + (color << 1)); @@ -46,34 +46,34 @@ auto PPU::renderPalette(uint4 palette, uint4 color) -> uint12 { auto PPU::renderBack() -> void { if(grayscale()) { - uint4 poolColor = 15 - r.pool[l.backColor.bit(0,2)]; + n4 poolColor = 15 - r.pool[l.backColor.bit(0,2)]; s.pixel = {Pixel::Source::Back, poolColor << 0 | poolColor << 4 | poolColor << 8}; } else { - uint12 color = iram.read16(0xfe00 + (l.backColor << 1)); + n12 color = iram.read16(0xfe00 + (l.backColor << 1)); s.pixel = {Pixel::Source::Back, color}; } } -auto PPU::renderScreenOne(uint8 x, uint8 y) -> void { - uint8 scrollX = x + l.scrollOneX; - uint8 scrollY = y + l.scrollOneY; +auto PPU::renderScreenOne(n8 x, n8 y) -> void { + n8 scrollX = x + l.scrollOneX; + n8 scrollY = y + l.scrollOneY; - uint15 tilemapOffset = 0; + n15 tilemapOffset = 0; tilemapOffset.bit( 1, 5) = scrollX >> 3; tilemapOffset.bit( 6,10) = scrollY >> 3; tilemapOffset.bit(11,14) = l.screenOneMapBase.bit(0, depth() == 2 ? 2 : 3); - uint16 attributes = iram.read16(tilemapOffset); - uint10 tile = attributes.bit(13) << 9 | attributes.bit(0,8); - uint3 tileX = scrollX ^ attributes.bit(14) * 7; - uint3 tileY = scrollY ^ attributes.bit(15) * 7; - uint4 tileColor = renderFetch(tile & tilemask(), tileX, tileY); + n16 attributes = iram.read16(tilemapOffset); + n10 tile = attributes.bit(13) << 9 | attributes.bit(0,8); + n3 tileX = scrollX ^ attributes.bit(14) * 7; + n3 tileY = scrollY ^ attributes.bit(15) * 7; + n4 tileColor = renderFetch(tile & tilemask(), tileX, tileY); if(renderTransparent(attributes.bit(11), tileColor)) return; s.pixel = {Pixel::Source::ScreenOne, renderPalette(attributes.bit(9,12), tileColor)}; } -auto PPU::renderScreenTwo(uint8 x, uint8 y) -> void { +auto PPU::renderScreenTwo(n8 x, n8 y) -> void { auto x0 = l.screenTwoWindowX0; auto x1 = l.screenTwoWindowX1; if(x0 > x1) swap(x0, x1); @@ -86,25 +86,25 @@ auto PPU::renderScreenTwo(uint8 x, uint8 y) -> void { windowInside ^= l.screenTwoWindowInvert; if(l.screenTwoWindowEnable && !windowInside) return; - uint8 scrollX = x + l.scrollTwoX; - uint8 scrollY = y + l.scrollTwoY; + n8 scrollX = x + l.scrollTwoX; + n8 scrollY = y + l.scrollTwoY; - uint15 tilemapOffset = 0; + n15 tilemapOffset = 0; tilemapOffset.bit( 1, 5) = scrollX >> 3; tilemapOffset.bit( 6,10) = scrollY >> 3; tilemapOffset.bit(11,14) = l.screenTwoMapBase.bit(0, depth() == 2 ? 2 : 3); - uint16 attributes = iram.read16(tilemapOffset); - uint10 tile = attributes.bit(13) << 9 | attributes.bit(0,8); - uint3 tileX = scrollX ^ attributes.bit(14) * 7; - uint3 tileY = scrollY ^ attributes.bit(15) * 7; - uint4 tileColor = renderFetch(tile & tilemask(), tileX, tileY); + n16 attributes = iram.read16(tilemapOffset); + n10 tile = attributes.bit(13) << 9 | attributes.bit(0,8); + n3 tileX = scrollX ^ attributes.bit(14) * 7; + n3 tileY = scrollY ^ attributes.bit(15) * 7; + n4 tileColor = renderFetch(tile & tilemask(), tileX, tileY); if(renderTransparent(attributes.bit(11), tileColor)) return; s.pixel = {Pixel::Source::ScreenTwo, renderPalette(attributes.bit(9,12), tileColor)}; } -auto PPU::renderSprite(uint8 x, uint8 y) -> void { +auto PPU::renderSprite(n8 x, n8 y) -> void { auto x0 = l.spriteWindowX0; auto x1 = l.spriteWindowX1; if(x0 > x1) swap(x0, x1); @@ -117,11 +117,11 @@ auto PPU::renderSprite(uint8 x, uint8 y) -> void { for(auto index : range(l.spriteCount)) { auto sprite = l.sprite[index]; if(l.spriteWindowEnable && sprite.bit(12) == windowInside) continue; - if((uint8)(x - sprite.bit(24,31)) > 7) continue; + if((n8)(x - sprite.bit(24,31)) > 7) continue; - uint3 tileX = (x - sprite.bit(24,31)) ^ sprite.bit(14) * 7; - uint3 tileY = (y - sprite.bit(16,23)) ^ sprite.bit(15) * 7; - uint4 tileColor = renderFetch(sprite.bit(0,8), tileX, tileY); + n3 tileX = (x - sprite.bit(24,31)) ^ sprite.bit(14) * 7; + n3 tileY = (y - sprite.bit(16,23)) ^ sprite.bit(15) * 7; + n4 tileColor = renderFetch(sprite.bit(0,8), tileX, tileY); if(renderTransparent(sprite.bit(11), tileColor)) continue; if(!sprite.bit(13) && s.pixel.source == Pixel::Source::ScreenTwo) continue; diff --git a/ares/ws/ppu/serialization.cpp b/ares/ws/ppu/serialization.cpp index 0fc19d2ddb..7b1d355e31 100644 --- a/ares/ws/ppu/serialization.cpp +++ b/ares/ws/ppu/serialization.cpp @@ -3,7 +3,7 @@ auto PPU::serialize(serializer& s) -> void { s(this->s.field); s(this->s.vtime); - s((uint&)this->s.pixel.source); + s((u32&)this->s.pixel.source); s(this->s.pixel.color); s(l.backColor); @@ -31,7 +31,7 @@ auto PPU::serialize(serializer& s) -> void { s(l.sprite); s(l.spriteCount); - for(uint n : range(2)) s(l.oam[n]); + for(u32 n : range(2)) s(l.oam[n]); s(l.oamCount); s(l.orientation); @@ -73,7 +73,7 @@ auto PPU::serialize(serializer& s) -> void { s(r.vtotal); s(r.vsync); s(r.pool); - for(uint n : range(16)) s(r.palette[n].color); + for(u32 n : range(16)) s(r.palette[n].color); s(r.htimerEnable); s(r.htimerRepeat); s(r.vtimerEnable); diff --git a/ares/ws/system/controls.cpp b/ares/ws/system/controls.cpp index fe6d9997fc..fb81a0a806 100644 --- a/ares/ws/system/controls.cpp +++ b/ares/ws/system/controls.cpp @@ -55,7 +55,7 @@ auto System::Controls::poll() -> void { bool volumeValue = volume->value(); platform->input(volume); if(!volumeValue && volume->value()) { - //lower volume by one step. 0 wraps to 3 here (uint2 type.) + //lower volume by one step. 0 wraps to 3 here (n2 type.) apu.r.masterVolume--; //ASWAN has three volume steps; SPHINX and SPHINX2 have four. if(SoC::ASWAN() && apu.r.masterVolume == 3) apu.r.masterVolume = 2; diff --git a/ares/ws/system/io.cpp b/ares/ws/system/io.cpp index f0aca188b9..08ecff8980 100644 --- a/ares/ws/system/io.cpp +++ b/ares/ws/system/io.cpp @@ -1,5 +1,5 @@ -auto System::portRead(uint16 address) -> uint8 { - uint8 data; +auto System::portRead(n16 address) -> n8 { + n8 data; //DISP_MODE if(address == 0x0060) { @@ -45,7 +45,7 @@ auto System::portRead(uint16 address) -> uint8 { return data; } -auto System::portWrite(uint16 address, uint8 data) -> void { +auto System::portWrite(n16 address, n8 data) -> void { //DISP_MODE if(address == 0x0060) { io.unknown0 = data.bit(0); diff --git a/ares/ws/system/serialization.cpp b/ares/ws/system/serialization.cpp index a490e9748c..b6413e2a9f 100644 --- a/ares/ws/system/serialization.cpp +++ b/ares/ws/system/serialization.cpp @@ -2,7 +2,7 @@ auto System::serialize(bool synchronize) -> serializer { if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize); serializer s; - uint signature = SerializerSignature; + u32 signature = SerializerSignature; char version[16] = {}; char description[512] = {}; memory::copy(&version, (const char*)SerializerVersion, SerializerVersion.size()); @@ -17,7 +17,7 @@ auto System::serialize(bool synchronize) -> serializer { } auto System::unserialize(serializer& s) -> bool { - uint signature = 0; + u32 signature = 0; bool synchronize = true; char version[16] = {}; char description[512] = {}; diff --git a/ares/ws/system/system.cpp b/ares/ws/system/system.cpp index 32629d2197..259857389e 100644 --- a/ares/ws/system/system.cpp +++ b/ares/ws/system/system.cpp @@ -2,7 +2,17 @@ namespace ares::WonderSwan { +auto enumerate() -> vector { + return { + "[Bandai] WonderSwan", + "[Bandai] WonderSwan Color", + "[Bandai] SwanCrystal", + "[Benesse] Pocket Challenge V2", + }; +} + auto load(Node::System& node, string name) -> bool { + if(!enumerate().find(name)) return false; return system.load(node, name); } @@ -33,13 +43,28 @@ auto System::load(Node::System& root, string name) -> bool { if(node) unload(); information = {}; + if(name.find("WonderSwan")) { + information.name = "WonderSwan"; + information.soc = SoC::ASWAN; + information.model = Model::WonderSwan; + } + if(name.find("WonderSwan Color")) { + information.name = "WonderSwan Color"; + information.soc = SoC::SPHINX; + information.model = Model::WonderSwanColor; + } + if(name.find("SwanCrystal")) { + information.name = "SwanCrystal"; + information.soc = SoC::SPHINX2; + information.model = Model::SwanCrystal; + } + if(name.find("Pocket Challenge V2")) { + information.name = "Pocket Challenge V2"; + information.soc = SoC::ASWAN; + information.model = Model::PocketChallengeV2; + } - if(name == "WonderSwan" ) information.soc = SoC::ASWAN, information.model = Model::WonderSwan; - if(name == "WonderSwan Color" ) information.soc = SoC::SPHINX, information.model = Model::WonderSwanColor; - if(name == "SwanCrystal" ) information.soc = SoC::SPHINX2, information.model = Model::SwanCrystal; - if(name == "Pocket Challenge V2") information.soc = SoC::ASWAN, information.model = Model::PocketChallengeV2; - - node = Node::System::create(name); + node = Node::System::create(information.name); node->setGame({&System::game, this}); node->setRun({&System::run, this}); node->setPower({&System::power, this}); @@ -61,7 +86,7 @@ auto System::load(Node::System& root, string name) -> bool { //none of this can be considered 100% verified; direct EEPROM dumps from new-old stock would be required. auto initializeName = [&](string name) { //16-character limit, 'A'-'Z' only! - for(uint index : range(name.size())) { + for(u32 index : range(name.size())) { eeprom.program(0x60 + index, name[index] - 'A' + 0x0b); } }; diff --git a/ares/ws/system/system.hpp b/ares/ws/system/system.hpp index d2c279f0ef..34fbec2326 100644 --- a/ares/ws/system/system.hpp +++ b/ares/ws/system/system.hpp @@ -2,13 +2,13 @@ struct System : IO { Node::System node; Node::Setting::Boolean headphones; - enum class SoC : uint { + enum class SoC : u32 { ASWAN, SPHINX, SPHINX2, }; - enum class Model : uint { + enum class Model : u32 { WonderSwan, WonderSwanColor, SwanCrystal, @@ -55,11 +55,11 @@ struct System : IO { bool rightLatch = 0; } controls; - auto name() const -> string { return node->name(); } + auto name() const -> string { return information.name; } auto model() const -> Model { return information.model; } auto soc() const -> SoC { return information.soc; } - auto mode() const -> uint3 { return io.mode; } - auto memory() const -> uint { return io.mode.bit(2) == 0 ? 16_KiB : 64_KiB; } + auto mode() const -> n3 { return io.mode; } + auto memory() const -> u32 { return io.mode.bit(2) == 0 ? 16_KiB : 64_KiB; } //mode: //xx0 => planar tiledata @@ -83,28 +83,29 @@ struct System : IO { auto power(bool reset = false) -> void; //io.cpp - auto portRead(uint16 address) -> uint8 override; - auto portWrite(uint16 address, uint8 data) -> void override; + auto portRead(n16 address) -> n8 override; + auto portWrite(n16 address, n8 data) -> void override; //serialization.cpp auto serialize(bool synchronize) -> serializer; auto unserialize(serializer&) -> bool; struct Information { + string name = "WonderSwan"; SoC soc = SoC::ASWAN; Model model = Model::WonderSwan; } information; - Memory::Readable bootROM; + Memory::Readable bootROM; EEPROM eeprom; private: struct Registers { //$0060 DISP_MODE - uint1 unknown0; - uint1 unknown1; - uint1 unknown3; - uint3 mode; + n1 unknown0; + n1 unknown1; + n1 unknown3; + n3 mode; } io; //serialization.cpp diff --git a/ares/ws/ws.hpp b/ares/ws/ws.hpp index adaed7ed63..414daf68f6 100644 --- a/ares/ws/ws.hpp +++ b/ares/ws/ws.hpp @@ -8,9 +8,10 @@ namespace ares::WonderSwan { #include + auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; - enum : uint { Byte = 1, Word = 2, Long = 4 }; + enum : u32 { Byte = 1, Word = 2, Long = 4 }; struct SoC { inline static auto ASWAN() -> bool; //Grayscale diff --git a/hiro/GNUmakefile b/hiro/GNUmakefile index 8ed3cc8a18..f50daf4197 100644 --- a/hiro/GNUmakefile +++ b/hiro/GNUmakefile @@ -26,7 +26,7 @@ ifeq ($(platform),macos) ifeq ($(hiro),cocoa) hiro.flags = $(flags.objcpp) -w -DHIRO_COCOA - hiro.options = -framework Cocoa -framework Carbon -framework Security + hiro.options = -framework Cocoa -framework Carbon -framework IOKit -framework Security endif endif diff --git a/hiro/cocoa/action/menu-item.cpp b/hiro/cocoa/action/menu-item.cpp index 10335e6357..45f735cce1 100644 --- a/hiro/cocoa/action/menu-item.cpp +++ b/hiro/cocoa/action/menu-item.cpp @@ -37,7 +37,7 @@ auto pMenuItem::destruct() -> void { auto pMenuItem::setIcon(const image& icon) -> void { @autoreleasepool { - uint size = 15; //there is no API to retrieve the optimal size + u32 size = 15; //there is no API to retrieve the optimal size [cocoaAction setImage:NSMakeImage(icon, size, size)]; } } diff --git a/hiro/cocoa/action/menu.cpp b/hiro/cocoa/action/menu.cpp index 7f23b19dff..cd45750199 100644 --- a/hiro/cocoa/action/menu.cpp +++ b/hiro/cocoa/action/menu.cpp @@ -55,7 +55,7 @@ auto pMenu::remove(sAction action) -> void { auto pMenu::setIcon(const image& icon) -> void { @autoreleasepool { - uint size = 15; //there is no API to retrieve the optimal size + u32 size = 15; //there is no API to retrieve the optimal size [cocoaAction setImage:NSMakeImage(icon, size, size)]; } } diff --git a/hiro/cocoa/application.cpp b/hiro/cocoa/application.cpp index 38a09919f8..d0188e0ca8 100644 --- a/hiro/cocoa/application.cpp +++ b/hiro/cocoa/application.cpp @@ -22,7 +22,7 @@ -(void) updateInDock:(NSTimer*)timer { NSArray* windows = [NSApp windows]; - for(uint n = 0; n < [windows count]; n++) { + for(u32 n = 0; n < [windows count]; n++) { NSWindow* window = [windows objectAtIndex:n]; if([window isMiniaturized]) { [window updateInDock]; diff --git a/hiro/cocoa/desktop.cpp b/hiro/cocoa/desktop.cpp index 2eaa0adf14..315f05e029 100644 --- a/hiro/cocoa/desktop.cpp +++ b/hiro/cocoa/desktop.cpp @@ -6,8 +6,8 @@ auto pDesktop::size() -> Size { @autoreleasepool { NSRect primary = [[[NSScreen screens] objectAtIndex:0] frame]; return { - (int)primary.size.width, - (int)primary.size.height + (s32)primary.size.width, + (s32)primary.size.height }; } } @@ -17,10 +17,10 @@ auto pDesktop::workspace() -> Geometry { auto screen = Desktop::size(); NSRect area = [[[NSScreen screens] objectAtIndex:0] visibleFrame]; return { - (int)area.origin.x, - (int)area.origin.y, - (int)area.size.width, - (int)area.size.height + (s32)area.origin.x, + (s32)area.origin.y, + (s32)area.size.width, + (s32)area.size.height }; } } diff --git a/hiro/cocoa/font.cpp b/hiro/cocoa/font.cpp index ad90039589..8a09ed4371 100644 --- a/hiro/cocoa/font.cpp +++ b/hiro/cocoa/font.cpp @@ -16,7 +16,7 @@ auto pFont::size(NSFont* font, const string& text) -> Size { NSString* cocoaText = [NSString stringWithUTF8String:text]; NSDictionary* fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]; NSSize size = [cocoaText sizeWithAttributes:fontAttributes]; - return {(int)size.width, (int)size.height}; + return {(s32)size.width, (s32)size.height}; } } diff --git a/hiro/cocoa/keyboard.cpp b/hiro/cocoa/keyboard.cpp index 46647e28ec..8f03962ad0 100644 --- a/hiro/cocoa/keyboard.cpp +++ b/hiro/cocoa/keyboard.cpp @@ -7,7 +7,7 @@ auto pKeyboard::poll() -> vector { return result; } -auto pKeyboard::pressed(uint code) -> bool { +auto pKeyboard::pressed(u32 code) -> bool { return false; } diff --git a/hiro/cocoa/keyboard.hpp b/hiro/cocoa/keyboard.hpp index e8b8d40150..485000fa06 100644 --- a/hiro/cocoa/keyboard.hpp +++ b/hiro/cocoa/keyboard.hpp @@ -4,7 +4,7 @@ namespace hiro { struct pKeyboard { static auto poll() -> vector; - static auto pressed(uint code) -> bool; + static auto pressed(u32 code) -> bool; }; } diff --git a/hiro/cocoa/message-window.cpp b/hiro/cocoa/message-window.cpp index a85e0ce99c..a34e313ec7 100644 --- a/hiro/cocoa/message-window.cpp +++ b/hiro/cocoa/message-window.cpp @@ -2,7 +2,7 @@ namespace hiro { -enum class MessageWindowType : uint { Error, Information, Question, Warning }; +enum class MessageWindowType : u32 { Error, Information, Question, Warning }; auto MessageWindow_dialog(MessageWindow::State& state, MessageWindowType type) -> MessageWindow::Response { @autoreleasepool { diff --git a/hiro/cocoa/monitor.cpp b/hiro/cocoa/monitor.cpp index 1f201577e6..e76c0a44fc 100644 --- a/hiro/cocoa/monitor.cpp +++ b/hiro/cocoa/monitor.cpp @@ -2,13 +2,13 @@ namespace hiro { -auto pMonitor::count() -> uint { +auto pMonitor::count() -> u32 { @autoreleasepool { return [[NSScreen screens] count]; } } -auto pMonitor::dpi(uint monitor) -> Position { +auto pMonitor::dpi(u32 monitor) -> Position { //macOS includes built-in HiDPI scaling support. //it may be better to rely on per-application scaling, //but for now we'll let macOS handle it so it works in all hiro applications. @@ -23,32 +23,32 @@ auto pMonitor::dpi(uint monitor) -> Position { return {96.0, 96.0}; } -auto pMonitor::geometry(uint monitor) -> Geometry { +auto pMonitor::geometry(u32 monitor) -> Geometry { @autoreleasepool { NSRect rectangle = [[[NSScreen screens] objectAtIndex:monitor] frame]; return { - (int)rectangle.origin.x, - (int)rectangle.origin.y, - (int)rectangle.size.width, - (int)rectangle.size.height + (s32)rectangle.origin.x, + (s32)rectangle.origin.y, + (s32)rectangle.size.width, + (s32)rectangle.size.height }; } } -auto pMonitor::primary() -> uint { +auto pMonitor::primary() -> u32 { //on macOS, the primary monitor is always the first monitor. return 0; } -auto pMonitor::workspace(uint monitor) -> Geometry { +auto pMonitor::workspace(u32 monitor) -> Geometry { @autoreleasepool { NSRect size = [[[NSScreen screens] objectAtIndex:monitor] frame]; NSRect area = [[[NSScreen screens] objectAtIndex:monitor] visibleFrame]; return { - (int)area.origin.x, - (int)area.origin.y, - (int)area.size.width, - (int)area.size.height + (s32)area.origin.x, + (s32)area.origin.y, + (s32)area.size.width, + (s32)area.size.height }; } } diff --git a/hiro/cocoa/monitor.hpp b/hiro/cocoa/monitor.hpp index 1effa3dad3..3e0ef670bb 100644 --- a/hiro/cocoa/monitor.hpp +++ b/hiro/cocoa/monitor.hpp @@ -3,11 +3,11 @@ namespace hiro { struct pMonitor { - static auto count() -> uint; - static auto dpi(uint monitor) -> Position; - static auto geometry(uint monitor) -> Geometry; - static auto primary() -> uint; - static auto workspace(uint monitor) -> Geometry; + static auto count() -> u32; + static auto dpi(u32 monitor) -> Position; + static auto geometry(u32 monitor) -> Geometry; + static auto primary() -> u32; + static auto workspace(u32 monitor) -> Geometry; }; } diff --git a/hiro/cocoa/timer.cpp b/hiro/cocoa/timer.cpp index e9a183fcdd..5d8bf640f2 100644 --- a/hiro/cocoa/timer.cpp +++ b/hiro/cocoa/timer.cpp @@ -58,7 +58,7 @@ auto pTimer::setEnabled(bool enabled) -> void { } } -auto pTimer::setInterval(uint interval) -> void { +auto pTimer::setInterval(u32 interval) -> void { @autoreleasepool { [cocoaTimer update]; } diff --git a/hiro/cocoa/timer.hpp b/hiro/cocoa/timer.hpp index d8fd337228..ac78e73ce1 100644 --- a/hiro/cocoa/timer.hpp +++ b/hiro/cocoa/timer.hpp @@ -17,7 +17,7 @@ struct pTimer : pObject { Declare(Timer, Object) auto setEnabled(bool enabled) -> void; - auto setInterval(uint interval) -> void; + auto setInterval(u32 interval) -> void; CocoaTimer* cocoaTimer = nullptr; }; diff --git a/hiro/cocoa/utility.cpp b/hiro/cocoa/utility.cpp index 9d6962391d..7ce281ef41 100644 --- a/hiro/cocoa/utility.cpp +++ b/hiro/cocoa/utility.cpp @@ -9,7 +9,7 @@ auto NSMakeCursor(const hiro::MouseCursor& mouseCursor) -> NSCursor* { return nil; } -auto NSMakeImage(image icon, uint scaleWidth = 0, uint scaleHeight = 0) -> NSImage* { +auto NSMakeImage(image icon, u32 scaleWidth = 0, u32 scaleHeight = 0) -> NSImage* { if(!icon) return nil; if(scaleWidth && scaleHeight) icon.scale(scaleWidth, scaleHeight); @@ -25,7 +25,7 @@ auto NSMakeImage(image icon, uint scaleWidth = 0, uint scaleHeight = 0) -> NSIma bitmapFormat:NSAlphaNonpremultipliedBitmapFormat bytesPerRow:(4 * icon.width()) bitsPerPixel:32 ] autorelease]; - memory::copy([bitmap bitmapData], icon.data(), icon.width() * icon.height()); + memory::copy([bitmap bitmapData], icon.data(), icon.width() * icon.height()); [cocoaImage addRepresentation:bitmap]; return cocoaImage; } @@ -45,7 +45,7 @@ auto DropPaths(id sender) -> vector { NSPasteboard* pboard = [sender draggingPasteboard]; if([[pboard types] containsObject:NSFilenamesPboardType]) { NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; - for(uint n = 0; n < [files count]; n++) { + for(u32 n = 0; n < [files count]; n++) { string path = [[files objectAtIndex:n] UTF8String]; if(directory::exists(path) && !path.endsWith("/")) path.append("/"); paths.append(path); diff --git a/hiro/cocoa/widget/canvas.cpp b/hiro/cocoa/widget/canvas.cpp index 3a8a74f43b..2fce1c5692 100644 --- a/hiro/cocoa/widget/canvas.cpp +++ b/hiro/cocoa/widget/canvas.cpp @@ -59,7 +59,7 @@ -(void) mouseMove:(NSEvent*)event { if([event window] == nil) return; NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; - canvas->doMouseMove({(int)location.x, (int)([self frame].size.height - 1 - location.y)}); + canvas->doMouseMove({(s32)location.x, (s32)([self frame].size.height - 1 - location.y)}); } -(void) mouseDown:(NSEvent*)event { @@ -117,7 +117,7 @@ auto pCanvas::destruct() -> void { } auto pCanvas::minimumSize() const -> Size { - if(auto& icon = state().icon) return {(int)icon.width(), (int)icon.height()}; + if(auto& icon = state().icon) return {(s32)icon.width(), (s32)icon.height()}; return {0, 0}; } @@ -166,8 +166,8 @@ auto pCanvas::update() -> void { //todo: support cases where the icon size does not match the canvas size (alignment) auto pCanvas::_rasterize() -> void { @autoreleasepool { - int width = 0; - int height = 0; + s32 width = 0; + s32 height = 0; if(auto& icon = state().icon) { width = icon.width(); @@ -201,7 +201,7 @@ auto pCanvas::_rasterize() -> void { [cocoaView setImage:surface]; } - auto target = (uint32_t*)[bitmap bitmapData]; + auto target = (u32*)[bitmap bitmapData]; if(auto icon = state().icon) { icon.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); //Cocoa uses ABGR format @@ -213,7 +213,7 @@ auto pCanvas::_rasterize() -> void { fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value()); memory::copy(target, fill.data(), fill.size()); } else { - uint32_t color = state().color.value(); + u32 color = state().color.value(); for(auto n : range(width * height)) target[n] = color; } } diff --git a/hiro/cocoa/widget/canvas.hpp b/hiro/cocoa/widget/canvas.hpp index 95bcf917a0..714b9e0436 100644 --- a/hiro/cocoa/widget/canvas.hpp +++ b/hiro/cocoa/widget/canvas.hpp @@ -43,8 +43,8 @@ struct pCanvas : pWidget { CocoaCanvas* cocoaCanvas = nullptr; NSImage* surface = nullptr; NSBitmapImageRep* bitmap = nullptr; - uint surfaceWidth = 0; - uint surfaceHeight = 0; + u32 surfaceWidth = 0; + u32 surfaceHeight = 0; }; } diff --git a/hiro/cocoa/widget/combo-button.cpp b/hiro/cocoa/widget/combo-button.cpp index b6ac1d494d..379aaea555 100644 --- a/hiro/cocoa/widget/combo-button.cpp +++ b/hiro/cocoa/widget/combo-button.cpp @@ -43,7 +43,7 @@ auto pComboButton::append(sComboButtonItem item) -> void { auto pComboButton::minimumSize() const -> Size { auto font = self().font(true); - int maximumWidth = 0; + s32 maximumWidth = 0; for(auto& item : state().items) { maximumWidth = max(maximumWidth, pFont::size(font, item->state.text).width()); } diff --git a/hiro/cocoa/widget/console.cpp b/hiro/cocoa/widget/console.cpp index 4a5f186e25..d4b3279e9b 100644 --- a/hiro/cocoa/widget/console.cpp +++ b/hiro/cocoa/widget/console.cpp @@ -13,28 +13,28 @@ namespace hiro { -void pConsole::print(string text) { +auto pConsole::print(string text) -> void { } -void pConsole::reset() { +auto pConsole::reset() -> void { } -void pConsole::setBackgroundColor(Color color) { +auto pConsole::setBackgroundColor(Color color) -> void { } -void pConsole::setForegroundColor(Color color) { +auto pConsole::setForegroundColor(Color color) -> void { } -void pConsole::setPrompt(string prompt) { +auto pConsole::setPrompt(string prompt) -> void { } -void pConsole::constructor() { +auto pConsole::constructor() -> void { @autoreleasepool { cocoaView = cocoaConsole = [[CocoaConsole alloc] initWith:console]; } } -void pConsole::destructor() { +auto pConsole::destructor() -> void { @autoreleasepool { [cocoaView removeFromSuperview]; [cocoaView release]; diff --git a/hiro/cocoa/widget/console.hpp b/hiro/cocoa/widget/console.hpp index fa42a991c3..502d608ce6 100644 --- a/hiro/cocoa/widget/console.hpp +++ b/hiro/cocoa/widget/console.hpp @@ -13,15 +13,15 @@ struct pConsole : public pWidget { Console& console; CocoaConsole* cocoaConsole = nullptr; - void print(string text); - void reset(); - void setBackgroundColor(Color color); - void setForegroundColor(Color color); - void setPrompt(string prompt); + auto print(string text) -> void; + auto reset() -> void; + auto setBackgroundColor(Color color) -> void; + auto setForegroundColor(Color color) -> void; + auto setPrompt(string prompt) -> void; pConsole(Console& console) : pWidget(console), console(console) {} - void constructor(); - void destructor(); + auto constructor() -> void; + auto destructor() -> void; }; } diff --git a/hiro/cocoa/widget/hex-edit.cpp b/hiro/cocoa/widget/hex-edit.cpp index 767dd7ce27..238a458d30 100644 --- a/hiro/cocoa/widget/hex-edit.cpp +++ b/hiro/cocoa/widget/hex-edit.cpp @@ -26,22 +26,22 @@ auto pHexEdit::destruct() -> void { } } -auto pHexEdit::setAddress(uint offset) -> void { +auto pHexEdit::setAddress(u32 offset) -> void { } auto pHexEdit::setBackgroundColor(Color color) -> void { } -auto pHexEdit::setColumns(uint columns) -> void { +auto pHexEdit::setColumns(u32 columns) -> void { } auto pHexEdit::setForegroundColor(Color color) -> void { } -auto pHexEdit::setLength(uint length) -> void { +auto pHexEdit::setLength(u32 length) -> void { } -auto pHexEdit::setRows(uint rows) -> void { +auto pHexEdit::setRows(u32 rows) -> void { } auto pHexEdit::update() -> void { diff --git a/hiro/cocoa/widget/hex-edit.hpp b/hiro/cocoa/widget/hex-edit.hpp index 22cb694c0f..7bc5663d0d 100644 --- a/hiro/cocoa/widget/hex-edit.hpp +++ b/hiro/cocoa/widget/hex-edit.hpp @@ -12,12 +12,12 @@ namespace hiro { struct pHexEdit : public pWidget { Declare(HexEdit, Widget); - auto setAddress(uint address) -> void; + auto setAddress(u32 address) -> void; auto setBackgroundColor(Color color) -> void; - auto setColumns(uint columns) -> void; + auto setColumns(u32 columns) -> void; auto setForegroundColor(Color color) -> void; - auto setLength(uint length) -> void; - auto setRows(uint rows) -> void; + auto setLength(u32 length) -> void; + auto setRows(u32 rows) -> void; auto update() -> void; CocoaHexEdit* cocoaHexEdit = nullptr; diff --git a/hiro/cocoa/widget/horizontal-scroll-bar.cpp b/hiro/cocoa/widget/horizontal-scroll-bar.cpp index f1672f573b..40c55518b2 100644 --- a/hiro/cocoa/widget/horizontal-scroll-bar.cpp +++ b/hiro/cocoa/widget/horizontal-scroll-bar.cpp @@ -19,8 +19,8 @@ } -(void) update { - double d = 1.0 / horizontalScrollBar->state.length; - double f = d * horizontalScrollBar->state.position; + f64 d = 1.0 / horizontalScrollBar->state.length; + f64 f = d * horizontalScrollBar->state.position; [self setDoubleValue:f]; [self setKnobProportion:d]; @@ -73,17 +73,17 @@ auto pHorizontalScrollBar::destruct() -> void { auto pHorizontalScrollBar::minimumSize() const -> Size { @autoreleasepool { - return {32, (int)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy]}; + return {32, (s32)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy]}; } } -auto pHorizontalScrollBar::setLength(uint length) -> void { +auto pHorizontalScrollBar::setLength(u32 length) -> void { @autoreleasepool { [cocoaView update]; } } -auto pHorizontalScrollBar::setPosition(uint position) -> void { +auto pHorizontalScrollBar::setPosition(u32 position) -> void { @autoreleasepool { [cocoaView update]; } diff --git a/hiro/cocoa/widget/horizontal-scroll-bar.hpp b/hiro/cocoa/widget/horizontal-scroll-bar.hpp index b80cc6491e..389166c874 100644 --- a/hiro/cocoa/widget/horizontal-scroll-bar.hpp +++ b/hiro/cocoa/widget/horizontal-scroll-bar.hpp @@ -15,8 +15,8 @@ struct pHorizontalScrollBar : pWidget { Declare(HorizontalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; CocoaHorizontalScrollBar* cocoaHorizontalScrollBar = nullptr; }; diff --git a/hiro/cocoa/widget/horizontal-slider.cpp b/hiro/cocoa/widget/horizontal-slider.cpp index 7878d6f739..9366153703 100644 --- a/hiro/cocoa/widget/horizontal-slider.cpp +++ b/hiro/cocoa/widget/horizontal-slider.cpp @@ -50,13 +50,13 @@ auto pHorizontalSlider::setGeometry(Geometry geometry) -> void { }); } -auto pHorizontalSlider::setLength(uint length) -> void { +auto pHorizontalSlider::setLength(u32 length) -> void { @autoreleasepool { [cocoaView setMaxValue:length]; } } -auto pHorizontalSlider::setPosition(uint position) -> void { +auto pHorizontalSlider::setPosition(u32 position) -> void { @autoreleasepool { [cocoaView setDoubleValue:position]; } diff --git a/hiro/cocoa/widget/horizontal-slider.hpp b/hiro/cocoa/widget/horizontal-slider.hpp index b8d4b0daec..cd52be0129 100644 --- a/hiro/cocoa/widget/horizontal-slider.hpp +++ b/hiro/cocoa/widget/horizontal-slider.hpp @@ -15,8 +15,8 @@ struct pHorizontalSlider : pWidget { auto minimumSize() const -> Size override; auto setGeometry(Geometry geometry) -> void; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; CocoaHorizontalSlider* cocoaHorizontalSlider = nullptr; }; diff --git a/hiro/cocoa/widget/label.cpp b/hiro/cocoa/widget/label.cpp index 6fbe707551..4725eebfb3 100644 --- a/hiro/cocoa/widget/label.cpp +++ b/hiro/cocoa/widget/label.cpp @@ -78,7 +78,7 @@ -(void) mouseMove:(NSEvent*)event { if([event window] == nil) return; NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; - label->doMouseMove({(int)location.x, (int)([self frame].size.height - 1 - location.y)}); + label->doMouseMove({(s32)location.x, (s32)([self frame].size.height - 1 - location.y)}); } -(void) mouseDown:(NSEvent*)event { diff --git a/hiro/cocoa/widget/progress-bar.cpp b/hiro/cocoa/widget/progress-bar.cpp index 4afe7ed6df..9b0c3b3b16 100644 --- a/hiro/cocoa/widget/progress-bar.cpp +++ b/hiro/cocoa/widget/progress-bar.cpp @@ -37,7 +37,7 @@ auto pProgressBar::minimumSize() const -> Size { return {0, 12}; } -auto pProgressBar::setPosition(uint position) -> void { +auto pProgressBar::setPosition(u32 position) -> void { @autoreleasepool { [cocoaView setDoubleValue:position]; } diff --git a/hiro/cocoa/widget/progress-bar.hpp b/hiro/cocoa/widget/progress-bar.hpp index 0369156734..f888273454 100644 --- a/hiro/cocoa/widget/progress-bar.hpp +++ b/hiro/cocoa/widget/progress-bar.hpp @@ -13,7 +13,7 @@ struct pProgressBar : pWidget { Declare(ProgressBar, Widget) auto minimumSize() const -> Size override; - auto setPosition(uint position) -> void; + auto setPosition(u32 position) -> void; CocoaProgressBar* cocoaProgressBar = nullptr; }; diff --git a/hiro/cocoa/widget/tab-frame.cpp b/hiro/cocoa/widget/tab-frame.cpp index 9a0193409d..eb08b2d256 100644 --- a/hiro/cocoa/widget/tab-frame.cpp +++ b/hiro/cocoa/widget/tab-frame.cpp @@ -30,11 +30,11 @@ -(NSSize) sizeOfLabel:(BOOL)shouldTruncateLabel { NSSize sizeOfLabel = [super sizeOfLabel:shouldTruncateLabel]; - int selection = [cocoaTabFrame indexOfTabViewItem:self]; + s32 selection = [cocoaTabFrame indexOfTabViewItem:self]; if(selection >= 0) { if(auto item = tabFrame->item(selection)) { if(item->state.icon) { - uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height(); + u32 iconSize = hiro::pFont::size(tabFrame->font(true), " ").height(); sizeOfLabel.width += iconSize + 2; } } @@ -43,11 +43,11 @@ } -(void) drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect { - int selection = [cocoaTabFrame indexOfTabViewItem:self]; + s32 selection = [cocoaTabFrame indexOfTabViewItem:self]; if(selection >= 0) { if(auto item = tabFrame->item(selection)) { if(item->state.icon) { - uint iconSize = hiro::pFont::size(tabFrame->font(true), " ").height(); + u32 iconSize = hiro::pFont::size(tabFrame->font(true), " ").height(); NSImage* image = NSMakeImage(item->state.icon); [[NSGraphicsContext currentContext] saveGraphicsState]; @@ -151,7 +151,7 @@ auto pTabFrame::setVisible(bool visible) -> void { auto pTabFrame::_synchronizeSizable() -> void { @autoreleasepool { NSTabViewItem* tabViewItem = [cocoaView selectedTabViewItem]; - int selected = tabViewItem ? [cocoaView indexOfTabViewItem:tabViewItem] : -1; + s32 selected = tabViewItem ? [cocoaView indexOfTabViewItem:tabViewItem] : -1; for(auto& item : state().items) { item->state.selected = item->offset() == selected; if(auto& sizable = item->state.sizable) sizable->setVisible(item->selected()); diff --git a/hiro/cocoa/widget/table-view.cpp b/hiro/cocoa/widget/table-view.cpp index 08d2c1c574..99f5ad4d31 100644 --- a/hiro/cocoa/widget/table-view.cpp +++ b/hiro/cocoa/widget/table-view.cpp @@ -48,7 +48,7 @@ if(font) [font release]; font = fontPointer; - uint fontHeight = hiro::pFont::size(font, " ").height(); + u32 fontHeight = hiro::pFont::size(font, " ").height(); [content setFont:font]; [content setRowHeight:fontHeight]; [self reloadColumns]; @@ -112,9 +112,9 @@ } -(IBAction) doubleAction:(id)sender { - int row = [content clickedRow]; + s32 row = [content clickedRow]; if(row >= 0 && row < tableView->state.items.size()) { - int column = [content clickedColumn]; + s32 column = [content clickedColumn]; if(column >= 0 && column < tableView->state.columns.size()) { auto item = tableView->state.items[row]; auto cell = item->cell(column); @@ -143,9 +143,9 @@ -(void) keyDown:(NSEvent*)event { auto character = [[event characters] characterAtIndex:0]; if(character == NSEnterCharacter || character == NSCarriageReturnCharacter) { - int row = [self selectedRow]; + s32 row = [self selectedRow]; if(row >= 0 && row < tableView->state.items.size()) { - int column = max(0, [self selectedColumn]); //can be -1? + s32 column = max(0, [self selectedColumn]); //can be -1? if(column >= 0 && column < tableView->state.columns.size()) { auto item = tableView->state.items[row]; auto cell = item->cell(column); @@ -337,25 +337,25 @@ auto pTableView::remove(sTableViewItem item) -> void { auto pTableView::resizeColumns() -> void { @autoreleasepool { - vector widths; - int minimumWidth = 0; - int expandable = 0; - for(uint column : range(self().columnCount())) { - int width = _width(column); + vector widths; + s32 minimumWidth = 0; + s32 expandable = 0; + for(u32 column : range(self().columnCount())) { + s32 width = _width(column); widths.append(width); minimumWidth += width; if(state().columns[column]->expandable()) expandable++; } - int maximumWidth = self().geometry().width() - 18; //include margin for vertical scroll bar - int expandWidth = 0; + s32 maximumWidth = self().geometry().width() - 18; //include margin for vertical scroll bar + s32 expandWidth = 0; if(expandable && maximumWidth > minimumWidth) { expandWidth = (maximumWidth - minimumWidth) / expandable; } - for(uint column : range(self().columnCount())) { + for(u32 column : range(self().columnCount())) { if(auto self = state().columns[column]->self()) { - int width = widths[column]; + s32 width = widths[column]; if(self->state().expandable) width += expandWidth; NSTableColumn* tableColumn = [[cocoaView content] tableColumnWithIdentifier:[[NSNumber numberWithInteger:column] stringValue]]; [tableColumn setWidth:width]; @@ -409,8 +409,8 @@ auto pTableView::setSortable(bool sortable) -> void { //TODO } -auto pTableView::_cellWidth(uint row, uint column) -> uint { - uint width = 8; +auto pTableView::_cellWidth(u32 row, u32 column) -> u32 { + u32 width = 8; if(auto pTableViewItem = self().item(row)) { if(auto pTableViewCell = pTableViewItem->cell(column)) { if(pTableViewCell->state.checkable) { @@ -427,8 +427,8 @@ auto pTableView::_cellWidth(uint row, uint column) -> uint { return width; } -auto pTableView::_columnWidth(uint column_) -> uint { - uint width = 8; +auto pTableView::_columnWidth(u32 column_) -> u32 { + u32 width = 8; if(auto column = self().column(column_)) { if(auto& icon = column->state.icon) { width += icon.width() + 2; @@ -443,9 +443,9 @@ auto pTableView::_columnWidth(uint column_) -> uint { return width; } -auto pTableView::_width(uint column) -> uint { +auto pTableView::_width(u32 column) -> u32 { if(auto width = self().column(column).width()) return width; - uint width = 1; + u32 width = 1; if(!self().column(column).visible()) return width; if(state().headered) width = max(width, _columnWidth(column)); for(auto row : range(state().items.size())) { @@ -463,7 +463,7 @@ auto pTableView::setSelected(bool selected) -> void { } } -auto pTableView::setSelection(unsigned selection) -> void { +auto pTableView::setSelection(u32 selection) -> void { @autoreleasepool { [[cocoaView content] selectRowIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(selection, 1)] byExtendingSelection:NO]; } diff --git a/hiro/cocoa/widget/table-view.hpp b/hiro/cocoa/widget/table-view.hpp index a8df0f0f86..7401ed959e 100644 --- a/hiro/cocoa/widget/table-view.hpp +++ b/hiro/cocoa/widget/table-view.hpp @@ -64,9 +64,9 @@ struct pTableView : pWidget { auto setHeadered(bool headered) -> void; auto setSortable(bool sortable) -> void; - auto _cellWidth(uint row, uint column) -> uint; - auto _columnWidth(uint column) -> uint; - auto _width(uint column) -> uint; + auto _cellWidth(u32 row, u32 column) -> u32; + auto _columnWidth(u32 column) -> u32; + auto _width(u32 column) -> u32; CocoaTableView* cocoaTableView = nullptr; }; diff --git a/hiro/cocoa/widget/vertical-scroll-bar.cpp b/hiro/cocoa/widget/vertical-scroll-bar.cpp index db8bc4165e..b8c6ddc440 100644 --- a/hiro/cocoa/widget/vertical-scroll-bar.cpp +++ b/hiro/cocoa/widget/vertical-scroll-bar.cpp @@ -19,8 +19,8 @@ } -(void) update { - double d = 1.0 / verticalScrollBar->state.length; - double f = d * verticalScrollBar->state.position; + f64 d = 1.0 / verticalScrollBar->state.length; + f64 f = d * verticalScrollBar->state.position; [self setDoubleValue:f]; [self setKnobProportion:d]; @@ -73,17 +73,17 @@ auto pVerticalScrollBar::destruct() -> void { auto pVerticalScrollBar::minimumSize() const -> Size { @autoreleasepool { - return {(int)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy], 32}; + return {(s32)[NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy], 32}; } } -auto pVerticalScrollBar::setLength(uint length) -> void { +auto pVerticalScrollBar::setLength(u32 length) -> void { @autoreleasepool { [cocoaView update]; } } -auto pVerticalScrollBar::setPosition(uint position) -> void { +auto pVerticalScrollBar::setPosition(u32 position) -> void { @autoreleasepool { [cocoaView update]; } diff --git a/hiro/cocoa/widget/vertical-scroll-bar.hpp b/hiro/cocoa/widget/vertical-scroll-bar.hpp index 22e232b9e2..74ae654cee 100644 --- a/hiro/cocoa/widget/vertical-scroll-bar.hpp +++ b/hiro/cocoa/widget/vertical-scroll-bar.hpp @@ -15,8 +15,8 @@ struct pVerticalScrollBar : pWidget { Declare(VerticalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; CocoaVerticalScrollBar* cocoaVerticalScrollBar = nullptr; }; diff --git a/hiro/cocoa/widget/vertical-slider.cpp b/hiro/cocoa/widget/vertical-slider.cpp index 12cd4010e2..bba3d27c5c 100644 --- a/hiro/cocoa/widget/vertical-slider.cpp +++ b/hiro/cocoa/widget/vertical-slider.cpp @@ -50,13 +50,13 @@ auto pVerticalSlider::setGeometry(Geometry geometry) -> void { }); } -auto pVerticalSlider::setLength(uint length) -> void { +auto pVerticalSlider::setLength(u32 length) -> void { @autoreleasepool { [cocoaView setMaxValue:length]; } } -auto pVerticalSlider::setPosition(uint position) -> void { +auto pVerticalSlider::setPosition(u32 position) -> void { @autoreleasepool { [cocoaView setDoubleValue:position]; } diff --git a/hiro/cocoa/widget/vertical-slider.hpp b/hiro/cocoa/widget/vertical-slider.hpp index a8b2c1e49d..d81cb8ee87 100644 --- a/hiro/cocoa/widget/vertical-slider.hpp +++ b/hiro/cocoa/widget/vertical-slider.hpp @@ -15,8 +15,8 @@ struct pVerticalSlider : pWidget { auto minimumSize() const -> Size override; auto setGeometry(Geometry geometry) -> void override; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; CocoaVerticalSlider* cocoaVerticalSlider = nullptr; }; diff --git a/hiro/cocoa/widget/widget.cpp b/hiro/cocoa/widget/widget.cpp index 0c0ddbdeaf..7fbe598d29 100644 --- a/hiro/cocoa/widget/widget.cpp +++ b/hiro/cocoa/widget/widget.cpp @@ -72,10 +72,10 @@ auto pWidget::setGeometry(Geometry geometry) -> void { @autoreleasepool { CGFloat windowHeight = [[cocoaView superview] frame].size.height; //round coordinates - uint x = geometry.x(); - uint y = windowHeight - geometry.y() - geometry.height(); - uint width = geometry.width(); - uint height = geometry.height(); + u32 x = geometry.x(); + u32 y = windowHeight - geometry.y() - geometry.height(); + u32 width = geometry.width(); + u32 height = geometry.height(); [cocoaView setFrame:NSMakeRect(x, y, width, height)]; [[cocoaView superview] setNeedsDisplay:YES]; } diff --git a/hiro/cocoa/window.cpp b/hiro/cocoa/window.cpp index b5b0d60c0e..a093941e65 100644 --- a/hiro/cocoa/window.cpp +++ b/hiro/cocoa/window.cpp @@ -238,7 +238,7 @@ auto pWindow::focused() const -> bool { auto pWindow::frameMargin() const -> Geometry { @autoreleasepool { NSRect frame = [cocoaWindow frameRectForContentRect:NSMakeRect(0, 0, 640, 480)]; - return {abs(frame.origin.x), (int)(frame.size.height - 480), (int)(frame.size.width - 640), abs(frame.origin.y)}; + return {abs(frame.origin.x), (s32)(frame.size.height - 480), (s32)(frame.size.width - 640), abs(frame.origin.y)}; } } @@ -246,7 +246,7 @@ auto pWindow::handle() const -> uintptr_t { return (uintptr_t)cocoaWindow; } -auto pWindow::monitor() const -> uint { +auto pWindow::monitor() const -> u32 { //TODO return 0; } @@ -421,7 +421,7 @@ auto pWindow::sizeEvent() -> void { if(!locked()) self().doSize(); } -auto pWindow::statusBarHeight() -> uint { +auto pWindow::statusBarHeight() -> u32 { if(auto& statusBar = state().statusBar) { if(statusBar->visible()) { return pFont::size(statusBar->font(true), " ").height() + 6; @@ -454,8 +454,8 @@ auto pWindow::_geometry() -> Geometry { NSRect area = [cocoaWindow contentRectForFrameRect:[cocoaWindow frame]]; area.size.height -= statusBarHeight(); return { - (int)area.origin.x, (int)(Monitor::geometry(Monitor::primary()).height() - area.origin.y - area.size.height), - (int)area.size.width, (int)area.size.height + (s32)area.origin.x, (s32)(Monitor::geometry(Monitor::primary()).height() - area.origin.y - area.size.height), + (s32)area.size.width, (s32)area.size.height }; } } diff --git a/hiro/cocoa/window.hpp b/hiro/cocoa/window.hpp index ef33e361b3..fea4b3f034 100644 --- a/hiro/cocoa/window.hpp +++ b/hiro/cocoa/window.hpp @@ -36,7 +36,7 @@ struct pWindow : pObject { auto focused() const -> bool override; auto frameMargin() const -> Geometry; auto handle() const -> uintptr_t; - auto monitor() const -> uint; + auto monitor() const -> u32; auto remove(sMenuBar menuBar) -> void; auto remove(sSizable sizable) -> void; auto remove(sStatusBar statusBar) -> void; @@ -57,7 +57,7 @@ struct pWindow : pObject { auto moveEvent() -> void; auto sizeEvent() -> void; - auto statusBarHeight() -> uint; + auto statusBarHeight() -> u32; auto statusBarReposition() -> void; auto _append(mWidget& widget) -> void; diff --git a/hiro/core/action/action.hpp b/hiro/core/action/action.hpp new file mode 100644 index 0000000000..e2906287a0 --- /dev/null +++ b/hiro/core/action/action.hpp @@ -0,0 +1,11 @@ +#if defined(Hiro_Action) +struct mAction : mObject { + Declare(Action) + + auto remove() -> type& override; + +//private: + struct State { + } state; +}; +#endif diff --git a/hiro/core/action/menu-check-item.hpp b/hiro/core/action/menu-check-item.hpp new file mode 100644 index 0000000000..196f6fb1ee --- /dev/null +++ b/hiro/core/action/menu-check-item.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_MenuCheckItem) +struct mMenuCheckItem : mAction { + Declare(MenuCheckItem) + + auto checked() const -> bool; + auto doToggle() const -> void; + auto onToggle(const function& callback = {}) -> type&; + auto setChecked(bool checked = true) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool checked = false; + function onToggle; + string text; + } state; +}; +#endif diff --git a/hiro/core/action/menu-item.hpp b/hiro/core/action/menu-item.hpp new file mode 100644 index 0000000000..08b40c7f28 --- /dev/null +++ b/hiro/core/action/menu-item.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_MenuItem) +struct mMenuItem : mAction { + Declare(MenuItem) + + auto doActivate() const -> void; + auto icon() const -> image; + auto onActivate(const function& callback = {}) -> type&; + auto setIcon(const image& icon = {}) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + image icon; + function onActivate; + string text; + } state; +}; +#endif diff --git a/hiro/core/action/menu-radio-item.hpp b/hiro/core/action/menu-radio-item.hpp new file mode 100644 index 0000000000..f399303115 --- /dev/null +++ b/hiro/core/action/menu-radio-item.hpp @@ -0,0 +1,22 @@ +#if defined(Hiro_MenuRadioItem) +struct mMenuRadioItem : mAction { + Declare(MenuRadioItem) + + auto checked() const -> bool; + auto doActivate() const -> void; + auto group() const -> Group override; + auto onActivate(const function& callback = {}) -> type&; + auto setChecked() -> type&; + auto setGroup(sGroup group = {}) -> type& override; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool checked = false; + sGroup group; + function onActivate; + string text; + } state; +}; +#endif diff --git a/hiro/core/action/menu-separator.hpp b/hiro/core/action/menu-separator.hpp new file mode 100644 index 0000000000..52aa925e1c --- /dev/null +++ b/hiro/core/action/menu-separator.hpp @@ -0,0 +1,9 @@ +#if defined(Hiro_MenuSeparator) +struct mMenuSeparator : mAction { + Declare(MenuSeparator) + +//private: + struct State { + } state; +}; +#endif diff --git a/hiro/core/action/menu.cpp b/hiro/core/action/menu.cpp index a184d2fca3..e7ebb641ae 100644 --- a/hiro/core/action/menu.cpp +++ b/hiro/core/action/menu.cpp @@ -11,12 +11,12 @@ auto mMenu::destruct() -> void { // -auto mMenu::action(unsigned position) const -> Action { +auto mMenu::action(u32 position) const -> Action { if(position < actionCount()) return state.actions[position]; return {}; } -auto mMenu::actionCount() const -> unsigned { +auto mMenu::actionCount() const -> u32 { return state.actions.size(); } @@ -58,7 +58,7 @@ auto mMenu::setIcon(const image& icon) -> type& { return *this; } -auto mMenu::setParent(mObject* parent, signed offset) -> type& { +auto mMenu::setParent(mObject* parent, s32 offset) -> type& { for(auto& action : reverse(state.actions)) action->destruct(); mObject::setParent(parent, offset); for(auto& action : state.actions) action->setParent(this, action->offset()); diff --git a/hiro/core/action/menu.hpp b/hiro/core/action/menu.hpp new file mode 100644 index 0000000000..6b5a7a5e76 --- /dev/null +++ b/hiro/core/action/menu.hpp @@ -0,0 +1,27 @@ +#if defined(Hiro_Menu) +struct mMenu : mAction { + Declare(Menu) + using mObject::remove; + + auto action(u32 position) const -> Action; + auto actionCount() const -> u32; + auto actions() const -> vector; + auto append(sAction action) -> type&; + auto icon() const -> image; + auto remove(sAction action) -> type&; + auto reset() -> type& override; + auto setIcon(const image& icon = {}) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + vector actions; + image icon; + string text; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/alignment.cpp b/hiro/core/alignment.cpp index ba968e264f..37001b74ab 100644 --- a/hiro/core/alignment.cpp +++ b/hiro/core/alignment.cpp @@ -6,7 +6,7 @@ Alignment::Alignment() { setAlignment(-1.0, -1.0); } -Alignment::Alignment(float horizontal, float vertical) { +Alignment::Alignment(f32 horizontal, f32 vertical) { setAlignment(horizontal, vertical); } @@ -15,7 +15,7 @@ Alignment::operator bool() const { && state.vertical >= 0.0 && state.vertical <= 1.0; } -auto Alignment::horizontal() const -> float { +auto Alignment::horizontal() const -> f32 { return state.horizontal; } @@ -23,23 +23,23 @@ auto Alignment::reset() -> type& { return setAlignment(-1.0, -1.0); } -auto Alignment::setAlignment(float horizontal, float vertical) -> type& { +auto Alignment::setAlignment(f32 horizontal, f32 vertical) -> type& { state.horizontal = horizontal; state.vertical = vertical; return *this; } -auto Alignment::setHorizontal(float horizontal) -> type& { +auto Alignment::setHorizontal(f32 horizontal) -> type& { state.horizontal = horizontal; return *this; } -auto Alignment::setVertical(float vertical) -> type& { +auto Alignment::setVertical(f32 vertical) -> type& { state.vertical = vertical; return *this; } -auto Alignment::vertical() const -> float { +auto Alignment::vertical() const -> f32 { return state.vertical; } diff --git a/hiro/core/alignment.hpp b/hiro/core/alignment.hpp new file mode 100644 index 0000000000..da743e5225 --- /dev/null +++ b/hiro/core/alignment.hpp @@ -0,0 +1,26 @@ +#if defined(Hiro_Alignment) +struct Alignment { + using type = Alignment; + static const Alignment Center; + + Alignment(); + Alignment(f32 horizontal, f32 vertical = 0.5); + + explicit operator bool() const; + auto operator==(const Alignment& source) const -> bool; + auto operator!=(const Alignment& source) const -> bool; + + auto horizontal() const -> f32; + auto reset() -> type&; + auto setAlignment(f32 horizontal = -1.0, f32 vertical = 0.5) -> type&; + auto setHorizontal(f32 horizontal) -> type&; + auto setVertical(f32 vertical) -> type&; + auto vertical() const -> f32; + +//private: + struct State { + f32 horizontal; + f32 vertical; + } state; +}; +#endif diff --git a/hiro/core/application.cpp b/hiro/core/application.cpp index 4d5f2ebc49..ed4a86dbb7 100644 --- a/hiro/core/application.cpp +++ b/hiro/core/application.cpp @@ -51,11 +51,11 @@ auto Application::quit() -> void { return pApplication::quit(); } -auto Application::scale() -> float { +auto Application::scale() -> f32 { return state().scale; } -auto Application::scale(float value) -> float { +auto Application::scale(f32 value) -> f32 { return value * state().scale; } @@ -71,7 +71,7 @@ auto Application::setName(const string& name) -> void { state().name = name; } -auto Application::setScale(float scale) -> void { +auto Application::setScale(f32 scale) -> void { state().scale = scale; } @@ -94,7 +94,7 @@ auto Application::toolTips() -> bool { return state().toolTips; } -auto Application::unscale(float value) -> float { +auto Application::unscale(f32 value) -> f32 { return value * (1.0 / state().scale); } diff --git a/hiro/core/application.hpp b/hiro/core/application.hpp index daae3ccca1..84480c21c1 100644 --- a/hiro/core/application.hpp +++ b/hiro/core/application.hpp @@ -11,19 +11,19 @@ struct Application { static auto name() -> string; static auto onMain(const function& callback = {}) -> void; static auto run() -> void; - static auto scale() -> float; - static auto scale(float value) -> float; + static auto scale() -> f32; + static auto scale(f32 value) -> f32; static auto pendingEvents() -> bool; static auto processEvents() -> void; static auto quit() -> void; static auto screenSaver() -> bool; static auto setFont(const Font& font = {}) -> void; static auto setName(const string& name = "") -> void; - static auto setScale(float scale = 1.0) -> void; + static auto setScale(f32 scale = 1.0) -> void; static auto setScreenSaver(bool screenSaver = true) -> void; static auto setToolTips(bool toolTips = true) -> void; static auto toolTips() -> bool; - static auto unscale(float value) -> float; + static auto unscale(f32 value) -> f32; struct Cocoa { static auto doAbout() -> void; @@ -45,11 +45,11 @@ struct Application { Font font; bool initialized = false; Locale locale; - int modal = 0; + s32 modal = 0; string name; function onMain; bool quit = false; - float scale = 1.0; + f32 scale = 1.0; bool screenSaver = true; bool toolTips = true; diff --git a/hiro/core/browser-window.hpp b/hiro/core/browser-window.hpp new file mode 100644 index 0000000000..76c55a4c18 --- /dev/null +++ b/hiro/core/browser-window.hpp @@ -0,0 +1,21 @@ +#if defined(Hiro_BrowserWindow) +struct BrowserWindow { + using type = BrowserWindow; + + auto directory() -> string; + auto open() -> string; + auto save() -> string; + auto setFilters(const vector& filters = {"*"}) -> type&; + auto setParent(sWindow parent) -> type&; + auto setPath(const string& path = "") -> type&; + auto setTitle(const string& title = "") -> type&; + +//private: + struct State { + vector filters; + sWindow parent; + string path; + string title; + } state; +}; +#endif diff --git a/hiro/core/color.cpp b/hiro/core/color.cpp index c13fd4f39d..c61da07a42 100644 --- a/hiro/core/color.cpp +++ b/hiro/core/color.cpp @@ -4,7 +4,7 @@ Color::Color() { setColor(0, 0, 0, 0); } -Color::Color(signed red, signed green, signed blue, signed alpha) { +Color::Color(s32 red, s32 green, s32 blue, s32 alpha) { setColor(red, green, blue, alpha); } @@ -20,19 +20,19 @@ auto Color::operator!=(const Color& source) const -> bool { return !operator==(source); } -auto Color::alpha() const -> uint8_t { +auto Color::alpha() const -> u8 { return state.alpha; } -auto Color::blue() const -> uint8_t { +auto Color::blue() const -> u8 { return state.blue; } -auto Color::green() const -> uint8_t { +auto Color::green() const -> u8 { return state.green; } -auto Color::red() const -> uint8_t { +auto Color::red() const -> u8 { return state.red; } @@ -40,12 +40,12 @@ auto Color::reset() -> type& { return setColor(0, 0, 0, 0); } -auto Color::setAlpha(signed alpha) -> type& { +auto Color::setAlpha(s32 alpha) -> type& { state.alpha = max(0, min(255, alpha)); return *this; } -auto Color::setBlue(signed blue) -> type& { +auto Color::setBlue(s32 blue) -> type& { state.blue = max(0, min(255, blue)); return *this; } @@ -54,7 +54,7 @@ auto Color::setColor(Color color) -> type& { return setColor(color.red(), color.green(), color.blue(), color.alpha()); } -auto Color::setColor(signed red, signed green, signed blue, signed alpha) -> type& { +auto Color::setColor(s32 red, s32 green, s32 blue, s32 alpha) -> type& { state.red = max(0, min(255, red )); state.green = max(0, min(255, green)); state.blue = max(0, min(255, blue )); @@ -62,17 +62,17 @@ auto Color::setColor(signed red, signed green, signed blue, signed alpha) -> typ return *this; } -auto Color::setGreen(signed green) -> type& { +auto Color::setGreen(s32 green) -> type& { state.green = max(0, min(255, green)); return *this; } -auto Color::setRed(signed red) -> type& { +auto Color::setRed(s32 red) -> type& { state.red = max(0, min(255, red)); return *this; } -auto Color::setValue(uint32_t value) -> type& { +auto Color::setValue(u32 value) -> type& { state.alpha = value >> 24 & 255; state.red = value >> 16 & 255; state.green = value >> 8 & 255; @@ -80,7 +80,7 @@ auto Color::setValue(uint32_t value) -> type& { return *this; } -auto Color::value() const -> uint32_t { +auto Color::value() const -> u32 { return state.alpha << 24 | state.red << 16 | state.green << 8 | state.blue << 0; } diff --git a/hiro/core/color.hpp b/hiro/core/color.hpp new file mode 100644 index 0000000000..0bb1683238 --- /dev/null +++ b/hiro/core/color.hpp @@ -0,0 +1,34 @@ +#if defined(Hiro_Color) +struct Color { + using type = Color; + + Color(); + Color(s32 red, s32 green, s32 blue, s32 alpha = 255); + + explicit operator bool() const; + auto operator==(const Color& source) const -> bool; + auto operator!=(const Color& source) const -> bool; + + auto alpha() const -> u8; + auto blue() const -> u8; + auto green() const -> u8; + auto red() const -> u8; + auto reset() -> type&; + auto setAlpha(s32 alpha) -> type&; + auto setBlue(s32 blue) -> type&; + auto setColor(Color color = {}) -> type&; + auto setColor(s32 red, s32 green, s32 blue, s32 alpha = 255) -> type&; + auto setGreen(s32 green) -> type&; + auto setRed(s32 red) -> type&; + auto setValue(u32 value) -> type&; + auto value() const -> u32; + +//private: + struct State { + u8 red; + u8 green; + u8 blue; + u8 alpha; + } state; +}; +#endif diff --git a/hiro/core/core.hpp b/hiro/core/core.hpp index 27d452764c..98e6b02221 100644 --- a/hiro/core/core.hpp +++ b/hiro/core/core.hpp @@ -95,322 +95,27 @@ Declare(Viewport) #undef Declare -enum class Orientation : uint { Horizontal, Vertical }; -enum class Navigation : uint { Top, Bottom, Left, Right }; -enum class Sort : uint { None, Ascending, Descending }; - -#if defined(Hiro_Color) -struct Color { - using type = Color; - - Color(); - Color(int red, int green, int blue, int alpha = 255); - - explicit operator bool() const; - auto operator==(const Color& source) const -> bool; - auto operator!=(const Color& source) const -> bool; - - auto alpha() const -> uint8_t; - auto blue() const -> uint8_t; - auto green() const -> uint8_t; - auto red() const -> uint8_t; - auto reset() -> type&; - auto setAlpha(int alpha) -> type&; - auto setBlue(int blue) -> type&; - auto setColor(Color color = {}) -> type&; - auto setColor(int red, int green, int blue, int alpha = 255) -> type&; - auto setGreen(int green) -> type&; - auto setRed(int red) -> type&; - auto setValue(uint32_t value) -> type&; - auto value() const -> uint32_t; - -//private: - struct State { - uint8_t red; - uint8_t green; - uint8_t blue; - uint8_t alpha; - } state; -}; -#endif - -#if defined(Hiro_Gradient) -struct Gradient { - using type = Gradient; - - Gradient(); - - explicit operator bool() const; - auto operator==(const Gradient& source) const -> bool; - auto operator!=(const Gradient& source) const -> bool; - - auto setBilinear(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) -> type&; - auto setHorizontal(Color left, Color right) -> type&; - auto setVertical(Color top, Color bottom) -> type&; - -//private: - struct State { - vector colors; - } state; -}; -#endif - -#if defined(Hiro_Alignment) -struct Alignment { - using type = Alignment; - static const Alignment Center; - - Alignment(); - Alignment(float horizontal, float vertical = 0.5); - - explicit operator bool() const; - auto operator==(const Alignment& source) const -> bool; - auto operator!=(const Alignment& source) const -> bool; - - auto horizontal() const -> float; - auto reset() -> type&; - auto setAlignment(float horizontal = -1.0, float vertical = 0.5) -> type&; - auto setHorizontal(float horizontal) -> type&; - auto setVertical(float vertical) -> type&; - auto vertical() const -> float; - -//private: - struct State { - float horizontal; - float vertical; - } state; -}; -#endif +enum class Orientation : u32 { Horizontal, Vertical }; +enum class Navigation : u32 { Top, Bottom, Left, Right }; +enum class Sort : u32 { None, Ascending, Descending }; +#include "color.hpp" +#include "gradient.hpp" +#include "alignment.hpp" #include "text-cursor.hpp" - -#if defined(Hiro_Position) -struct Position { - using type = Position; - - Position(); - Position(float x, float y); - template - Position(X x, Y y) : Position((float)x, (float)y) {} - - explicit operator bool() const; - auto operator==(const Position& source) const -> bool; - auto operator!=(const Position& source) const -> bool; - - auto reset() -> type&; - auto setPosition(Position position = {}) -> type&; - auto setPosition(float x, float y) -> type&; - auto setX(float x) -> type&; - auto setY(float y) -> type&; - auto x() const -> float; - auto y() const -> float; - -//private: - struct State { - float x; - float y; - } state; -}; -#endif - -#if defined(Hiro_Size) -struct Size { - using type = Size; - - Size(); - Size(float width, float height); - template - Size(W width, H height) : Size((float)width, (float)height) {} - - explicit operator bool() const; - auto operator==(const Size& source) const -> bool; - auto operator!=(const Size& source) const -> bool; - - auto height() const -> float; - auto reset() -> type&; - auto setHeight(float height) -> type&; - auto setSize(Size source = {}) -> type&; - auto setSize(float width, float height) -> type&; - auto setWidth(float width) -> type&; - auto width() const -> float; - - static constexpr float Maximum = -1.0; - static constexpr float Minimum = +0.0; - -//private: - struct State { - float width; - float height; - } state; -}; -#endif - -#if defined(Hiro_Geometry) -struct Geometry { - using type = Geometry; - - Geometry(); - Geometry(Position position, Size size); - Geometry(float x, float y, float width, float height); - template - Geometry(X x, Y y, W width, H height) : Geometry((float)x, (float)y, (float)width, (float)height) {} - - explicit operator bool() const; - auto operator==(const Geometry& source) const -> bool; - auto operator!=(const Geometry& source) const -> bool; - - auto height() const -> float; - auto position() const -> Position; - auto reset() -> type&; - auto setGeometry(Geometry geometry = {}) -> type&; - auto setGeometry(Position position, Size size) -> type&; - auto setGeometry(float x, float y, float width, float height) -> type&; - auto setHeight(float height) -> type&; - auto setPosition(Position position = {}) -> type&; - auto setPosition(float x, float y) -> type&; - auto setSize(Size size = {}) -> type&; - auto setSize(float width, float height) -> type&; - auto setWidth(float width) -> type&; - auto setX(float x) -> type&; - auto setY(float y) -> type&; - auto size() const -> Size; - auto width() const -> float; - auto x() const -> float; - auto y() const -> float; - -//private: - struct State { - float x; - float y; - float width; - float height; - } state; -}; -#endif - +#include "position.hpp" +#include "size.hpp" +#include "geometry.hpp" #include "font.hpp" #include "mouse-cursor.hpp" - -#if defined(Hiro_Hotkey) -struct Hotkey { - using type = Hotkey; - - Hotkey(); - Hotkey(const string& sequence); - - explicit operator bool() const; - auto operator==(const Hotkey& source) const -> bool; - auto operator!=(const Hotkey& source) const -> bool; - - auto doPress() const -> void; - auto doRelease() const -> void; - auto onPress(const function& callback = {}) -> type&; - auto onRelease(const function& callback = {}) -> type&; - auto reset() -> type&; - auto sequence() const -> string; - auto setSequence(const string& sequence = "") -> type&; - -//private: - struct State { - bool active = false; - vector keys; - function onPress; - function onRelease; - string sequence; - }; - shared_pointer state; -}; -#endif - +#include "hotkey.hpp" #include "application.hpp" #include "desktop.hpp" #include "monitor.hpp" - -#if defined(Hiro_Keyboard) -struct Keyboard { - Keyboard() = delete; - - static auto append(Hotkey hotkey) -> void; - static auto hotkey(uint position) -> Hotkey; - static auto hotkeyCount() -> uint; - static auto hotkeys() -> vector; - static auto poll() -> vector; - static auto pressed(const string& key) -> bool; - static auto released(const string& key) -> bool; - static auto remove(Hotkey hotkey) -> void; - - static const vector keys; - -//private: - struct State { - vector hotkeys; - }; - static State state; -}; -#endif - -#if defined(Hiro_Mouse) -struct Mouse { - enum class Button : uint { Left, Middle, Right }; - enum class Click : uint { Single, Double }; - - Mouse() = delete; - - static auto position() -> Position; - static auto pressed(Button) -> bool; - static auto released(Button) -> bool; -}; -#endif - -#if defined(Hiro_BrowserWindow) -struct BrowserWindow { - using type = BrowserWindow; - - auto directory() -> string; - auto open() -> string; - auto save() -> string; - auto setFilters(const vector& filters = {"*"}) -> type&; - auto setParent(sWindow parent) -> type&; - auto setPath(const string& path = "") -> type&; - auto setTitle(const string& title = "") -> type&; - -//private: - struct State { - vector filters; - sWindow parent; - string path; - string title; - } state; -}; -#endif - -#if defined(Hiro_MessageWindow) -struct MessageWindow { - enum class Buttons : uint { Ok, OkCancel, YesNo, YesNoCancel }; - enum class Response : uint { Ok, Cancel, Yes, No }; - - using type = MessageWindow; - - MessageWindow(const string& text = ""); - - auto error(Buttons = Buttons::Ok) -> Response; - auto information(Buttons = Buttons::Ok) -> Response; - auto question(Buttons = Buttons::YesNo) -> Response; - auto setParent(sWindow parent) -> type&; - auto setText(const string& text = "") -> type&; - auto setTitle(const string& title = "") -> type&; - auto warning(Buttons = Buttons::Ok) -> Response; - -//private: - struct State { - MessageWindow::Buttons buttons = MessageWindow::Buttons::Ok; - sWindow parent; - string text; - string title; - } state; -}; -#endif - +#include "keyboard.hpp" +#include "mouse.hpp" +#include "browser-window.hpp" +#include "message-window.hpp" #include "attribute.hpp" #define Declare(Name) \ @@ -431,663 +136,62 @@ struct MessageWindow { virtual auto allocate() -> pObject*; \ #include "object.hpp" + +#undef Declare +#define Declare(Name) \ + using type = m##Name; \ + operator s##Name() const { return instance; } \ + auto self() -> p##Name* { return (p##Name*)delegate; } \ + auto self() const -> const p##Name* { return (const p##Name*)delegate; } \ + auto bind(const s##Name& instance) -> void { \ + this->instance = instance; \ + setGroup(); \ + if(!abstract()) construct(); \ + } \ + auto unbind() -> void { \ + reset(); \ + destruct(); \ + instance.reset(); \ + } \ + auto allocate() -> pObject* override; \ + #include "group.hpp" #include "timer.hpp" #include "window.hpp" +#include "status-bar.hpp" +#include "menu-bar.hpp" +#include "popup-menu.hpp" -#if defined(Hiro_StatusBar) -struct mStatusBar : mObject { - Declare(StatusBar) - - auto remove() -> type& override; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - string text; - } state; -}; -#endif - -#if defined(Hiro_MenuBar) -struct mMenuBar : mObject { - Declare(MenuBar) - - auto append(sMenu menu) -> type&; - auto menu(uint position) const -> Menu; - auto menuCount() const -> uint; - auto menus() const -> vector; - auto remove() -> type& override; - auto remove(sMenu menu) -> type&; - auto reset() -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - -//private: - struct State { - vector menus; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_PopupMenu) -struct mPopupMenu : mObject { - Declare(PopupMenu) - using mObject::remove; - - auto action(uint position) const -> Action; - auto actionCount() const -> uint; - auto actions() const -> vector; - auto append(sAction action) -> type&; - auto remove(sAction action) -> type&; - auto reset() -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - auto setVisible(bool visible = true) -> type& override; - -//private: - struct State { - vector actions; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_Action) -struct mAction : mObject { - Declare(Action) - - auto remove() -> type& override; - -//private: - struct State { - } state; -}; -#endif - -#if defined(Hiro_Menu) -struct mMenu : mAction { - Declare(Menu) - using mObject::remove; - - auto action(uint position) const -> Action; - auto actionCount() const -> uint; - auto actions() const -> vector; - auto append(sAction action) -> type&; - auto icon() const -> image; - auto remove(sAction action) -> type&; - auto reset() -> type&; - auto setIcon(const image& icon = {}) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - vector actions; - image icon; - string text; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_MenuSeparator) -struct mMenuSeparator : mAction { - Declare(MenuSeparator) - -//private: - struct State { - } state; -}; -#endif - -#if defined(Hiro_MenuItem) -struct mMenuItem : mAction { - Declare(MenuItem) - - auto doActivate() const -> void; - auto icon() const -> image; - auto onActivate(const function& callback = {}) -> type&; - auto setIcon(const image& icon = {}) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - image icon; - function onActivate; - string text; - } state; -}; -#endif - -#if defined(Hiro_MenuCheckItem) -struct mMenuCheckItem : mAction { - Declare(MenuCheckItem) - - auto checked() const -> bool; - auto doToggle() const -> void; - auto onToggle(const function& callback = {}) -> type&; - auto setChecked(bool checked = true) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool checked = false; - function onToggle; - string text; - } state; -}; -#endif - -#if defined(Hiro_MenuRadioItem) -struct mMenuRadioItem : mAction { - Declare(MenuRadioItem) - - auto checked() const -> bool; - auto doActivate() const -> void; - auto group() const -> Group override; - auto onActivate(const function& callback = {}) -> type&; - auto setChecked() -> type&; - auto setGroup(sGroup group = {}) -> type& override; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool checked = false; - sGroup group; - function onActivate; - string text; - } state; -}; -#endif +#include "action/action.hpp" +#include "action/menu.hpp" +#include "action/menu-separator.hpp" +#include "action/menu-item.hpp" +#include "action/menu-check-item.hpp" +#include "action/menu-radio-item.hpp" #include "sizable.hpp" #include "widget/widget.hpp" - -#if defined(Hiro_Button) -struct mButton : mWidget { - Declare(Button) - - auto bordered() const -> bool; - auto doActivate() const -> void; - auto icon() const -> image; - auto onActivate(const function& callback = {}) -> type&; - auto orientation() const -> Orientation; - auto setBordered(bool bordered = true) -> type&; - auto setIcon(const image& icon = {}) -> type&; - auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool bordered = true; - image icon; - function onActivate; - Orientation orientation = Orientation::Horizontal; - string text; - } state; -}; -#endif - +#include "widget/button.hpp" #include "widget/canvas.hpp" - -#if defined(Hiro_CheckButton) -struct mCheckButton : mWidget { - Declare(CheckButton) - - auto bordered() const -> bool; - auto checked() const -> bool; - auto doToggle() const -> void; - auto icon() const -> image; - auto onToggle(const function& callback = {}) -> type&; - auto orientation() const -> Orientation; - auto setBordered(bool bordered = true) -> type&; - auto setChecked(bool checked = true) -> type&; - auto setIcon(const image& icon = {}) -> type&; - auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool bordered = true; - bool checked = false; - image icon; - function onToggle; - Orientation orientation = Orientation::Horizontal; - string text; - } state; -}; -#endif - -#if defined(Hiro_CheckLabel) -struct mCheckLabel : mWidget { - Declare(CheckLabel) - - auto checked() const -> bool; - auto doToggle() const -> void; - auto onToggle(const function& callback = {}) -> type&; - auto setChecked(bool checked = true) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool checked = false; - function onToggle; - string text; - } state; -}; -#endif - -#if defined(Hiro_ComboButton) -struct mComboButton : mWidget { - Declare(ComboButton) - using mObject::remove; - - auto append(sComboButtonItem item) -> type&; - auto doChange() const -> void; - auto item(uint position) const -> ComboButtonItem; - auto itemCount() const -> uint; - auto items() const -> vector; - auto onChange(const function& callback = {}) -> type&; - auto remove(sComboButtonItem item) -> type&; - auto reset() -> type&; - auto selected() const -> ComboButtonItem; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - -//private: - struct State { - vector items; - function onChange; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_ComboButton) -struct mComboButtonItem : mObject { - Declare(ComboButtonItem) - - auto icon() const -> image; - auto remove() -> type& override; - auto selected() const -> bool; - auto setIcon(const image& icon = {}) -> type&; - auto setSelected() -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - image icon; - bool selected = false; - string text; - } state; -}; -#endif - -#if defined(Hiro_ComboEdit) -struct mComboEdit : mWidget { - Declare(ComboEdit) - using mObject::remove; - - auto append(sComboEditItem item) -> type&; - auto backgroundColor() const -> Color; - auto doActivate() const -> void; - auto doChange() const -> void; - auto editable() const -> bool; - auto foregroundColor() const -> Color; - auto item(uint position) const -> ComboEditItem; - auto itemCount() const -> uint; - auto items() const -> vector; - auto onActivate(const function& callback = {}) -> type&; - auto onChange(const function& callback = {}) -> type&; - auto remove(sComboEditItem item) -> type&; - auto reset() -> type&; - auto setBackgroundColor(Color color = {}) -> type&; - auto setEditable(bool editable = true) -> type&; - auto setForegroundColor(Color color = {}) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - Color backgroundColor; - bool editable = true; - Color foregroundColor; - vector items; - function onActivate; - function onChange; - string text; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_ComboEdit) -struct mComboEditItem : mObject { - Declare(ComboEditItem) - - auto icon() const -> image; - auto remove() -> type& override; - auto setIcon(const image& icon = {}) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - image icon; - string text; - } state; -}; -#endif - -#if defined(Hiro_Console) -struct mConsole : mWidget { - Declare(Console) - - auto backgroundColor() const -> Color; - auto doActivate(string) const -> void; - auto foregroundColor() const -> Color; - auto onActivate(const function& callback = {}) -> type&; - auto print(const string& text) -> type&; - auto prompt() const -> string; - auto reset() -> type&; - auto setBackgroundColor(Color color = {}) -> type&; - auto setForegroundColor(Color color = {}) -> type&; - auto setPrompt(const string& prompt = "") -> type&; - -//private: - struct State { - Color backgroundColor; - Color foregroundColor; - function onActivate; - string prompt; - } state; -}; -#endif - -#if defined(Hiro_Frame) -struct mFrame : mWidget { - Declare(Frame) - using mObject::remove; - - auto append(sSizable sizable) -> type&; - auto remove(sSizable sizable) -> type&; - auto reset() -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - auto setText(const string& text = "") -> type&; - auto sizable() const -> Sizable; - auto text() const -> string; - -//private: - struct State { - sSizable sizable; - string text; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_HexEdit) -struct mHexEdit : mWidget { - Declare(HexEdit) - - auto address() const -> uint; - auto backgroundColor() const -> Color; - auto columns() const -> uint; - auto doRead(uint offset) const -> uint8_t; - auto doWrite(uint offset, uint8_t data) const -> void; - auto foregroundColor() const -> Color; - auto length() const -> uint; - auto onRead(const function& callback = {}) -> type&; - auto onWrite(const function& callback = {}) -> type&; - auto rows() const -> uint; - auto setAddress(uint address = 0) -> type&; - auto setBackgroundColor(Color color = {}) -> type&; - auto setColumns(uint columns = 16) -> type&; - auto setForegroundColor(Color color = {}) -> type&; - auto setLength(uint length) -> type&; - auto setRows(uint rows = 16) -> type&; - auto update() -> type&; - -//private: - struct State { - uint address = 0; - Color backgroundColor; - uint columns = 16; - Color foregroundColor; - uint length = 0; - function onRead; - function onWrite; - uint rows = 16; - } state; -}; -#endif - -#if defined(Hiro_HorizontalScrollBar) -struct mHorizontalScrollBar : mWidget { - Declare(HorizontalScrollBar) - - auto doChange() const -> void; - auto length() const -> uint; - auto onChange(const function& callback = {}) -> type&; - auto position() const -> uint; - auto setLength(uint length = 101) -> type&; - auto setPosition(uint position = 0) -> type&; - -//private: - struct State { - uint length = 101; - function onChange; - uint position = 0; - } state; -}; -#endif - -#if defined(Hiro_HorizontalSlider) -struct mHorizontalSlider : mWidget { - Declare(HorizontalSlider) - - auto doChange() const -> void; - auto length() const -> uint; - auto onChange(const function& callback = {}) -> type&; - auto position() const -> uint; - auto setLength(uint length = 101) -> type&; - auto setPosition(uint position = 0) -> type&; - -//private: - struct State { - uint length = 101; - function onChange; - uint position = 0; - } state; -}; -#endif - -#if defined(Hiro_IconView) -struct mIconView : mWidget { - Declare(IconView) - using mObject::remove; - - auto append(sIconViewItem item) -> type&; - auto backgroundColor() const -> Color; - auto batchable() const -> bool; - auto batched() const -> vector; - auto doActivate() const -> void; - auto doChange() const -> void; - auto doContext() const -> void; - auto flow() const -> Orientation; - auto foregroundColor() const -> Color; - auto item(uint position) const -> IconViewItem; - auto itemCount() const -> uint; - auto items() const -> vector; - auto onActivate(const function& callback = {}) -> type&; - auto onChange(const function& callback = {}) -> type&; - auto onContext(const function& callback = {}) -> type&; - auto orientation() const -> Orientation; - auto remove(sIconViewItem item) -> type&; - auto reset() -> type&; - auto selected() const -> IconViewItem; - auto setBackgroundColor(Color color = {}) -> type&; - auto setBatchable(bool batchable = true) -> type&; - auto setFlow(Orientation flow = Orientation::Vertical) -> type&; - auto setForegroundColor(Color color = {}) -> type&; - auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; - auto setParent(mObject* object = nullptr, int offset = -1) -> type& override; - auto setSelected(const vector& selections) -> type&; - -//private: - struct State { - Color backgroundColor; - bool batchable = false; - Color foregroundColor; - Orientation flow = Orientation::Vertical; - vector items; - function onActivate; - function onChange; - function onContext; - Orientation orientation = Orientation::Horizontal; - } state; - - auto destruct() -> void override; -}; -#endif - -#if defined(Hiro_IconView) -struct mIconViewItem : mObject { - Declare(IconViewItem) - - auto icon() const -> image; - auto remove() -> type& override; - auto selected() const -> bool; - auto setIcon(const image& icon = {}) -> type&; - auto setSelected(bool selected = true) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - image icon; - bool selected = false; - string text; - } state; -}; -#endif - +#include "widget/check-button.hpp" +#include "widget/check-label.hpp" +#include "widget/combo-button.hpp" +#include "widget/combo-button-item.hpp" +#include "widget/combo-edit.hpp" +#include "widget/combo-edit-item.hpp" +#include "widget/console.hpp" +#include "widget/frame.hpp" +#include "widget/hex-edit.hpp" +#include "widget/horizontal-scroll-bar.hpp" +#include "widget/horizontal-slider.hpp" +#include "widget/icon-view.hpp" +#include "widget/icon-view-item.hpp" #include "widget/label.hpp" - -#if defined(Hiro_LineEdit) -struct mLineEdit : mWidget { - Declare(LineEdit) - - auto backgroundColor() const -> Color; - auto doActivate() const -> void; - auto doChange() const -> void; - auto editable() const -> bool; - auto foregroundColor() const -> Color; - auto onActivate(const function& callback = {}) -> type&; - auto onChange(const function& callback = {}) -> type&; - auto setBackgroundColor(Color color = {}) -> type&; - auto setEditable(bool editable = true) -> type&; - auto setForegroundColor(Color color = {}) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - Color backgroundColor; - bool editable = true; - Color foregroundColor; - function onActivate; - function onChange; - string text; - } state; -}; -#endif - -#if defined(Hiro_ProgressBar) -struct mProgressBar : mWidget { - Declare(ProgressBar) - - auto position() const -> uint; - auto setPosition(uint position) -> type&; - -//private: - struct State { - uint position = 0; - } state; -}; -#endif - -#if defined(Hiro_RadioButton) -struct mRadioButton : mWidget { - Declare(RadioButton) - - auto bordered() const -> bool; - auto checked() const -> bool; - auto doActivate() const -> void; - auto group() const -> Group override; - auto icon() const -> image; - auto onActivate(const function& callback = {}) -> type&; - auto orientation() const -> Orientation; - auto setBordered(bool bordered = true) -> type&; - auto setChecked() -> type&; - auto setGroup(sGroup group = {}) -> type& override; - auto setIcon(const image& icon = {}) -> type&; - auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool bordered = true; - bool checked = false; - sGroup group; - image icon; - function onActivate; - Orientation orientation = Orientation::Horizontal; - string text; - } state; -}; -#endif - -#if defined(Hiro_RadioLabel) -struct mRadioLabel : mWidget { - Declare(RadioLabel) - - auto checked() const -> bool; - auto doActivate() const -> void; - auto group() const -> Group override; - auto onActivate(const function& callback = {}) -> type&; - auto setChecked() -> type&; - auto setGroup(sGroup group = {}) -> type& override; - auto setText(const string& text = "") -> type&; - auto text() const -> string; - -//private: - struct State { - bool checked = false; - sGroup group; - function onActivate; - string text; - } state; -}; -#endif - +#include "widget/line-edit.hpp" +#include "widget/progress-bar.hpp" +#include "widget/radio-button.hpp" +#include "widget/radio-label.hpp" #include "widget/source-edit.hpp" #include "widget/tab-frame.hpp" #include "widget/tab-frame-item.hpp" @@ -1098,47 +202,8 @@ struct mRadioLabel : mWidget { #include "widget/text-edit.hpp" #include "widget/tree-view.hpp" #include "widget/tree-view-item.hpp" - -#if defined(Hiro_VerticalScrollBar) -struct mVerticalScrollBar : mWidget { - Declare(VerticalScrollBar) - - auto doChange() const -> void; - auto length() const -> uint; - auto onChange(const function& callback = {}) -> type&; - auto position() const -> uint; - auto setLength(uint length = 101) -> type&; - auto setPosition(uint position = 0) -> type&; - -//private: - struct State { - uint length = 101; - function onChange; - uint position = 0; - } state; -}; -#endif - -#if defined(Hiro_VerticalSlider) -struct mVerticalSlider : mWidget { - Declare(VerticalSlider) - - auto doChange() const -> void; - auto length() const -> uint; - auto onChange(const function& callback = {}) -> type&; - auto position() const -> uint; - auto setLength(uint length = 101) -> type&; - auto setPosition(uint position = 0) -> type&; - -//private: - struct State { - uint length = 101; - function onChange; - uint position = 0; - } state; -}; -#endif - +#include "widget/vertical-scroll-bar.hpp" +#include "widget/vertical-slider.hpp" #include "widget/viewport.hpp" #undef Declare diff --git a/hiro/core/font.cpp b/hiro/core/font.cpp index d17e007b88..3de9e17b47 100644 --- a/hiro/core/font.cpp +++ b/hiro/core/font.cpp @@ -4,7 +4,7 @@ const string Font::Sans = "{sans}"; const string Font::Serif = "{serif}"; const string Font::Mono = "{mono}"; -Font::Font(const string& family, float size) { +Font::Font(const string& family, f32 size) { setFamily(family); setSize(size); state.bold = false; @@ -58,12 +58,12 @@ auto Font::setItalic(bool italic) -> type& { return *this; } -auto Font::setSize(float size) -> type& { +auto Font::setSize(f32 size) -> type& { state.size = size; return *this; } -auto Font::size() const -> float { +auto Font::size() const -> f32 { return state.size; } diff --git a/hiro/core/font.hpp b/hiro/core/font.hpp index 4d36f0d561..d987b2d053 100644 --- a/hiro/core/font.hpp +++ b/hiro/core/font.hpp @@ -2,7 +2,7 @@ struct Font { using type = Font; - Font(const string& family = "", float size = 0.0); + Font(const string& family = "", f32 size = 0.0); explicit operator bool() const; auto operator==(const Font& source) const -> bool; @@ -15,21 +15,19 @@ struct Font { auto setBold(bool bold = true) -> type&; auto setFamily(const string& family = "") -> type&; auto setItalic(bool italic = true) -> type&; - auto setSize(float size = 0.0) -> type&; - auto size() const -> float; + auto setSize(f32 size = 0.0) -> type&; + auto size() const -> f32; auto size(const string& text) const -> Size; static const string Sans; static const string Serif; static const string Mono; -//private: -//sizeof(Font) == 32 struct State { - string family; //24 - float size = 0.0; //4 - char bold = false; //1+ - char italic = false; //1=4 + string family; + f32 size = 0.0; + char bold = false; + char italic = false; } state; }; #endif diff --git a/hiro/core/geometry.cpp b/hiro/core/geometry.cpp index b5a2242f03..5c8db1946f 100644 --- a/hiro/core/geometry.cpp +++ b/hiro/core/geometry.cpp @@ -8,7 +8,7 @@ Geometry::Geometry(Position position, Size size) { setGeometry(position, size); } -Geometry::Geometry(float x, float y, float width, float height) { +Geometry::Geometry(f32 x, f32 y, f32 width, f32 height) { setGeometry(x, y, width, height); } @@ -24,7 +24,7 @@ auto Geometry::operator!=(const Geometry& source) const -> bool { return !operator==(source); } -auto Geometry::height() const -> float { +auto Geometry::height() const -> f32 { return state.height; } @@ -36,7 +36,7 @@ auto Geometry::reset() -> type& { return setGeometry(0, 0, 0, 0); } -auto Geometry::setHeight(float height) -> type& { +auto Geometry::setHeight(f32 height) -> type& { state.height = height; return *this; } @@ -50,7 +50,7 @@ auto Geometry::setGeometry(Position position, Size size) -> type& { return *this; } -auto Geometry::setGeometry(float x, float y, float width, float height) -> type& { +auto Geometry::setGeometry(f32 x, f32 y, f32 width, f32 height) -> type& { state.x = x; state.y = y; state.width = width; @@ -62,7 +62,7 @@ auto Geometry::setPosition(Position position) -> type& { return setPosition(position.x(), position.y()); } -auto Geometry::setPosition(float x, float y) -> type& { +auto Geometry::setPosition(f32 x, f32 y) -> type& { state.x = x; state.y = y; return *this; @@ -72,23 +72,23 @@ auto Geometry::setSize(Size size) -> type& { return setSize(size.width(), size.height()); } -auto Geometry::setSize(float width, float height) -> type& { +auto Geometry::setSize(f32 width, f32 height) -> type& { state.width = width; state.height = height; return *this; } -auto Geometry::setWidth(float width) -> type& { +auto Geometry::setWidth(f32 width) -> type& { state.width = width; return *this; } -auto Geometry::setX(float x) -> type& { +auto Geometry::setX(f32 x) -> type& { state.x = x; return *this; } -auto Geometry::setY(float y) -> type& { +auto Geometry::setY(f32 y) -> type& { state.y = y; return *this; } @@ -97,15 +97,15 @@ auto Geometry::size() const -> Size { return {state.width, state.height}; } -auto Geometry::width() const -> float { +auto Geometry::width() const -> f32 { return state.width; } -auto Geometry::x() const -> float { +auto Geometry::x() const -> f32 { return state.x; } -auto Geometry::y() const -> float { +auto Geometry::y() const -> f32 { return state.y; } diff --git a/hiro/core/geometry.hpp b/hiro/core/geometry.hpp new file mode 100644 index 0000000000..830078838f --- /dev/null +++ b/hiro/core/geometry.hpp @@ -0,0 +1,42 @@ +#if defined(Hiro_Geometry) +struct Geometry { + using type = Geometry; + + Geometry(); + Geometry(Position position, Size size); + Geometry(f32 x, f32 y, f32 width, f32 height); + template + Geometry(X x, Y y, W width, H height) : Geometry((f32)x, (f32)y, (f32)width, (f32)height) {} + + explicit operator bool() const; + auto operator==(const Geometry& source) const -> bool; + auto operator!=(const Geometry& source) const -> bool; + + auto height() const -> f32; + auto position() const -> Position; + auto reset() -> type&; + auto setGeometry(Geometry geometry = {}) -> type&; + auto setGeometry(Position position, Size size) -> type&; + auto setGeometry(f32 x, f32 y, f32 width, f32 height) -> type&; + auto setHeight(f32 height) -> type&; + auto setPosition(Position position = {}) -> type&; + auto setPosition(f32 x, f32 y) -> type&; + auto setSize(Size size = {}) -> type&; + auto setSize(f32 width, f32 height) -> type&; + auto setWidth(f32 width) -> type&; + auto setX(f32 x) -> type&; + auto setY(f32 y) -> type&; + auto size() const -> Size; + auto width() const -> f32; + auto x() const -> f32; + auto y() const -> f32; + +//private: + struct State { + f32 x; + f32 y; + f32 width; + f32 height; + } state; +}; +#endif diff --git a/hiro/core/gradient.hpp b/hiro/core/gradient.hpp new file mode 100644 index 0000000000..6900f4383e --- /dev/null +++ b/hiro/core/gradient.hpp @@ -0,0 +1,20 @@ +#if defined(Hiro_Gradient) +struct Gradient { + using type = Gradient; + + Gradient(); + + explicit operator bool() const; + auto operator==(const Gradient& source) const -> bool; + auto operator!=(const Gradient& source) const -> bool; + + auto setBilinear(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) -> type&; + auto setHorizontal(Color left, Color right) -> type&; + auto setVertical(Color top, Color bottom) -> type&; + +//private: + struct State { + vector colors; + } state; +}; +#endif diff --git a/hiro/core/group.cpp b/hiro/core/group.cpp index c420608d8d..b7c82d3984 100644 --- a/hiro/core/group.cpp +++ b/hiro/core/group.cpp @@ -14,7 +14,7 @@ auto mGroup::append(sObject object) -> type& { return *this; } -auto mGroup::object(unsigned position) const -> Object { +auto mGroup::object(u32 position) const -> Object { if(position < objectCount()) { if(auto object = state.objects[position].acquire()) { return object; @@ -23,7 +23,7 @@ auto mGroup::object(unsigned position) const -> Object { return {}; } -auto mGroup::objectCount() const -> unsigned { +auto mGroup::objectCount() const -> u32 { return state.objects.size(); } diff --git a/hiro/core/group.hpp b/hiro/core/group.hpp index 0c6c6d70bb..f1d328be3d 100644 --- a/hiro/core/group.hpp +++ b/hiro/core/group.hpp @@ -4,8 +4,8 @@ struct mGroup : mObject { using mObject::remove; auto append(sObject object) -> type&; - auto object(uint offset) const -> Object; - auto objectCount() const -> uint; + auto object(u32 offset) const -> Object; + auto objectCount() const -> u32; auto objects() const -> vector; auto remove(sObject object) -> type&; diff --git a/hiro/core/hotkey.hpp b/hiro/core/hotkey.hpp new file mode 100644 index 0000000000..57eeb35c57 --- /dev/null +++ b/hiro/core/hotkey.hpp @@ -0,0 +1,30 @@ +#if defined(Hiro_Hotkey) +struct Hotkey { + using type = Hotkey; + + Hotkey(); + Hotkey(const string& sequence); + + explicit operator bool() const; + auto operator==(const Hotkey& source) const -> bool; + auto operator!=(const Hotkey& source) const -> bool; + + auto doPress() const -> void; + auto doRelease() const -> void; + auto onPress(const function& callback = {}) -> type&; + auto onRelease(const function& callback = {}) -> type&; + auto reset() -> type&; + auto sequence() const -> string; + auto setSequence(const string& sequence = "") -> type&; + +//private: + struct State { + bool active = false; + vector keys; + function onPress; + function onRelease; + string sequence; + }; + shared_pointer state; +}; +#endif diff --git a/hiro/core/keyboard.cpp b/hiro/core/keyboard.cpp index 8abbbf3d0c..fdade2822b 100644 --- a/hiro/core/keyboard.cpp +++ b/hiro/core/keyboard.cpp @@ -29,12 +29,12 @@ auto Keyboard::append(Hotkey hotkey) -> void { state.hotkeys.append(hotkey); } -auto Keyboard::hotkey(unsigned position) -> Hotkey { +auto Keyboard::hotkey(u32 position) -> Hotkey { if(position < hotkeyCount()) return state.hotkeys[position]; return {}; } -auto Keyboard::hotkeyCount() -> unsigned { +auto Keyboard::hotkeyCount() -> u32 { return state.hotkeys.size(); } diff --git a/hiro/core/keyboard.hpp b/hiro/core/keyboard.hpp new file mode 100644 index 0000000000..481b5a2114 --- /dev/null +++ b/hiro/core/keyboard.hpp @@ -0,0 +1,22 @@ +#if defined(Hiro_Keyboard) +struct Keyboard { + Keyboard() = delete; + + static auto append(Hotkey hotkey) -> void; + static auto hotkey(u32 position) -> Hotkey; + static auto hotkeyCount() -> u32; + static auto hotkeys() -> vector; + static auto poll() -> vector; + static auto pressed(const string& key) -> bool; + static auto released(const string& key) -> bool; + static auto remove(Hotkey hotkey) -> void; + + static const vector keys; + +//private: + struct State { + vector hotkeys; + }; + static State state; +}; +#endif diff --git a/hiro/core/lock.hpp b/hiro/core/lock.hpp index 3e5dfb39ce..4234e0c480 100644 --- a/hiro/core/lock.hpp +++ b/hiro/core/lock.hpp @@ -46,5 +46,5 @@ struct Lock { --locks; } - mutable int locks = 0; + mutable s32 locks = 0; }; diff --git a/hiro/core/menu-bar.cpp b/hiro/core/menu-bar.cpp index 8c653b4b30..712e4573f2 100644 --- a/hiro/core/menu-bar.cpp +++ b/hiro/core/menu-bar.cpp @@ -18,12 +18,12 @@ auto mMenuBar::append(sMenu menu) -> type& { return *this; } -auto mMenuBar::menu(unsigned position) const -> Menu { +auto mMenuBar::menu(u32 position) const -> Menu { if(position < menuCount()) return state.menus[position]; return {}; } -auto mMenuBar::menuCount() const -> unsigned { +auto mMenuBar::menuCount() const -> u32 { return state.menus.size(); } @@ -39,7 +39,7 @@ auto mMenuBar::remove() -> type& { } auto mMenuBar::remove(sMenu menu) -> type& { - signed offset = menu->offset(); + s32 offset = menu->offset(); signal(remove, menu); state.menus.remove(offset); for(auto n : range(offset, menuCount())) { @@ -54,7 +54,7 @@ auto mMenuBar::reset() -> type& { return *this; } -auto mMenuBar::setParent(mObject* parent, signed offset) -> type& { +auto mMenuBar::setParent(mObject* parent, s32 offset) -> type& { for(auto& menu : reverse(state.menus)) menu->destruct(); mObject::setParent(parent, offset); for(auto& menu : state.menus) menu->setParent(this, menu->offset()); diff --git a/hiro/core/menu-bar.hpp b/hiro/core/menu-bar.hpp new file mode 100644 index 0000000000..8140a43d4f --- /dev/null +++ b/hiro/core/menu-bar.hpp @@ -0,0 +1,21 @@ +#if defined(Hiro_MenuBar) +struct mMenuBar : mObject { + Declare(MenuBar) + + auto append(sMenu menu) -> type&; + auto menu(u32 position) const -> Menu; + auto menuCount() const -> u32; + auto menus() const -> vector; + auto remove() -> type& override; + auto remove(sMenu menu) -> type&; + auto reset() -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + +//private: + struct State { + vector menus; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/message-window.hpp b/hiro/core/message-window.hpp new file mode 100644 index 0000000000..44f9ccd8ae --- /dev/null +++ b/hiro/core/message-window.hpp @@ -0,0 +1,26 @@ +#if defined(Hiro_MessageWindow) +struct MessageWindow { + enum class Buttons : u32 { Ok, OkCancel, YesNo, YesNoCancel }; + enum class Response : u32 { Ok, Cancel, Yes, No }; + + using type = MessageWindow; + + MessageWindow(const string& text = ""); + + auto error(Buttons = Buttons::Ok) -> Response; + auto information(Buttons = Buttons::Ok) -> Response; + auto question(Buttons = Buttons::YesNo) -> Response; + auto setParent(sWindow parent) -> type&; + auto setText(const string& text = "") -> type&; + auto setTitle(const string& title = "") -> type&; + auto warning(Buttons = Buttons::Ok) -> Response; + +//private: + struct State { + MessageWindow::Buttons buttons = MessageWindow::Buttons::Ok; + sWindow parent; + string text; + string title; + } state; +}; +#endif diff --git a/hiro/core/monitor.cpp b/hiro/core/monitor.cpp index 63f25c65b8..e7b6296e83 100644 --- a/hiro/core/monitor.cpp +++ b/hiro/core/monitor.cpp @@ -1,22 +1,22 @@ #if defined(Hiro_Monitor) -auto Monitor::count() -> uint { +auto Monitor::count() -> u32 { return pMonitor::count(); } -auto Monitor::dpi(maybe monitor) -> Position { +auto Monitor::dpi(maybe monitor) -> Position { return pMonitor::dpi(monitor ? monitor() : primary()); } -auto Monitor::geometry(maybe monitor) -> Geometry { +auto Monitor::geometry(maybe monitor) -> Geometry { return pMonitor::geometry(monitor ? monitor() : primary()); } -auto Monitor::primary() -> uint { +auto Monitor::primary() -> u32 { return pMonitor::primary(); } -auto Monitor::workspace(maybe monitor) -> Geometry { +auto Monitor::workspace(maybe monitor) -> Geometry { return pMonitor::workspace(monitor ? monitor() : primary()); } diff --git a/hiro/core/monitor.hpp b/hiro/core/monitor.hpp index 2f580845a0..53a6035f78 100644 --- a/hiro/core/monitor.hpp +++ b/hiro/core/monitor.hpp @@ -2,26 +2,26 @@ struct Monitor { Monitor() = delete; - static auto count() -> uint; - static auto dpi(maybe monitor = nothing) -> Position; - static auto geometry(maybe monitor = nothing) -> Geometry; - static auto primary() -> uint; - static auto workspace(maybe monitor = nothing) -> Geometry; + static auto count() -> u32; + static auto dpi(maybe monitor = nothing) -> Position; + static auto geometry(maybe monitor = nothing) -> Geometry; + static auto primary() -> u32; + static auto workspace(maybe monitor = nothing) -> Geometry; }; //DPI scale X -inline auto sx(float x) -> float { +inline auto sx(f32 x) -> f32 { //round DPI scalar to increments of 0.5 (eg 1.0, 1.5, 2.0, ...) static auto scale = round(Monitor::dpi().x() / 96.0 * 2.0) / 2.0; return x * scale; } //DPI scale y -inline auto sy(float y) -> float { +inline auto sy(f32 y) -> f32 { static auto scale = round(Monitor::dpi().y() / 96.0 * 2.0) / 2.0; return y * scale; } -inline auto operator"" _sx(unsigned long long x) -> float { return sx(x); } -inline auto operator"" _sy(unsigned long long y) -> float { return sy(y); } +inline auto operator"" _sx(unsigned long long x) -> f32 { return sx(x); } +inline auto operator"" _sy(unsigned long long y) -> f32 { return sy(y); } #endif diff --git a/hiro/core/mouse.hpp b/hiro/core/mouse.hpp new file mode 100644 index 0000000000..94ed80a98f --- /dev/null +++ b/hiro/core/mouse.hpp @@ -0,0 +1,12 @@ +#if defined(Hiro_Mouse) +struct Mouse { + enum class Button : u32 { Left, Middle, Right }; + enum class Click : u32 { Single, Double }; + + Mouse() = delete; + + static auto position() -> Position; + static auto pressed(Button) -> bool; + static auto released(Button) -> bool; +}; +#endif diff --git a/hiro/core/object.cpp b/hiro/core/object.cpp index ab8094d148..07b540020c 100644 --- a/hiro/core/object.cpp +++ b/hiro/core/object.cpp @@ -56,7 +56,7 @@ auto mObject::abstract() const -> bool { return true; } -auto mObject::adjustOffset(signed displacement) -> type& { +auto mObject::adjustOffset(s32 displacement) -> type& { state.offset += displacement; return *this; } @@ -81,7 +81,7 @@ auto mObject::group() const -> Group { return {}; } -auto mObject::offset() const -> signed { +auto mObject::offset() const -> s32 { return state.offset; } @@ -280,7 +280,7 @@ auto mObject::setGroup(sGroup group) -> type& { return *this; } -auto mObject::setParent(mObject* parent, int offset) -> type& { +auto mObject::setParent(mObject* parent, s32 offset) -> type& { destruct(); state.parent = parent; state.offset = offset; diff --git a/hiro/core/object.hpp b/hiro/core/object.hpp index ab56282b45..6fd16908e0 100644 --- a/hiro/core/object.hpp +++ b/hiro/core/object.hpp @@ -10,12 +10,12 @@ struct mObject { explicit operator bool() const; auto abstract() const -> bool; - auto adjustOffset(int displacement) -> type&; + auto adjustOffset(s32 displacement) -> type&; auto enabled(bool recursive = false) const -> bool; virtual auto focused() const -> bool; auto font(bool recursive = false) const -> Font; virtual auto group() const -> Group; - auto offset() const -> int; + auto offset() const -> s32; auto parent() const -> mObject*; auto parentComboButton(bool recursive = false) const -> mComboButton*; auto parentComboEdit(bool recursive = false) const -> mComboEdit*; @@ -39,7 +39,7 @@ struct mObject { virtual auto setFocused() -> type&; virtual auto setFont(const Font& font = {}) -> type&; virtual auto setGroup(sGroup group = {}) -> type&; - virtual auto setParent(mObject* parent = nullptr, int offset = -1) -> type&; + virtual auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type&; virtual auto setVisible(bool visible = true) -> type&; auto visible(bool recursive = false) const -> bool; @@ -73,7 +73,7 @@ struct mObject { set attributes; Font font; mObject* parent = nullptr; - int offset = -1; + s32 offset = -1; char enabled = true; char visible = true; } state; diff --git a/hiro/core/popup-menu.cpp b/hiro/core/popup-menu.cpp index 400a39c87f..84dfaa1b54 100644 --- a/hiro/core/popup-menu.cpp +++ b/hiro/core/popup-menu.cpp @@ -11,12 +11,12 @@ auto mPopupMenu::destruct() -> void { // -auto mPopupMenu::action(unsigned position) const -> Action { +auto mPopupMenu::action(u32 position) const -> Action { if(position < actionCount()) return state.actions[position]; return {}; } -auto mPopupMenu::actionCount() const -> unsigned { +auto mPopupMenu::actionCount() const -> u32 { return state.actions.size(); } @@ -34,7 +34,7 @@ auto mPopupMenu::append(sAction action) -> type& { } auto mPopupMenu::remove(sAction action) -> type& { - signed offset = action->offset(); + s32 offset = action->offset(); signal(remove, action); state.actions.remove(offset); for(auto n : range(offset, actionCount())) { @@ -49,7 +49,7 @@ auto mPopupMenu::reset() -> type& { return *this; } -auto mPopupMenu::setParent(mObject* parent, signed offset) -> type& { +auto mPopupMenu::setParent(mObject* parent, s32 offset) -> type& { for(auto& action : reverse(state.actions)) action->destruct(); mObject::setParent(parent, offset); for(auto& action : state.actions) action->construct(); diff --git a/hiro/core/popup-menu.hpp b/hiro/core/popup-menu.hpp new file mode 100644 index 0000000000..ac6fdfe552 --- /dev/null +++ b/hiro/core/popup-menu.hpp @@ -0,0 +1,22 @@ +#if defined(Hiro_PopupMenu) +struct mPopupMenu : mObject { + Declare(PopupMenu) + using mObject::remove; + + auto action(u32 position) const -> Action; + auto actionCount() const -> u32; + auto actions() const -> vector; + auto append(sAction action) -> type&; + auto remove(sAction action) -> type&; + auto reset() -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setVisible(bool visible = true) -> type& override; + +//private: + struct State { + vector actions; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/position.cpp b/hiro/core/position.cpp index 79c45657dd..75ef97eaab 100644 --- a/hiro/core/position.cpp +++ b/hiro/core/position.cpp @@ -4,7 +4,7 @@ Position::Position() { setPosition(0, 0); } -Position::Position(float x, float y) { +Position::Position(f32 x, f32 y) { setPosition(x, y); } @@ -28,27 +28,27 @@ auto Position::setPosition(Position position) -> type& { return setPosition(position.x(), position.y()); } -auto Position::setPosition(float x, float y) -> type& { +auto Position::setPosition(f32 x, f32 y) -> type& { state.x = x; state.y = y; return *this; } -auto Position::setX(float x) -> type& { +auto Position::setX(f32 x) -> type& { state.x = x; return *this; } -auto Position::setY(float y) -> type& { +auto Position::setY(f32 y) -> type& { state.y = y; return *this; } -auto Position::x() const -> float { +auto Position::x() const -> f32 { return state.x; } -auto Position::y() const -> float { +auto Position::y() const -> f32 { return state.y; } diff --git a/hiro/core/position.hpp b/hiro/core/position.hpp new file mode 100644 index 0000000000..1c8580870c --- /dev/null +++ b/hiro/core/position.hpp @@ -0,0 +1,28 @@ +#if defined(Hiro_Position) +struct Position { + using type = Position; + + Position(); + Position(f32 x, f32 y); + template + Position(X x, Y y) : Position((f32)x, (f32)y) {} + + explicit operator bool() const; + auto operator==(const Position& source) const -> bool; + auto operator!=(const Position& source) const -> bool; + + auto reset() -> type&; + auto setPosition(Position position = {}) -> type&; + auto setPosition(f32 x, f32 y) -> type&; + auto setX(f32 x) -> type&; + auto setY(f32 y) -> type&; + auto x() const -> f32; + auto y() const -> f32; + +//private: + struct State { + f32 x; + f32 y; + } state; +}; +#endif diff --git a/hiro/core/shared.hpp b/hiro/core/shared.hpp index f376b0dd76..4c8bc79210 100644 --- a/hiro/core/shared.hpp +++ b/hiro/core/shared.hpp @@ -95,7 +95,7 @@ struct Group : sGroup { template Group(P&&... p) : Group() { _append(std::forward

(p)...); } auto append(sObject object) -> type& { return self().append(object), *this; } - auto object(unsigned position) const { return self().object(position); } + auto object(u32 position) const { return self().object(position); } auto objectCount() const { return self().objectCount(); } template auto objects() const -> vector { vector objects; @@ -122,7 +122,7 @@ struct Timer : sTimer { auto doActivate() const { return self().doActivate(); } auto interval() const { return self().interval(); } auto onActivate(const function& callback = {}) { return self().onActivate(callback), *this; } - auto setInterval(unsigned interval = 0) { return self().setInterval(interval), *this; } + auto setInterval(u32 interval = 0) { return self().setInterval(interval), *this; } }; #endif @@ -136,7 +136,7 @@ struct Action : sAction { struct Menu : sMenu { DeclareSharedAction(Menu) - auto action(unsigned position) const { return self().action(position); } + auto action(u32 position) const { return self().action(position); } auto actionCount() const { return self().actionCount(); } auto actions() const { return self().actions(); } auto append(sAction action) { return self().append(action), *this; } @@ -293,14 +293,14 @@ struct ComboButton : sComboButton { auto append(sComboButtonItem item) { return self().append(item), *this; } auto doChange() const { return self().doChange(); } - auto item(unsigned position) const { return self().item(position); } + auto item(u32 position) const { return self().item(position); } auto itemCount() const { return self().itemCount(); } auto items() const { return self().items(); } auto onChange(const function& callback = {}) { return self().onChange(callback), *this; } auto remove(sComboButtonItem item) { return self().remove(item), *this; } auto reset() { return self().reset(), *this; } auto selected() const { return self().selected(); } - auto setParent(mObject* parent = nullptr, signed offset = -1) { return self().setParent(parent, offset), *this; } + auto setParent(mObject* parent = nullptr, s32 offset = -1) { return self().setParent(parent, offset), *this; } }; #endif @@ -325,7 +325,7 @@ struct ComboEdit : sComboEdit { auto doChange() const { return self().doChange(); } auto editable() const { return self().editable(); } auto foregroundColor() const { return self().foregroundColor(); } - auto item(uint position) const { return self().item(position); } + auto item(u32 position) const { return self().item(position); } auto itemCount() const { return self().itemCount(); } auto items() const { return self().items(); } auto onActivate(const function& callback = {}) { return self().onActivate(callback), *this; } @@ -377,19 +377,19 @@ struct HexEdit : sHexEdit { auto address() const { return self().address(); } auto backgroundColor() const { return self().backgroundColor(); } auto columns() const { return self().columns(); } - auto doRead(unsigned offset) const { return self().doRead(offset); } - auto doWrite(unsigned offset, uint8_t data) const { return self().doWrite(offset, data); } + auto doRead(u32 offset) const { return self().doRead(offset); } + auto doWrite(u32 offset, u8 data) const { return self().doWrite(offset, data); } auto foregroundColor() const { return self().foregroundColor(); } auto length() const { return self().length(); } - auto onRead(const function& callback = {}) { return self().onRead(callback), *this; } - auto onWrite(const function& callback = {}) { return self().onWrite(callback), *this; } + auto onRead(const function& callback = {}) { return self().onRead(callback), *this; } + auto onWrite(const function& callback = {}) { return self().onWrite(callback), *this; } auto rows() const { return self().rows(); } - auto setAddress(unsigned address) { return self().setAddress(address), *this; } + auto setAddress(u32 address) { return self().setAddress(address), *this; } auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; } - auto setColumns(unsigned columns = 16) { return self().setColumns(columns), *this; } + auto setColumns(u32 columns = 16) { return self().setColumns(columns), *this; } auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; } - auto setLength(unsigned length) { return self().setLength(length), *this; } - auto setRows(unsigned rows = 16) { return self().setRows(rows), *this; } + auto setLength(u32 length) { return self().setLength(length), *this; } + auto setRows(u32 rows = 16) { return self().setRows(rows), *this; } auto update() { return self().update(), *this; } }; #endif @@ -402,8 +402,8 @@ struct HorizontalScrollBar : sHorizontalScrollBar { auto length() const { return self().length(); } auto onChange(const function& callback = {}) { return self().onChange(callback), *this; } auto position() const { return self().position(); } - auto setLength(unsigned length = 101) { return self().setLength(length), *this; } - auto setPosition(unsigned position = 0) { return self().setPosition(position), *this; } + auto setLength(u32 length = 101) { return self().setLength(length), *this; } + auto setPosition(u32 position = 0) { return self().setPosition(position), *this; } }; #endif @@ -415,8 +415,8 @@ struct HorizontalSlider : sHorizontalSlider { auto length() const { return self().length(); } auto onChange(const function& callback = {}) { return self().onChange(callback), *this; } auto position() const { return self().position(); } - auto setLength(unsigned length = 101) { return self().setLength(length), *this; } - auto setPosition(unsigned position = 0) { return self().setPosition(position), *this; } + auto setLength(u32 length = 101) { return self().setLength(length), *this; } + auto setPosition(u32 position = 0) { return self().setPosition(position), *this; } }; #endif @@ -446,7 +446,7 @@ struct IconView : sIconView { auto doContext() const { return self().doContext(); } auto flow() const { return self().flow(); } auto foregroundColor() const { return self().foregroundColor(); } - auto item(unsigned position) const { return self().item(position); } + auto item(u32 position) const { return self().item(position); } auto itemCount() const { return self().itemCount(); } auto items() const { return self().items(); } auto onActivate(const function& callback = {}) { return self().onActivate(callback), *this; } @@ -461,7 +461,7 @@ struct IconView : sIconView { auto setFlow(Orientation orientation = Orientation::Vertical) { return self().setFlow(orientation), *this; } auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; } auto setOrientation(Orientation orientation = Orientation::Horizontal) { return self().setOrientation(orientation), *this; } - auto setSelected(const vector& selections) { return self().setSelected(selections), *this; } + auto setSelected(const vector& selections) { return self().setSelected(selections), *this; } }; #endif @@ -504,7 +504,7 @@ struct ProgressBar : sProgressBar { DeclareSharedWidget(ProgressBar) auto position() const { return self().position(); } - auto setPosition(unsigned position = 0) { return self().setPosition(position), *this; } + auto setPosition(u32 position = 0) { return self().setPosition(position), *this; } }; #endif @@ -596,7 +596,7 @@ struct TabFrame : sTabFrame { auto doChange() const { return self().doChange(); } auto doClose(sTabFrameItem item) const { return self().doClose(item); } auto doMove(sTabFrameItem from, sTabFrameItem to) const { return self().doMove(from, to); } - auto item(unsigned position) const { return self().item(position); } + auto item(u32 position) const { return self().item(position); } auto itemCount() const { return self().itemCount(); } auto items() const { return self().items(); } auto navigation() const { return self().navigation(); } @@ -629,13 +629,13 @@ struct TableViewColumn : sTableViewColumn { auto setEditable(bool editable = true) { return self().setEditable(editable), *this; } auto setExpandable(bool expandable = true) { return self().setExpandable(expandable), *this; } auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; } - auto setHorizontalAlignment(float alignment = 0.0) { return self().setHorizontalAlignment(alignment), *this; } + auto setHorizontalAlignment(f32 alignment = 0.0) { return self().setHorizontalAlignment(alignment), *this; } auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; } auto setResizable(bool resizable = true) { return self().setResizable(resizable), *this; } auto setSorting(Sort sorting = Sort::None) { return self().setSorting(sorting), *this; } auto setText(const string& text = "") { return self().setText(text), *this; } - auto setVerticalAlignment(float alignment = 0.5) { return self().setVerticalAlignment(alignment), *this; } - auto setWidth(float width = 0) { return self().setWidth(width), *this; } + auto setVerticalAlignment(f32 alignment = 0.5) { return self().setVerticalAlignment(alignment), *this; } + auto setWidth(f32 width = 0) { return self().setWidth(width), *this; } auto sort(Sort sorting) { return self().sort(sorting), *this; } auto sorting() const { return self().sorting(); } auto text() const { return self().text(); } @@ -672,7 +672,7 @@ struct TableViewItem : sTableViewItem { auto alignment() const { return self().alignment(); } auto append(sTableViewCell cell) { return self().append(cell), *this; } auto backgroundColor() const { return self().backgroundColor(); } - auto cell(unsigned position) const { return self().cell(position); } + auto cell(u32 position) const { return self().cell(position); } auto cellCount() const { return self().cellCount(); } auto cells() const { return self().cells(); } auto foregroundColor() const { return self().foregroundColor(); } @@ -697,7 +697,7 @@ struct TableView : sTableView { auto batchable() const { return self().batchable(); } auto batched() const { return self().batched(); } auto bordered() const { return self().bordered(); } - auto column(uint position) const { return self().column(position); } + auto column(u32 position) const { return self().column(position); } auto columnCount() const { return self().columnCount(); } auto columns() const { return self().columns(); } auto doActivate(sTableViewCell cell) const { return self().doActivate(cell); } @@ -708,7 +708,7 @@ struct TableView : sTableView { auto doToggle(sTableViewCell cell) const { return self().doToggle(cell); } auto foregroundColor() const { return self().foregroundColor(); } auto headered() const { return self().headered(); } - auto item(unsigned position) const { return self().item(position); } + auto item(u32 position) const { return self().item(position); } auto itemCount() const { return self().itemCount(); } auto items() const { return self().items(); } auto onActivate(const function& callback = {}) { return self().onActivate(callback), *this; } @@ -829,8 +829,8 @@ struct VerticalScrollBar : sVerticalScrollBar { auto length() const { return self().length(); } auto onChange(const function& callback = {}) { return self().onChange(callback), *this; } auto position() const { return self().position(); } - auto setLength(unsigned length = 101) { return self().setLength(length), *this; } - auto setPosition(unsigned position = 0) { return self().setPosition(position), *this; } + auto setLength(u32 length = 101) { return self().setLength(length), *this; } + auto setPosition(u32 position = 0) { return self().setPosition(position), *this; } }; #endif @@ -842,8 +842,8 @@ struct VerticalSlider : sVerticalSlider { auto length() const { return self().length(); } auto onChange(const function& callback = {}) { return self().onChange(callback), *this; } auto position() const { return self().position(); } - auto setLength(unsigned length = 101) { return self().setLength(length), *this; } - auto setPosition(unsigned position = 0) { return self().setPosition(position), *this; } + auto setLength(u32 length = 101) { return self().setLength(length), *this; } + auto setPosition(u32 position = 0) { return self().setPosition(position), *this; } }; #endif @@ -868,7 +868,7 @@ struct StatusBar : sStatusBar { struct PopupMenu : sPopupMenu { DeclareSharedObject(PopupMenu) - auto action(unsigned position) const { return self().action(position); } + auto action(u32 position) const { return self().action(position); } auto actionCount() const { return self().actionCount(); } auto actions() const { return self().actions(); } auto append(sAction action) { return self().append(action), *this; } @@ -882,7 +882,7 @@ struct MenuBar : sMenuBar { DeclareSharedObject(MenuBar) auto append(sMenu menu) { return self().append(menu), *this; } - auto menu(unsigned position) const { return self().menu(position); } + auto menu(u32 position) const { return self().menu(position); } auto menuCount() const { return self().menuCount(); } auto menus() const { return self().menus(); } auto remove(sMenu menu) { return self().remove(menu), *this; } @@ -901,8 +901,8 @@ struct Window : sWindow { auto dismissable() const { return self().dismissable(); } auto doClose() const { return self().doClose(); } auto doDrop(vector names) const { return self().doDrop(names); } - auto doKeyPress(signed key) const { return self().doKeyPress(key); } - auto doKeyRelease(signed key) const { return self().doKeyRelease(key); } + auto doKeyPress(s32 key) const { return self().doKeyPress(key); } + auto doKeyRelease(s32 key) const { return self().doKeyRelease(key); } auto doMove() const { return self().doMove(); } auto doSize() const { return self().doSize(); } auto droppable() const { return self().droppable(); } @@ -919,8 +919,8 @@ struct Window : sWindow { auto monitor() const { return self().monitor(); } auto onClose(const function& callback = {}) { return self().onClose(callback), *this; } auto onDrop(const function)>& callback = {}) { return self().onDrop(callback), *this; } - auto onKeyPress(const function& callback = {}) { return self().onKeyPress(callback), *this; } - auto onKeyRelease(const function& callback = {}) { return self().onKeyRelease(callback), *this; } + auto onKeyPress(const function& callback = {}) { return self().onKeyPress(callback), *this; } + auto onKeyRelease(const function& callback = {}) { return self().onKeyRelease(callback), *this; } auto onMove(const function& callback = {}) { return self().onMove(callback), *this; } auto onSize(const function& callback = {}) { return self().onSize(callback), *this; } auto remove(sMenuBar menuBar) { return self().remove(menuBar), *this; } diff --git a/hiro/core/size.cpp b/hiro/core/size.cpp index 86818d3025..1bb0aed4a8 100644 --- a/hiro/core/size.cpp +++ b/hiro/core/size.cpp @@ -4,7 +4,7 @@ Size::Size() { setSize(0, 0); } -Size::Size(float width, float height) { +Size::Size(f32 width, f32 height) { setSize(width, height); } @@ -20,7 +20,7 @@ auto Size::operator!=(const Size& source) const -> bool { return !operator==(source); } -auto Size::height() const -> float { +auto Size::height() const -> f32 { return state.height; } @@ -28,7 +28,7 @@ auto Size::reset() -> type& { return setSize(0, 0); } -auto Size::setHeight(float height) -> type& { +auto Size::setHeight(f32 height) -> type& { state.height = height; return *this; } @@ -37,18 +37,18 @@ auto Size::setSize(Size size) -> type& { return setSize(size.width(), size.height()); } -auto Size::setSize(float width, float height) -> type& { +auto Size::setSize(f32 width, f32 height) -> type& { state.width = width; state.height = height; return *this; } -auto Size::setWidth(float width) -> type& { +auto Size::setWidth(f32 width) -> type& { state.width = width; return *this; } -auto Size::width() const -> float { +auto Size::width() const -> f32 { return state.width; } diff --git a/hiro/core/size.hpp b/hiro/core/size.hpp new file mode 100644 index 0000000000..4eae403bba --- /dev/null +++ b/hiro/core/size.hpp @@ -0,0 +1,31 @@ +#if defined(Hiro_Size) +struct Size { + using type = Size; + + Size(); + Size(f32 width, f32 height); + template + Size(W width, H height) : Size((f32)width, (f32)height) {} + + explicit operator bool() const; + auto operator==(const Size& source) const -> bool; + auto operator!=(const Size& source) const -> bool; + + auto height() const -> f32; + auto reset() -> type&; + auto setHeight(f32 height) -> type&; + auto setSize(Size source = {}) -> type&; + auto setSize(f32 width, f32 height) -> type&; + auto setWidth(f32 width) -> type&; + auto width() const -> f32; + + static constexpr f32 Maximum = -1.0; + static constexpr f32 Minimum = +0.0; + +//private: + struct State { + f32 width; + f32 height; + } state; +}; +#endif diff --git a/hiro/core/status-bar.hpp b/hiro/core/status-bar.hpp new file mode 100644 index 0000000000..33103a4558 --- /dev/null +++ b/hiro/core/status-bar.hpp @@ -0,0 +1,14 @@ +#if defined(Hiro_StatusBar) +struct mStatusBar : mObject { + Declare(StatusBar) + + auto remove() -> type& override; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + string text; + } state; +}; +#endif diff --git a/hiro/core/text-cursor.cpp b/hiro/core/text-cursor.cpp index cbb935f280..799b715428 100644 --- a/hiro/core/text-cursor.cpp +++ b/hiro/core/text-cursor.cpp @@ -1,6 +1,6 @@ #if defined(Hiro_TextCursor) -TextCursor::TextCursor(int offset, int length) { +TextCursor::TextCursor(s32 offset, s32 length) { setTextCursor(offset, length); } @@ -16,25 +16,25 @@ auto TextCursor::operator!=(const TextCursor& source) const -> bool { return !operator==(source); } -auto TextCursor::length() const -> int { +auto TextCursor::length() const -> s32 { return state.length; } -auto TextCursor::offset() const -> int { +auto TextCursor::offset() const -> s32 { return state.offset; } -auto TextCursor::setLength(int length) -> type& { +auto TextCursor::setLength(s32 length) -> type& { state.length = length; return *this; } -auto TextCursor::setOffset(int offset) -> type& { +auto TextCursor::setOffset(s32 offset) -> type& { state.offset = offset; return *this; } -auto TextCursor::setTextCursor(int offset, int length) -> type& { +auto TextCursor::setTextCursor(s32 offset, s32 length) -> type& { state.offset = offset; state.length = length; return *this; diff --git a/hiro/core/text-cursor.hpp b/hiro/core/text-cursor.hpp index 2f32373bcb..a5991f2adf 100644 --- a/hiro/core/text-cursor.hpp +++ b/hiro/core/text-cursor.hpp @@ -2,22 +2,22 @@ struct TextCursor { using type = TextCursor; - TextCursor(int offset = 0, int length = 0); + TextCursor(s32 offset = 0, s32 length = 0); explicit operator bool() const; auto operator==(const TextCursor& source) const -> bool; auto operator!=(const TextCursor& source) const -> bool; - auto length() const -> int; - auto offset() const -> int; - auto setLength(int length = 0) -> type&; - auto setOffset(int offset = 0) -> type&; - auto setTextCursor(int offset = 0, int length = 0) -> type&; + auto length() const -> s32; + auto offset() const -> s32; + auto setLength(s32 length = 0) -> type&; + auto setOffset(s32 offset = 0) -> type&; + auto setTextCursor(s32 offset = 0, s32 length = 0) -> type&; //private: struct State { - int offset; - int length; + s32 offset; + s32 length; } state; }; #endif diff --git a/hiro/core/timer.cpp b/hiro/core/timer.cpp index c54c82fb8d..3ea47031e4 100644 --- a/hiro/core/timer.cpp +++ b/hiro/core/timer.cpp @@ -14,7 +14,7 @@ auto mTimer::doActivate() const -> void { if(state.onActivate) return state.onActivate(); } -auto mTimer::interval() const -> unsigned { +auto mTimer::interval() const -> u32 { return state.interval; } @@ -23,7 +23,7 @@ auto mTimer::onActivate(const function& callback) -> type& { return *this; } -auto mTimer::setInterval(unsigned interval) -> type& { +auto mTimer::setInterval(u32 interval) -> type& { state.interval = interval; signal(setInterval, interval); return *this; diff --git a/hiro/core/timer.hpp b/hiro/core/timer.hpp index 29c72da4dd..1c1fc4913b 100644 --- a/hiro/core/timer.hpp +++ b/hiro/core/timer.hpp @@ -5,13 +5,13 @@ struct mTimer : mObject { mTimer(); auto doActivate() const -> void; - auto interval() const -> uint; + auto interval() const -> u32; auto onActivate(const function& callback = {}) -> type&; - auto setInterval(uint interval = 0) -> type&; + auto setInterval(u32 interval = 0) -> type&; //private: struct State { - uint interval = 0; + u32 interval = 0; function onActivate; } state; }; diff --git a/hiro/core/widget/button.hpp b/hiro/core/widget/button.hpp new file mode 100644 index 0000000000..ed7e740624 --- /dev/null +++ b/hiro/core/widget/button.hpp @@ -0,0 +1,25 @@ +#if defined(Hiro_Button) +struct mButton : mWidget { + Declare(Button) + + auto bordered() const -> bool; + auto doActivate() const -> void; + auto icon() const -> image; + auto onActivate(const function& callback = {}) -> type&; + auto orientation() const -> Orientation; + auto setBordered(bool bordered = true) -> type&; + auto setIcon(const image& icon = {}) -> type&; + auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool bordered = true; + image icon; + function onActivate; + Orientation orientation = Orientation::Horizontal; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/canvas.cpp b/hiro/core/widget/canvas.cpp index 073b73522e..dd96138024 100644 --- a/hiro/core/widget/canvas.cpp +++ b/hiro/core/widget/canvas.cpp @@ -14,8 +14,8 @@ auto mCanvas::color() const -> Color { return state.color; } -auto mCanvas::data() -> uint32_t* { - return (uint32_t*)state.icon.data(); +auto mCanvas::data() -> u32* { + return (u32*)state.icon.data(); } auto mCanvas::gradient() const -> Gradient { @@ -63,7 +63,7 @@ auto mCanvas::setSize(Size size) -> type& { } auto mCanvas::size() const -> Size { - return {(int)state.icon.width(), (int)state.icon.height()}; + return {(s32)state.icon.width(), (s32)state.icon.height()}; } auto mCanvas::update() -> type& { diff --git a/hiro/core/widget/canvas.hpp b/hiro/core/widget/canvas.hpp index 077b5f1190..542a8eeca0 100644 --- a/hiro/core/widget/canvas.hpp +++ b/hiro/core/widget/canvas.hpp @@ -4,7 +4,7 @@ struct mCanvas : mWidget { auto alignment() const -> Alignment; auto color() const -> Color; - auto data() -> uint32_t*; + auto data() -> u32*; auto gradient() const -> Gradient; auto icon() const -> image; auto setAlignment(Alignment alignment = {}) -> type&; diff --git a/hiro/core/widget/check-button.hpp b/hiro/core/widget/check-button.hpp new file mode 100644 index 0000000000..18bf4533cd --- /dev/null +++ b/hiro/core/widget/check-button.hpp @@ -0,0 +1,28 @@ +#if defined(Hiro_CheckButton) +struct mCheckButton : mWidget { + Declare(CheckButton) + + auto bordered() const -> bool; + auto checked() const -> bool; + auto doToggle() const -> void; + auto icon() const -> image; + auto onToggle(const function& callback = {}) -> type&; + auto orientation() const -> Orientation; + auto setBordered(bool bordered = true) -> type&; + auto setChecked(bool checked = true) -> type&; + auto setIcon(const image& icon = {}) -> type&; + auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool bordered = true; + bool checked = false; + image icon; + function onToggle; + Orientation orientation = Orientation::Horizontal; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/check-label.hpp b/hiro/core/widget/check-label.hpp new file mode 100644 index 0000000000..f4d4969c4c --- /dev/null +++ b/hiro/core/widget/check-label.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_CheckLabel) +struct mCheckLabel : mWidget { + Declare(CheckLabel) + + auto checked() const -> bool; + auto doToggle() const -> void; + auto onToggle(const function& callback = {}) -> type&; + auto setChecked(bool checked = true) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool checked = false; + function onToggle; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/combo-button-item.hpp b/hiro/core/widget/combo-button-item.hpp new file mode 100644 index 0000000000..d4ebeaf887 --- /dev/null +++ b/hiro/core/widget/combo-button-item.hpp @@ -0,0 +1,20 @@ +#if defined(Hiro_ComboButton) +struct mComboButtonItem : mObject { + Declare(ComboButtonItem) + + auto icon() const -> image; + auto remove() -> type& override; + auto selected() const -> bool; + auto setIcon(const image& icon = {}) -> type&; + auto setSelected() -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + image icon; + bool selected = false; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/combo-button.cpp b/hiro/core/widget/combo-button.cpp index ded7fdfb0f..b068d17141 100644 --- a/hiro/core/widget/combo-button.cpp +++ b/hiro/core/widget/combo-button.cpp @@ -23,12 +23,12 @@ auto mComboButton::doChange() const -> void { if(state.onChange) return state.onChange(); } -auto mComboButton::item(uint position) const -> ComboButtonItem { +auto mComboButton::item(u32 position) const -> ComboButtonItem { if(position < itemCount()) return state.items[position]; return {}; } -auto mComboButton::itemCount() const -> uint { +auto mComboButton::itemCount() const -> u32 { return state.items.size(); } @@ -46,7 +46,7 @@ auto mComboButton::onChange(const function& callback) -> type& { auto mComboButton::remove(sComboButtonItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); - for(uint n : range(item->offset(), itemCount())) { + for(u32 n : range(item->offset(), itemCount())) { state.items[n]->adjustOffset(-1); } item->setParent(); @@ -65,7 +65,7 @@ auto mComboButton::selected() const -> ComboButtonItem { return {}; } -auto mComboButton::setParent(mObject* parent, int offset) -> type& { +auto mComboButton::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); mObject::setParent(parent, offset); for(auto& item : state.items) item->setParent(this, item->offset()); diff --git a/hiro/core/widget/combo-button.hpp b/hiro/core/widget/combo-button.hpp new file mode 100644 index 0000000000..5b7a95cb7e --- /dev/null +++ b/hiro/core/widget/combo-button.hpp @@ -0,0 +1,25 @@ +#if defined(Hiro_ComboButton) +struct mComboButton : mWidget { + Declare(ComboButton) + using mObject::remove; + + auto append(sComboButtonItem item) -> type&; + auto doChange() const -> void; + auto item(u32 position) const -> ComboButtonItem; + auto itemCount() const -> u32; + auto items() const -> vector; + auto onChange(const function& callback = {}) -> type&; + auto remove(sComboButtonItem item) -> type&; + auto reset() -> type& override; + auto selected() const -> ComboButtonItem; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + +//private: + struct State { + vector items; + function onChange; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/widget/combo-edit-item.hpp b/hiro/core/widget/combo-edit-item.hpp new file mode 100644 index 0000000000..70e6a7d9e8 --- /dev/null +++ b/hiro/core/widget/combo-edit-item.hpp @@ -0,0 +1,17 @@ +#if defined(Hiro_ComboEdit) +struct mComboEditItem : mObject { + Declare(ComboEditItem) + + auto icon() const -> image; + auto remove() -> type& override; + auto setIcon(const image& icon = {}) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + image icon; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/combo-edit.cpp b/hiro/core/widget/combo-edit.cpp index 374c797583..55b508f07b 100644 --- a/hiro/core/widget/combo-edit.cpp +++ b/hiro/core/widget/combo-edit.cpp @@ -38,12 +38,12 @@ auto mComboEdit::foregroundColor() const -> Color { return state.foregroundColor; } -auto mComboEdit::item(uint position) const -> ComboEditItem { +auto mComboEdit::item(u32 position) const -> ComboEditItem { if(position < itemCount()) return state.items[position]; return {}; } -auto mComboEdit::itemCount() const -> uint { +auto mComboEdit::itemCount() const -> u32 { return state.items.size(); } @@ -98,7 +98,7 @@ auto mComboEdit::setForegroundColor(Color color) -> type& { return *this; } -auto mComboEdit::setParent(mObject* parent, int offset) -> type& { +auto mComboEdit::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : state.items) item->destruct(); mObject::setParent(parent, offset); for(auto& item : state.items) item->setParent(this, item->offset()); diff --git a/hiro/core/widget/combo-edit.hpp b/hiro/core/widget/combo-edit.hpp new file mode 100644 index 0000000000..a2af5c05e4 --- /dev/null +++ b/hiro/core/widget/combo-edit.hpp @@ -0,0 +1,39 @@ +#if defined(Hiro_ComboEdit) +struct mComboEdit : mWidget { + Declare(ComboEdit) + using mObject::remove; + + auto append(sComboEditItem item) -> type&; + auto backgroundColor() const -> Color; + auto doActivate() const -> void; + auto doChange() const -> void; + auto editable() const -> bool; + auto foregroundColor() const -> Color; + auto item(u32 position) const -> ComboEditItem; + auto itemCount() const -> u32; + auto items() const -> vector; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto remove(sComboEditItem item) -> type&; + auto reset() -> type& override; + auto setBackgroundColor(Color color = {}) -> type&; + auto setEditable(bool editable = true) -> type&; + auto setForegroundColor(Color color = {}) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + Color backgroundColor; + bool editable = true; + Color foregroundColor; + vector items; + function onActivate; + function onChange; + string text; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/widget/console.hpp b/hiro/core/widget/console.hpp new file mode 100644 index 0000000000..54c2ef8658 --- /dev/null +++ b/hiro/core/widget/console.hpp @@ -0,0 +1,24 @@ +#if defined(Hiro_Console) +struct mConsole : mWidget { + Declare(Console) + + auto backgroundColor() const -> Color; + auto doActivate(string) const -> void; + auto foregroundColor() const -> Color; + auto onActivate(const function& callback = {}) -> type&; + auto print(const string& text) -> type&; + auto prompt() const -> string; + auto reset() -> type& override; + auto setBackgroundColor(Color color = {}) -> type&; + auto setForegroundColor(Color color = {}) -> type&; + auto setPrompt(const string& prompt = "") -> type&; + +//private: + struct State { + Color backgroundColor; + Color foregroundColor; + function onActivate; + string prompt; + } state; +}; +#endif diff --git a/hiro/core/widget/frame.cpp b/hiro/core/widget/frame.cpp index e2b4558bc4..a3846cc552 100644 --- a/hiro/core/widget/frame.cpp +++ b/hiro/core/widget/frame.cpp @@ -31,7 +31,7 @@ auto mFrame::reset() -> type& { return *this; } -auto mFrame::setParent(mObject* object, int offset) -> type& { +auto mFrame::setParent(mObject* object, s32 offset) -> type& { if(auto& sizable = state.sizable) sizable->destruct(); mObject::setParent(object, offset); if(auto& sizable = state.sizable) sizable->setParent(this, 0); diff --git a/hiro/core/widget/frame.hpp b/hiro/core/widget/frame.hpp new file mode 100644 index 0000000000..0fdedbeb86 --- /dev/null +++ b/hiro/core/widget/frame.hpp @@ -0,0 +1,22 @@ +#if defined(Hiro_Frame) +struct mFrame : mWidget { + Declare(Frame) + using mObject::remove; + + auto append(sSizable sizable) -> type&; + auto remove(sSizable sizable) -> type&; + auto reset() -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setText(const string& text = "") -> type&; + auto sizable() const -> Sizable; + auto text() const -> string; + +//private: + struct State { + sSizable sizable; + string text; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/widget/hex-edit.cpp b/hiro/core/widget/hex-edit.cpp index 986072c0f1..023f6ea323 100644 --- a/hiro/core/widget/hex-edit.cpp +++ b/hiro/core/widget/hex-edit.cpp @@ -6,7 +6,7 @@ auto mHexEdit::allocate() -> pObject* { // -auto mHexEdit::address() const -> unsigned { +auto mHexEdit::address() const -> u32 { return state.address; } @@ -14,16 +14,16 @@ auto mHexEdit::backgroundColor() const -> Color { return state.backgroundColor; } -auto mHexEdit::columns() const -> unsigned { +auto mHexEdit::columns() const -> u32 { return state.columns; } -auto mHexEdit::doRead(unsigned offset) const -> uint8_t { +auto mHexEdit::doRead(u32 offset) const -> u8 { if(state.onRead) return state.onRead(offset); return 0x00; } -auto mHexEdit::doWrite(unsigned offset, uint8_t data) const -> void { +auto mHexEdit::doWrite(u32 offset, u8 data) const -> void { if(state.onWrite) return state.onWrite(offset, data); } @@ -31,25 +31,25 @@ auto mHexEdit::foregroundColor() const -> Color { return state.foregroundColor; } -auto mHexEdit::length() const -> unsigned { +auto mHexEdit::length() const -> u32 { return state.length; } -auto mHexEdit::onRead(const function& callback) -> type& { +auto mHexEdit::onRead(const function& callback) -> type& { state.onRead = callback; return *this; } -auto mHexEdit::onWrite(const function& callback) -> type& { +auto mHexEdit::onWrite(const function& callback) -> type& { state.onWrite = callback; return *this; } -auto mHexEdit::rows() const -> unsigned { +auto mHexEdit::rows() const -> u32 { return state.rows; } -auto mHexEdit::setAddress(unsigned address) -> type& { +auto mHexEdit::setAddress(u32 address) -> type& { state.address = address; signal(setAddress, address); return *this; @@ -61,7 +61,7 @@ auto mHexEdit::setBackgroundColor(Color color) -> type& { return *this; } -auto mHexEdit::setColumns(unsigned columns) -> type& { +auto mHexEdit::setColumns(u32 columns) -> type& { state.columns = columns; signal(setColumns, columns); return *this; @@ -73,13 +73,13 @@ auto mHexEdit::setForegroundColor(Color color) -> type& { return *this; } -auto mHexEdit::setLength(unsigned length) -> type& { +auto mHexEdit::setLength(u32 length) -> type& { state.length = length; signal(setLength, length); return *this; } -auto mHexEdit::setRows(unsigned rows) -> type& { +auto mHexEdit::setRows(u32 rows) -> type& { state.rows = rows; signal(setRows, rows); return *this; diff --git a/hiro/core/widget/hex-edit.hpp b/hiro/core/widget/hex-edit.hpp new file mode 100644 index 0000000000..0f8ce702c8 --- /dev/null +++ b/hiro/core/widget/hex-edit.hpp @@ -0,0 +1,35 @@ +#if defined(Hiro_HexEdit) +struct mHexEdit : mWidget { + Declare(HexEdit) + + auto address() const -> u32; + auto backgroundColor() const -> Color; + auto columns() const -> u32; + auto doRead(u32 offset) const -> u8; + auto doWrite(u32 offset, u8 data) const -> void; + auto foregroundColor() const -> Color; + auto length() const -> u32; + auto onRead(const function& callback = {}) -> type&; + auto onWrite(const function& callback = {}) -> type&; + auto rows() const -> u32; + auto setAddress(u32 address = 0) -> type&; + auto setBackgroundColor(Color color = {}) -> type&; + auto setColumns(u32 columns = 16) -> type&; + auto setForegroundColor(Color color = {}) -> type&; + auto setLength(u32 length) -> type&; + auto setRows(u32 rows = 16) -> type&; + auto update() -> type&; + +//private: + struct State { + u32 address = 0; + Color backgroundColor; + u32 columns = 16; + Color foregroundColor; + u32 length = 0; + function onRead; + function onWrite; + u32 rows = 16; + } state; +}; +#endif diff --git a/hiro/core/widget/horizontal-scroll-bar.cpp b/hiro/core/widget/horizontal-scroll-bar.cpp index 226b1bc614..7532462390 100644 --- a/hiro/core/widget/horizontal-scroll-bar.cpp +++ b/hiro/core/widget/horizontal-scroll-bar.cpp @@ -10,7 +10,7 @@ auto mHorizontalScrollBar::doChange() const -> void { if(state.onChange) return state.onChange(); } -auto mHorizontalScrollBar::length() const -> unsigned { +auto mHorizontalScrollBar::length() const -> u32 { return state.length; } @@ -19,17 +19,17 @@ auto mHorizontalScrollBar::onChange(const function& callback) -> type& return *this; } -auto mHorizontalScrollBar::position() const -> unsigned { +auto mHorizontalScrollBar::position() const -> u32 { return state.position; } -auto mHorizontalScrollBar::setLength(unsigned length) -> type& { +auto mHorizontalScrollBar::setLength(u32 length) -> type& { state.length = length; signal(setLength, length); return *this; } -auto mHorizontalScrollBar::setPosition(unsigned position) -> type& { +auto mHorizontalScrollBar::setPosition(u32 position) -> type& { state.position = position; signal(setPosition, position); return *this; diff --git a/hiro/core/widget/horizontal-scroll-bar.hpp b/hiro/core/widget/horizontal-scroll-bar.hpp new file mode 100644 index 0000000000..5e87534b09 --- /dev/null +++ b/hiro/core/widget/horizontal-scroll-bar.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_HorizontalScrollBar) +struct mHorizontalScrollBar : mWidget { + Declare(HorizontalScrollBar) + + auto doChange() const -> void; + auto length() const -> u32; + auto onChange(const function& callback = {}) -> type&; + auto position() const -> u32; + auto setLength(u32 length = 101) -> type&; + auto setPosition(u32 position = 0) -> type&; + +//private: + struct State { + u32 length = 101; + function onChange; + u32 position = 0; + } state; +}; +#endif diff --git a/hiro/core/widget/horizontal-slider.cpp b/hiro/core/widget/horizontal-slider.cpp index 9330b43b72..801af4136e 100644 --- a/hiro/core/widget/horizontal-slider.cpp +++ b/hiro/core/widget/horizontal-slider.cpp @@ -10,7 +10,7 @@ auto mHorizontalSlider::doChange() const -> void { if(state.onChange) return state.onChange(); } -auto mHorizontalSlider::length() const -> unsigned { +auto mHorizontalSlider::length() const -> u32 { return state.length; } @@ -19,17 +19,17 @@ auto mHorizontalSlider::onChange(const function& callback) -> type& { return *this; } -auto mHorizontalSlider::position() const -> unsigned { +auto mHorizontalSlider::position() const -> u32 { return state.position; } -auto mHorizontalSlider::setLength(unsigned length) -> type& { +auto mHorizontalSlider::setLength(u32 length) -> type& { state.length = length; signal(setLength, length); return *this; } -auto mHorizontalSlider::setPosition(unsigned position) -> type& { +auto mHorizontalSlider::setPosition(u32 position) -> type& { state.position = position; signal(setPosition, position); return *this; diff --git a/hiro/core/widget/horizontal-slider.hpp b/hiro/core/widget/horizontal-slider.hpp new file mode 100644 index 0000000000..b8a34de495 --- /dev/null +++ b/hiro/core/widget/horizontal-slider.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_HorizontalSlider) +struct mHorizontalSlider : mWidget { + Declare(HorizontalSlider) + + auto doChange() const -> void; + auto length() const -> u32; + auto onChange(const function& callback = {}) -> type&; + auto position() const -> u32; + auto setLength(u32 length = 101) -> type&; + auto setPosition(u32 position = 0) -> type&; + +//private: + struct State { + u32 length = 101; + function onChange; + u32 position = 0; + } state; +}; +#endif diff --git a/hiro/core/widget/icon-view-item.hpp b/hiro/core/widget/icon-view-item.hpp new file mode 100644 index 0000000000..48b079545e --- /dev/null +++ b/hiro/core/widget/icon-view-item.hpp @@ -0,0 +1,20 @@ +#if defined(Hiro_IconView) +struct mIconViewItem : mObject { + Declare(IconViewItem) + + auto icon() const -> image; + auto remove() -> type& override; + auto selected() const -> bool; + auto setIcon(const image& icon = {}) -> type&; + auto setSelected(bool selected = true) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + image icon; + bool selected = false; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/icon-view.cpp b/hiro/core/widget/icon-view.cpp index a240e6b3e0..7490d60a53 100644 --- a/hiro/core/widget/icon-view.cpp +++ b/hiro/core/widget/icon-view.cpp @@ -54,12 +54,12 @@ auto mIconView::foregroundColor() const -> Color { return state.foregroundColor; } -auto mIconView::item(unsigned position) const -> IconViewItem { +auto mIconView::item(u32 position) const -> IconViewItem { if(position < itemCount()) return state.items[position]; return {}; } -auto mIconView::itemCount() const -> unsigned { +auto mIconView::itemCount() const -> u32 { return state.items.size(); } @@ -142,14 +142,14 @@ auto mIconView::setOrientation(Orientation orientation) -> type& { return *this; } -auto mIconView::setParent(mObject* parent, signed offset) -> type& { +auto mIconView::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); mObject::setParent(parent, offset); for(auto& item : state.items) item->setParent(this, item->offset()); return *this; } -auto mIconView::setSelected(const vector& selections) -> type& { +auto mIconView::setSelected(const vector& selections) -> type& { bool selectAll = selections(0, 0) == ~0; for(auto& item : state.items) item->state.selected = selectAll; if(selectAll) return signal(setItemSelectedAll), *this; diff --git a/hiro/core/widget/icon-view.hpp b/hiro/core/widget/icon-view.hpp new file mode 100644 index 0000000000..71bd3aeed0 --- /dev/null +++ b/hiro/core/widget/icon-view.hpp @@ -0,0 +1,48 @@ +#if defined(Hiro_IconView) +struct mIconView : mWidget { + Declare(IconView) + using mObject::remove; + + auto append(sIconViewItem item) -> type&; + auto backgroundColor() const -> Color; + auto batchable() const -> bool; + auto batched() const -> vector; + auto doActivate() const -> void; + auto doChange() const -> void; + auto doContext() const -> void; + auto flow() const -> Orientation; + auto foregroundColor() const -> Color; + auto item(u32 position) const -> IconViewItem; + auto itemCount() const -> u32; + auto items() const -> vector; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto onContext(const function& callback = {}) -> type&; + auto orientation() const -> Orientation; + auto remove(sIconViewItem item) -> type&; + auto reset() -> type& override; + auto selected() const -> IconViewItem; + auto setBackgroundColor(Color color = {}) -> type&; + auto setBatchable(bool batchable = true) -> type&; + auto setFlow(Orientation flow = Orientation::Vertical) -> type&; + auto setForegroundColor(Color color = {}) -> type&; + auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; + auto setParent(mObject* object = nullptr, s32 offset = -1) -> type& override; + auto setSelected(const vector& selections) -> type&; + +//private: + struct State { + Color backgroundColor; + bool batchable = false; + Color foregroundColor; + Orientation flow = Orientation::Vertical; + vector items; + function onActivate; + function onChange; + function onContext; + Orientation orientation = Orientation::Horizontal; + } state; + + auto destruct() -> void override; +}; +#endif diff --git a/hiro/core/widget/line-edit.hpp b/hiro/core/widget/line-edit.hpp new file mode 100644 index 0000000000..62c5f31800 --- /dev/null +++ b/hiro/core/widget/line-edit.hpp @@ -0,0 +1,28 @@ +#if defined(Hiro_LineEdit) +struct mLineEdit : mWidget { + Declare(LineEdit) + + auto backgroundColor() const -> Color; + auto doActivate() const -> void; + auto doChange() const -> void; + auto editable() const -> bool; + auto foregroundColor() const -> Color; + auto onActivate(const function& callback = {}) -> type&; + auto onChange(const function& callback = {}) -> type&; + auto setBackgroundColor(Color color = {}) -> type&; + auto setEditable(bool editable = true) -> type&; + auto setForegroundColor(Color color = {}) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + Color backgroundColor; + bool editable = true; + Color foregroundColor; + function onActivate; + function onChange; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/progress-bar.cpp b/hiro/core/widget/progress-bar.cpp index d55b203aba..38cb98fa05 100644 --- a/hiro/core/widget/progress-bar.cpp +++ b/hiro/core/widget/progress-bar.cpp @@ -6,11 +6,11 @@ auto mProgressBar::allocate() -> pObject* { // -auto mProgressBar::position() const -> unsigned { +auto mProgressBar::position() const -> u32 { return state.position; } -auto mProgressBar::setPosition(unsigned position) -> type& { +auto mProgressBar::setPosition(u32 position) -> type& { state.position = position; signal(setPosition, position); return *this; diff --git a/hiro/core/widget/progress-bar.hpp b/hiro/core/widget/progress-bar.hpp new file mode 100644 index 0000000000..8e652bddb4 --- /dev/null +++ b/hiro/core/widget/progress-bar.hpp @@ -0,0 +1,13 @@ +#if defined(Hiro_ProgressBar) +struct mProgressBar : mWidget { + Declare(ProgressBar) + + auto position() const -> u32; + auto setPosition(u32 position) -> type&; + +//private: + struct State { + u32 position = 0; + } state; +}; +#endif diff --git a/hiro/core/widget/radio-button.hpp b/hiro/core/widget/radio-button.hpp new file mode 100644 index 0000000000..dd8bc3a158 --- /dev/null +++ b/hiro/core/widget/radio-button.hpp @@ -0,0 +1,31 @@ +#if defined(Hiro_RadioButton) +struct mRadioButton : mWidget { + Declare(RadioButton) + + auto bordered() const -> bool; + auto checked() const -> bool; + auto doActivate() const -> void; + auto group() const -> Group override; + auto icon() const -> image; + auto onActivate(const function& callback = {}) -> type&; + auto orientation() const -> Orientation; + auto setBordered(bool bordered = true) -> type&; + auto setChecked() -> type&; + auto setGroup(sGroup group = {}) -> type& override; + auto setIcon(const image& icon = {}) -> type&; + auto setOrientation(Orientation orientation = Orientation::Horizontal) -> type&; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool bordered = true; + bool checked = false; + sGroup group; + image icon; + function onActivate; + Orientation orientation = Orientation::Horizontal; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/radio-label.hpp b/hiro/core/widget/radio-label.hpp new file mode 100644 index 0000000000..e3bc15dc17 --- /dev/null +++ b/hiro/core/widget/radio-label.hpp @@ -0,0 +1,22 @@ +#if defined(Hiro_RadioLabel) +struct mRadioLabel : mWidget { + Declare(RadioLabel) + + auto checked() const -> bool; + auto doActivate() const -> void; + auto group() const -> Group override; + auto onActivate(const function& callback = {}) -> type&; + auto setChecked() -> type&; + auto setGroup(sGroup group = {}) -> type& override; + auto setText(const string& text = "") -> type&; + auto text() const -> string; + +//private: + struct State { + bool checked = false; + sGroup group; + function onActivate; + string text; + } state; +}; +#endif diff --git a/hiro/core/widget/tab-frame-item.cpp b/hiro/core/widget/tab-frame-item.cpp index 2156685809..60fbfedace 100644 --- a/hiro/core/widget/tab-frame-item.cpp +++ b/hiro/core/widget/tab-frame-item.cpp @@ -82,7 +82,7 @@ auto mTabFrameItem::setMovable(bool movable) -> type& { return *this; } -auto mTabFrameItem::setParent(mObject* parent, int offset) -> type& { +auto mTabFrameItem::setParent(mObject* parent, s32 offset) -> type& { if(auto& sizable = state.sizable) sizable->destruct(); mObject::setParent(parent, offset); if(auto& sizable = state.sizable) sizable->setParent(this, sizable->offset()); diff --git a/hiro/core/widget/tab-frame-item.hpp b/hiro/core/widget/tab-frame-item.hpp index b59d9dc125..d3345c6233 100644 --- a/hiro/core/widget/tab-frame-item.hpp +++ b/hiro/core/widget/tab-frame-item.hpp @@ -8,14 +8,14 @@ struct mTabFrameItem : mObject { auto movable() const -> bool; auto remove() -> type& override; auto remove(sSizable sizable) -> type&; - auto reset() -> type&; + auto reset() -> type& override; auto selected() const -> bool; auto setClosable(bool closable = true) -> type&; auto setEnabled(bool enabled = true) -> type& override; auto setFont(const Font& font = {}) -> type& override; auto setIcon(const image& icon = {}) -> type&; auto setMovable(bool movable = true) -> type&; - auto setParent(mObject* object = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* object = nullptr, s32 offset = -1) -> type& override; auto setSelected() -> type&; auto setText(const string& text = "") -> type&; auto setVisible(bool visible = true) -> type& override; diff --git a/hiro/core/widget/tab-frame.cpp b/hiro/core/widget/tab-frame.cpp index 59170a1ae3..b356ea4993 100644 --- a/hiro/core/widget/tab-frame.cpp +++ b/hiro/core/widget/tab-frame.cpp @@ -105,7 +105,7 @@ auto mTabFrame::setNavigation(Navigation navigation) -> type& { return *this; } -auto mTabFrame::setParent(mObject* parent, int offset) -> type& { +auto mTabFrame::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); mObject::setParent(parent, offset); for(auto& item : state.items) item->setParent(this, item->offset()); diff --git a/hiro/core/widget/tab-frame.hpp b/hiro/core/widget/tab-frame.hpp index b6e7c92abf..2b3e8d7aa0 100644 --- a/hiro/core/widget/tab-frame.hpp +++ b/hiro/core/widget/tab-frame.hpp @@ -16,12 +16,12 @@ struct mTabFrame : mWidget { auto onClose(const function& callback = {}) -> type&; auto onMove(const function& callback = {}) -> type&; auto remove(sTabFrameItem item) -> type&; - auto reset() -> type&; + auto reset() -> type& override; auto selected() const -> TabFrameItem; auto setEnabled(bool enabled = true) -> type& override; auto setFont(const Font& font = {}) -> type& override; auto setNavigation(Navigation navigation = Navigation::Top) -> type&; - auto setParent(mObject* object = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* object = nullptr, s32 offset = -1) -> type& override; auto setVisible(bool visible = true) -> type& override; //private: diff --git a/hiro/core/widget/table-view-column.cpp b/hiro/core/widget/table-view-column.cpp index 6e8c02828f..c4f7bc1408 100644 --- a/hiro/core/widget/table-view-column.cpp +++ b/hiro/core/widget/table-view-column.cpp @@ -33,7 +33,7 @@ auto mTableViewColumn::foregroundColor() const -> Color { return state.foregroundColor; } -auto mTableViewColumn::horizontalAlignment() const -> float { +auto mTableViewColumn::horizontalAlignment() const -> f32 { return state.horizontalAlignment; } @@ -86,7 +86,7 @@ auto mTableViewColumn::setForegroundColor(Color color) -> type& { return *this; } -auto mTableViewColumn::setHorizontalAlignment(float alignment) -> type& { +auto mTableViewColumn::setHorizontalAlignment(f32 alignment) -> type& { alignment = max(0.0, min(1.0, alignment)); state.horizontalAlignment = alignment; signal(setHorizontalAlignment, alignment); @@ -123,7 +123,7 @@ auto mTableViewColumn::setText(const string& text) -> type& { return *this; } -auto mTableViewColumn::setVerticalAlignment(float alignment) -> type& { +auto mTableViewColumn::setVerticalAlignment(f32 alignment) -> type& { alignment = max(0.0, min(1.0, alignment)); state.verticalAlignment = alignment; signal(setVerticalAlignment, alignment); @@ -136,7 +136,7 @@ auto mTableViewColumn::setVisible(bool visible) -> type& { return *this; } -auto mTableViewColumn::setWidth(float width) -> type& { +auto mTableViewColumn::setWidth(f32 width) -> type& { state.width = max(0, width); signal(setWidth, width); return *this; @@ -150,11 +150,11 @@ auto mTableViewColumn::text() const -> string { return state.text; } -auto mTableViewColumn::verticalAlignment() const -> float { +auto mTableViewColumn::verticalAlignment() const -> f32 { return state.verticalAlignment; } -auto mTableViewColumn::width() const -> float { +auto mTableViewColumn::width() const -> f32 { return state.width; } diff --git a/hiro/core/widget/table-view-column.hpp b/hiro/core/widget/table-view-column.hpp index 2c1ddf82c2..26b87b1587 100644 --- a/hiro/core/widget/table-view-column.hpp +++ b/hiro/core/widget/table-view-column.hpp @@ -8,7 +8,7 @@ struct mTableViewColumn : mObject { auto editable() const -> bool; auto expandable() const -> bool; auto foregroundColor() const -> Color; - auto horizontalAlignment() const -> float; + auto horizontalAlignment() const -> f32; auto icon() const -> image; auto remove() -> type& override; auto resizable() const -> bool; @@ -18,19 +18,19 @@ struct mTableViewColumn : mObject { auto setEditable(bool editable = true) -> type&; auto setExpandable(bool expandable = true) -> type&; auto setForegroundColor(Color color = {}) -> type&; - auto setHorizontalAlignment(float alignment = 0.0) -> type&; + auto setHorizontalAlignment(f32 alignment = 0.0) -> type&; auto setIcon(const image& icon = {}) -> type&; auto setResizable(bool resizable = true) -> type&; auto setSorting(Sort sorting = Sort::None) -> type&; auto setText(const string& text = "") -> type&; - auto setVerticalAlignment(float alignment = 0.5) -> type&; - auto setVisible(bool visible = true) -> type&; - auto setWidth(float width = 0) -> type&; + auto setVerticalAlignment(f32 alignment = 0.5) -> type&; + auto setVisible(bool visible = true) -> type& override; + auto setWidth(f32 width = 0) -> type&; auto sort(Sort sorting) -> type&; auto sorting() const -> Sort; auto text() const -> string; - auto verticalAlignment() const -> float; - auto width() const -> float; + auto verticalAlignment() const -> f32; + auto width() const -> f32; //private: struct State { @@ -40,14 +40,14 @@ struct mTableViewColumn : mObject { bool editable = false; bool expandable = false; Color foregroundColor; - float horizontalAlignment = 0.0; + f32 horizontalAlignment = 0.0; image icon; bool resizable = true; Sort sorting = Sort::None; string text; - float verticalAlignment = 0.5; + f32 verticalAlignment = 0.5; bool visible = true; - float width = 0; + f32 width = 0; } state; }; #endif diff --git a/hiro/core/widget/table-view-item.cpp b/hiro/core/widget/table-view-item.cpp index 9d55e0b44a..dfbc4311d6 100644 --- a/hiro/core/widget/table-view-item.cpp +++ b/hiro/core/widget/table-view-item.cpp @@ -26,12 +26,12 @@ auto mTableViewItem::backgroundColor() const -> Color { return state.backgroundColor; } -auto mTableViewItem::cell(unsigned position) const -> TableViewCell { +auto mTableViewItem::cell(u32 position) const -> TableViewCell { if(position < cellCount()) return state.cells[position]; return {}; } -auto mTableViewItem::cellCount() const -> unsigned { +auto mTableViewItem::cellCount() const -> u32 { return state.cells.size(); } @@ -92,7 +92,7 @@ auto mTableViewItem::setForegroundColor(Color color) -> type& { return *this; } -auto mTableViewItem::setParent(mObject* parent, signed offset) -> type& { +auto mTableViewItem::setParent(mObject* parent, s32 offset) -> type& { for(auto& cell : state.cells) cell->destruct(); mObject::setParent(parent, offset); for(auto& cell : state.cells) cell->setParent(this, cell->offset()); diff --git a/hiro/core/widget/table-view-item.hpp b/hiro/core/widget/table-view-item.hpp index aac43fc55e..6332aa2588 100644 --- a/hiro/core/widget/table-view-item.hpp +++ b/hiro/core/widget/table-view-item.hpp @@ -5,19 +5,19 @@ struct mTableViewItem : mObject { auto alignment() const -> Alignment; auto append(sTableViewCell cell) -> type&; auto backgroundColor() const -> Color; - auto cell(uint position) const -> TableViewCell; - auto cellCount() const -> uint; + auto cell(u32 position) const -> TableViewCell; + auto cellCount() const -> u32; auto cells() const -> vector; auto foregroundColor() const -> Color; auto remove() -> type& override; auto remove(sTableViewCell cell) -> type&; - auto reset() -> type&; + auto reset() -> type& override; auto selected() const -> bool; auto setAlignment(Alignment alignment = {}) -> type&; auto setBackgroundColor(Color color = {}) -> type&; auto setFocused() -> type& override; auto setForegroundColor(Color color = {}) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSelected(bool selected = true) -> type&; //private: diff --git a/hiro/core/widget/table-view.cpp b/hiro/core/widget/table-view.cpp index 5ec96bb777..544a291a19 100644 --- a/hiro/core/widget/table-view.cpp +++ b/hiro/core/widget/table-view.cpp @@ -50,12 +50,12 @@ auto mTableView::bordered() const -> bool { return state.bordered; } -auto mTableView::column(uint position) const -> TableViewColumn { +auto mTableView::column(u32 position) const -> TableViewColumn { if(position < columnCount()) return state.columns[position]; return {}; } -auto mTableView::columnCount() const -> uint { +auto mTableView::columnCount() const -> u32 { return state.columns.size(); } @@ -97,12 +97,12 @@ auto mTableView::headered() const -> bool { return state.headered; } -auto mTableView::item(unsigned position) const -> TableViewItem { +auto mTableView::item(u32 position) const -> TableViewItem { if(position < itemCount()) return state.items[position]; return {}; } -auto mTableView::itemCount() const -> unsigned { +auto mTableView::itemCount() const -> u32 { return state.items.size(); } @@ -145,7 +145,7 @@ auto mTableView::onToggle(const function& callback) -> typ auto mTableView::remove(sTableViewColumn column) -> type& { signal(remove, column); state.columns.remove(column->offset()); - for(uint n : range(column->offset(), columnCount())) { + for(u32 n : range(column->offset(), columnCount())) { state.columns[n]->adjustOffset(-1); } column->setParent(); @@ -155,7 +155,7 @@ auto mTableView::remove(sTableViewColumn column) -> type& { auto mTableView::remove(sTableViewItem item) -> type& { signal(remove, item); state.items.remove(item->offset()); - for(uint n : range(item->offset(), itemCount())) { + for(u32 n : range(item->offset(), itemCount())) { state.items[n]->adjustOffset(-1); } item->setParent(); @@ -231,7 +231,7 @@ auto mTableView::setHeadered(bool headered) -> type& { return *this; } -auto mTableView::setParent(mObject* parent, signed offset) -> type& { +auto mTableView::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); for(auto& column : reverse(state.columns)) column->destruct(); mObject::setParent(parent, offset); @@ -248,7 +248,7 @@ auto mTableView::setSortable(bool sortable) -> type& { auto mTableView::sort() -> type& { Sort sorting = Sort::None; - uint offset = 0; + u32 offset = 0; for(auto& column : state.columns) { if(column->sorting() == Sort::None) continue; sorting = column->sorting(); diff --git a/hiro/core/widget/table-view.hpp b/hiro/core/widget/table-view.hpp index 5ce03981cb..a7a3441249 100644 --- a/hiro/core/widget/table-view.hpp +++ b/hiro/core/widget/table-view.hpp @@ -10,8 +10,8 @@ struct mTableView : mWidget { auto batchable() const -> bool; auto batched() const -> vector; auto bordered() const -> bool; - auto column(uint position) const -> TableViewColumn; - auto columnCount() const -> uint; + auto column(u32 position) const -> TableViewColumn; + auto columnCount() const -> u32; auto columns() const -> vector; auto doActivate(sTableViewCell cell) const -> void; auto doChange() const -> void; @@ -21,8 +21,8 @@ struct mTableView : mWidget { auto doToggle(sTableViewCell cell) const -> void; auto foregroundColor() const -> Color; auto headered() const -> bool; - auto item(uint position) const -> TableViewItem; - auto itemCount() const -> uint; + auto item(u32 position) const -> TableViewItem; + auto itemCount() const -> u32; auto items() const -> vector; auto onActivate(const function& callback = {}) -> type&; auto onChange(const function& callback = {}) -> type&; @@ -32,7 +32,7 @@ struct mTableView : mWidget { auto onToggle(const function& callback = {}) -> type&; auto remove(sTableViewColumn column) -> type&; auto remove(sTableViewItem item) -> type&; - auto reset() -> type&; + auto reset() -> type& override; auto resizeColumns() -> type&; auto selectAll() -> type&; auto selectNone() -> type&; @@ -43,14 +43,14 @@ struct mTableView : mWidget { auto setBordered(bool bordered = true) -> type&; auto setForegroundColor(Color color = {}) -> type&; auto setHeadered(bool headered = true) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSortable(bool sortable = true) -> type&; auto sort() -> type&; auto sortable() const -> bool; //private: struct State { - uint activeColumn = 0; + u32 activeColumn = 0; Alignment alignment; Color backgroundColor; bool batchable = false; diff --git a/hiro/core/widget/tree-view-item.cpp b/hiro/core/widget/tree-view-item.cpp index 181cefba85..b1d057d453 100644 --- a/hiro/core/widget/tree-view-item.cpp +++ b/hiro/core/widget/tree-view-item.cpp @@ -75,13 +75,13 @@ auto mTreeViewItem::icon() const -> image { auto mTreeViewItem::item(const string& path) const -> TreeViewItem { if(!path) return {}; auto paths = path.split("/"); - unsigned position = paths.takeLeft().natural(); + u32 position = paths.takeLeft().natural(); if(position >= itemCount()) return {}; if(!paths) return state.items[position]; return state.items[position]->item(paths.merge("/")); } -auto mTreeViewItem::itemCount() const -> unsigned { +auto mTreeViewItem::itemCount() const -> u32 { return state.items.size(); } @@ -160,7 +160,7 @@ auto mTreeViewItem::setIcon(const image& icon) -> type& { return *this; } -auto mTreeViewItem::setParent(mObject* parent, signed offset) -> type& { +auto mTreeViewItem::setParent(mObject* parent, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); mObject::setParent(parent, offset); for(auto& item : state.items) item->setParent(this, item->offset()); diff --git a/hiro/core/widget/tree-view-item.hpp b/hiro/core/widget/tree-view-item.hpp index 40156bd3ec..de805840d2 100644 --- a/hiro/core/widget/tree-view-item.hpp +++ b/hiro/core/widget/tree-view-item.hpp @@ -12,7 +12,7 @@ struct mTreeViewItem : mObject { auto foregroundColor(bool recursive = false) const -> Color; auto icon() const -> image; auto item(const string& path) const -> TreeViewItem; - auto itemCount() const -> uint; + auto itemCount() const -> u32; auto items() const -> vector; auto path() const -> string; auto remove() -> type& override; @@ -25,7 +25,7 @@ struct mTreeViewItem : mObject { auto setFocused() -> type& override; auto setForegroundColor(Color color = {}) -> type&; auto setIcon(const image& icon = {}) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSelected() -> type&; auto setText(const string& text = "") -> type&; auto text() const -> string; diff --git a/hiro/core/widget/tree-view.cpp b/hiro/core/widget/tree-view.cpp index 07ae5ab523..6c87aa42bc 100644 --- a/hiro/core/widget/tree-view.cpp +++ b/hiro/core/widget/tree-view.cpp @@ -59,13 +59,13 @@ auto mTreeView::foregroundColor() const -> Color { auto mTreeView::item(const string& path) const -> TreeViewItem { if(!path) return {}; auto paths = path.split("/"); - unsigned position = paths.takeLeft().natural(); + u32 position = paths.takeLeft().natural(); if(position >= itemCount()) return {}; if(!paths) return state.items[position]; return state.items[position]->item(paths.merge("/")); } -auto mTreeView::itemCount() const -> unsigned { +auto mTreeView::itemCount() const -> u32 { return state.items.size(); } @@ -141,7 +141,7 @@ auto mTreeView::setForegroundColor(Color color) -> type& { return *this; } -auto mTreeView::setParent(mObject* object, signed offset) -> type& { +auto mTreeView::setParent(mObject* object, s32 offset) -> type& { for(auto& item : reverse(state.items)) item->destruct(); mObject::setParent(object, offset); for(auto& item : state.items) item->setParent(this, item->offset()); diff --git a/hiro/core/widget/tree-view.hpp b/hiro/core/widget/tree-view.hpp index 782f8db770..a0d141306a 100644 --- a/hiro/core/widget/tree-view.hpp +++ b/hiro/core/widget/tree-view.hpp @@ -14,20 +14,20 @@ struct mTreeView : mWidget { auto expand(bool recursive = true) -> type&; auto foregroundColor() const -> Color; auto item(const string& path) const -> TreeViewItem; - auto itemCount() const -> uint; + auto itemCount() const -> u32; auto items() const -> vector; auto onActivate(const function& callback = {}) -> type&; auto onChange(const function& callback = {}) -> type&; auto onContext(const function& callback = {}) -> type&; auto onToggle(const function& callback = {}) -> type&; auto remove(sTreeViewItem item) -> type&; - auto reset() -> type&; + auto reset() -> type& override; auto selectNone() -> type&; auto selected() const -> TreeViewItem; auto setActivation(Mouse::Click activation = Mouse::Click::Double) -> type&; auto setBackgroundColor(Color color = {}) -> type&; auto setForegroundColor(Color color = {}) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; //private: struct State { diff --git a/hiro/core/widget/vertical-scroll-bar.cpp b/hiro/core/widget/vertical-scroll-bar.cpp index d32409bb68..9d42eeea38 100644 --- a/hiro/core/widget/vertical-scroll-bar.cpp +++ b/hiro/core/widget/vertical-scroll-bar.cpp @@ -10,7 +10,7 @@ auto mVerticalScrollBar::doChange() const -> void { if(state.onChange) return state.onChange(); } -auto mVerticalScrollBar::length() const -> unsigned { +auto mVerticalScrollBar::length() const -> u32 { return state.length; } @@ -19,17 +19,17 @@ auto mVerticalScrollBar::onChange(const function& callback) -> type& { return *this; } -auto mVerticalScrollBar::position() const -> unsigned { +auto mVerticalScrollBar::position() const -> u32 { return state.position; } -auto mVerticalScrollBar::setLength(unsigned length) -> type& { +auto mVerticalScrollBar::setLength(u32 length) -> type& { state.length = length; signal(setLength, length); return *this; } -auto mVerticalScrollBar::setPosition(unsigned position) -> type& { +auto mVerticalScrollBar::setPosition(u32 position) -> type& { state.position = position; signal(setPosition, position); return *this; diff --git a/hiro/core/widget/vertical-scroll-bar.hpp b/hiro/core/widget/vertical-scroll-bar.hpp new file mode 100644 index 0000000000..477fdde40f --- /dev/null +++ b/hiro/core/widget/vertical-scroll-bar.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_VerticalScrollBar) +struct mVerticalScrollBar : mWidget { + Declare(VerticalScrollBar) + + auto doChange() const -> void; + auto length() const -> u32; + auto onChange(const function& callback = {}) -> type&; + auto position() const -> u32; + auto setLength(u32 length = 101) -> type&; + auto setPosition(u32 position = 0) -> type&; + +//private: + struct State { + u32 length = 101; + function onChange; + u32 position = 0; + } state; +}; +#endif diff --git a/hiro/core/widget/vertical-slider.cpp b/hiro/core/widget/vertical-slider.cpp index 7517f236c6..0a2377e357 100644 --- a/hiro/core/widget/vertical-slider.cpp +++ b/hiro/core/widget/vertical-slider.cpp @@ -10,7 +10,7 @@ auto mVerticalSlider::doChange() const -> void { if(state.onChange) return state.onChange(); } -auto mVerticalSlider::length() const -> unsigned { +auto mVerticalSlider::length() const -> u32 { return state.length; } @@ -19,17 +19,17 @@ auto mVerticalSlider::onChange(const function& callback) -> type& { return *this; } -auto mVerticalSlider::position() const -> unsigned { +auto mVerticalSlider::position() const -> u32 { return state.position; } -auto mVerticalSlider::setLength(unsigned length) -> type& { +auto mVerticalSlider::setLength(u32 length) -> type& { state.length = length; signal(setLength, length); return *this; } -auto mVerticalSlider::setPosition(unsigned position) -> type& { +auto mVerticalSlider::setPosition(u32 position) -> type& { state.position = position; signal(setPosition, position); return *this; diff --git a/hiro/core/widget/vertical-slider.hpp b/hiro/core/widget/vertical-slider.hpp new file mode 100644 index 0000000000..3265a940b6 --- /dev/null +++ b/hiro/core/widget/vertical-slider.hpp @@ -0,0 +1,19 @@ +#if defined(Hiro_VerticalSlider) +struct mVerticalSlider : mWidget { + Declare(VerticalSlider) + + auto doChange() const -> void; + auto length() const -> u32; + auto onChange(const function& callback = {}) -> type&; + auto position() const -> u32; + auto setLength(u32 length = 101) -> type&; + auto setPosition(u32 position = 0) -> type&; + +//private: + struct State { + u32 length = 101; + function onChange; + u32 position = 0; + } state; +}; +#endif diff --git a/hiro/core/window.cpp b/hiro/core/window.cpp index 7e37ab3d16..8bfecbb728 100644 --- a/hiro/core/window.cpp +++ b/hiro/core/window.cpp @@ -57,11 +57,11 @@ auto mWindow::doDrop(vector names) const -> void { if(state.onDrop) return state.onDrop(names); } -auto mWindow::doKeyPress(signed key) const -> void { +auto mWindow::doKeyPress(s32 key) const -> void { if(state.onKeyPress) return state.onKeyPress(key); } -auto mWindow::doKeyRelease(signed key) const -> void { +auto mWindow::doKeyRelease(s32 key) const -> void { if(state.onKeyRelease) return state.onKeyRelease(key); } @@ -121,7 +121,7 @@ auto mWindow::modal() const -> bool { return state.modal; } -auto mWindow::monitor() const -> uint { +auto mWindow::monitor() const -> u32 { return signal(monitor); } @@ -135,12 +135,12 @@ auto mWindow::onDrop(const function)>& callback) -> type& { return *this; } -auto mWindow::onKeyPress(const function& callback) -> type& { +auto mWindow::onKeyPress(const function& callback) -> type& { state.onKeyPress = callback; return *this; } -auto mWindow::onKeyRelease(const function& callback) -> type& { +auto mWindow::onKeyRelease(const function& callback) -> type& { state.onKeyRelease = callback; return *this; } @@ -192,7 +192,7 @@ auto mWindow::setAlignment(Alignment alignment) -> type& { auto geometry = frameGeometry(); auto x = workspace.x() + alignment.horizontal() * (workspace.width() - geometry.width()); auto y = workspace.y() + alignment.vertical() * (workspace.height() - geometry.height()); - setFramePosition({(int)x, (int)y}); + setFramePosition({(s32)x, (s32)y}); return *this; } @@ -211,7 +211,7 @@ auto mWindow::setAlignment(sWindow relativeTo, Alignment alignment) -> type& { if(signbit(alignment.vertical())) { y = (parent.y() - window.height()) + abs(alignment.vertical()) * (parent.height() + window.height()); } - setFramePosition({(int)x, (int)y}); + setFramePosition({(s32)x, (s32)y}); return *this; } @@ -286,7 +286,7 @@ auto mWindow::setGeometry(Alignment alignment, Size size) -> type& { auto workspace = Monitor::workspace(); auto x = workspace.x() + alignment.horizontal() * (workspace.width() - width); auto y = workspace.y() + alignment.vertical() * (workspace.height() - height); - setFrameGeometry({(int)x, (int)y, (int)width, (int)height}); + setFrameGeometry({(s32)x, (s32)y, (s32)width, (s32)height}); return *this; } diff --git a/hiro/core/window.hpp b/hiro/core/window.hpp index 07b6e4c19b..ed60ebf649 100644 --- a/hiro/core/window.hpp +++ b/hiro/core/window.hpp @@ -12,8 +12,8 @@ struct mWindow : mObject { auto dismissable() const -> bool; auto doClose() const -> void; auto doDrop(vector) const -> void; - auto doKeyPress(int) const -> void; - auto doKeyRelease(int) const -> void; + auto doKeyPress(s32) const -> void; + auto doKeyRelease(s32) const -> void; auto doMove() const -> void; auto doSize() const -> void; auto droppable() const -> bool; @@ -27,11 +27,11 @@ struct mWindow : mObject { auto minimized() const -> bool; auto minimumSize() const -> Size; auto modal() const -> bool; - auto monitor() const -> uint; + auto monitor() const -> u32; auto onClose(const function& callback = {}) -> type&; auto onDrop(const function)>& callback = {}) -> type&; - auto onKeyPress(const function& callback = {}) -> type&; - auto onKeyRelease(const function& callback = {}) -> type&; + auto onKeyPress(const function& callback = {}) -> type&; + auto onKeyRelease(const function& callback = {}) -> type&; auto onMove(const function& callback = {}) -> type&; auto onSize(const function& callback = {}) -> type&; auto remove(sMenuBar menuBar) -> type&; @@ -60,7 +60,7 @@ struct mWindow : mObject { auto setResizable(bool resizable = true) -> type&; auto setSize(Size size) -> type&; auto setTitle(const string& title = "") -> type&; - auto setVisible(bool visible = true) -> type&; + auto setVisible(bool visible = true) -> type& override; auto sizable() const -> Sizable; auto statusBar() const -> StatusBar; auto title() const -> string; @@ -80,8 +80,8 @@ struct mWindow : mObject { bool modal = false; function onClose; function)> onDrop; - function onKeyPress; - function onKeyRelease; + function onKeyPress; + function onKeyRelease; function onMove; function onSize; bool resizable = true; @@ -90,6 +90,6 @@ struct mWindow : mObject { string title; } state; - auto destruct() -> void; + auto destruct() -> void override; }; #endif diff --git a/hiro/extension/about-dialog.cpp b/hiro/extension/about-dialog.cpp index 0021f5c78d..e5a8f293f7 100644 --- a/hiro/extension/about-dialog.cpp +++ b/hiro/extension/about-dialog.cpp @@ -12,8 +12,9 @@ auto AboutDialog::setAlignment(sWindow relativeTo, Alignment alignment) -> type& return *this; } -auto AboutDialog::setCopyright(const string& copyright) -> type& { +auto AboutDialog::setCopyright(const string& copyright, const string& uri) -> type& { state.copyright = copyright; + state.copyrightURI = uri; return *this; } @@ -104,11 +105,19 @@ auto AboutDialog::show() -> void { copyrightLabel.setFont(Font().setBold()); copyrightLabel.setForegroundColor({0, 0, 0}); copyrightLabel.setText("Copyright:"); - Label copyrightValue{©rightLayout, Size{~0, 0}}; + HorizontalLayout copyrightValueLayout{©rightLayout, Size{~0, 0}}; + Label copyrightValue{©rightValueLayout, Size{~0, 0}}; copyrightValue.setAlignment(0.0); copyrightValue.setFont(Font().setBold()); copyrightValue.setForegroundColor({0, 0, 0}); copyrightValue.setText(state.copyright); + if(state.copyrightURI) { + copyrightValue.setForegroundColor({0, 0, 240}); + copyrightValue.setMouseCursor(MouseCursor::Hand); + copyrightValue.onMouseRelease([&](auto button) { + if(button == Mouse::Button::Left) invoke(state.copyrightURI); + }); + } if(!state.copyright) copyrightLayout.setVisible(false); HorizontalLayout licenseLayout{&layout, Size{~0, 0}, 0}; diff --git a/hiro/extension/about-dialog.hpp b/hiro/extension/about-dialog.hpp index 9d9a927ca2..24e6e24e5c 100644 --- a/hiro/extension/about-dialog.hpp +++ b/hiro/extension/about-dialog.hpp @@ -5,7 +5,7 @@ struct AboutDialog { auto setAlignment(Alignment = Alignment::Center) -> type&; auto setAlignment(sWindow relativeTo, Alignment = Alignment::Center) -> type&; - auto setCopyright(const string& copyright = "") -> type&; + auto setCopyright(const string& copyright = "", const string& uri = "") -> type&; auto setDescription(const string& description = "") -> type&; auto setLicense(const string& license = "", const string& uri = "") -> type&; auto setLogo(const image& logo = {}) -> type&; @@ -18,6 +18,7 @@ struct AboutDialog { struct State { Alignment alignment = Alignment::Center; string copyright; + string copyrightURI; string description; string license; string licenseURI; diff --git a/hiro/extension/fixed-layout.cpp b/hiro/extension/fixed-layout.cpp index 03963d4b3a..abc8371704 100644 --- a/hiro/extension/fixed-layout.cpp +++ b/hiro/extension/fixed-layout.cpp @@ -13,7 +13,7 @@ auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& { return synchronize(); } -auto mFixedLayout::cell(uint position) const -> FixedLayoutCell { +auto mFixedLayout::cell(u32 position) const -> FixedLayoutCell { return state.cells(position, {}); } @@ -28,7 +28,7 @@ auto mFixedLayout::cells() const -> vector { return state.cells; } -auto mFixedLayout::cellCount() const -> uint { +auto mFixedLayout::cellCount() const -> u32 { return state.cells.size(); } @@ -38,7 +38,7 @@ auto mFixedLayout::destruct() -> void { } auto mFixedLayout::minimumSize() const -> Size { - float width = 0, height = 0; + f32 width = 0, height = 0; for(auto& cell : state.cells) { width = max(width, cell.sizable().minimumSize().width()); height = max(height, cell.sizable().minimumSize().height()); @@ -58,7 +58,7 @@ auto mFixedLayout::remove(sFixedLayoutCell cell) -> type& { auto offset = cell->offset(); cell->setParent(); state.cells.remove(offset); - for(uint n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); + for(u32 n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); return synchronize(); } @@ -84,7 +84,7 @@ auto mFixedLayout::setFont(const Font& font) -> type& { return *this; } -auto mFixedLayout::setParent(mObject* parent, int offset) -> type& { +auto mFixedLayout::setParent(mObject* parent, s32 offset) -> type& { for(auto& cell : reverse(state.cells)) cell->destruct(); mSizable::setParent(parent, offset); for(auto& cell : state.cells) cell->setParent(this, cell->offset()); @@ -130,7 +130,7 @@ auto mFixedLayoutCell::setGeometry(Geometry geometry) -> type& { return synchronize(); } -auto mFixedLayoutCell::setParent(mObject* parent, int offset) -> type& { +auto mFixedLayoutCell::setParent(mObject* parent, s32 offset) -> type& { state.sizable->destruct(); mObject::setParent(parent, offset); state.sizable->setParent(this, 0); diff --git a/hiro/extension/fixed-layout.hpp b/hiro/extension/fixed-layout.hpp index 77d23937a6..da2ea11b86 100644 --- a/hiro/extension/fixed-layout.hpp +++ b/hiro/extension/fixed-layout.hpp @@ -14,10 +14,10 @@ struct mFixedLayout : mSizable { using mSizable::remove; auto append(sSizable sizable, Geometry geometry) -> type&; - auto cell(uint position) const -> FixedLayoutCell; + auto cell(u32 position) const -> FixedLayoutCell; auto cell(sSizable sizable) const -> FixedLayoutCell; auto cells() const -> vector; - auto cellCount() const -> uint; + auto cellCount() const -> u32; auto minimumSize() const -> Size override; auto remove(sSizable sizable) -> type&; auto remove(sFixedLayoutCell cell) -> type&; @@ -25,7 +25,7 @@ struct mFixedLayout : mSizable { auto resize() -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setVisible(bool visible) ->type& override; auto synchronize() -> type&; @@ -44,7 +44,7 @@ struct mFixedLayoutCell : mObject { auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; auto setGeometry(Geometry geometry) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSizable(sSizable sizable) -> type&; auto setVisible(bool visible) -> type& override; auto sizable() const -> Sizable; diff --git a/hiro/extension/horizontal-layout.cpp b/hiro/extension/horizontal-layout.cpp index d6c6b11ae5..69f46aa6ff 100644 --- a/hiro/extension/horizontal-layout.cpp +++ b/hiro/extension/horizontal-layout.cpp @@ -1,10 +1,10 @@ #if defined(Hiro_HorizontalLayout) -auto mHorizontalLayout::alignment() const -> maybe { +auto mHorizontalLayout::alignment() const -> maybe { return state.alignment; } -auto mHorizontalLayout::append(sSizable sizable, Size size, float spacing) -> type& { +auto mHorizontalLayout::append(sSizable sizable, Size size, f32 spacing) -> type& { for(auto& cell : state.cells) { if(cell->state.sizable == sizable) return *this; } @@ -18,7 +18,7 @@ auto mHorizontalLayout::append(sSizable sizable, Size size, float spacing) -> ty return synchronize(); } -auto mHorizontalLayout::cell(uint position) const -> HorizontalLayoutCell { +auto mHorizontalLayout::cell(u32 position) const -> HorizontalLayoutCell { return state.cells(position, {}); } @@ -33,7 +33,7 @@ auto mHorizontalLayout::cells() const -> vector { return state.cells; } -auto mHorizontalLayout::cellCount() const -> uint { +auto mHorizontalLayout::cellCount() const -> u32 { return state.cells.size(); } @@ -43,8 +43,8 @@ auto mHorizontalLayout::destruct() -> void { } auto mHorizontalLayout::minimumSize() const -> Size { - float width = 0; - float spacing = 0; + f32 width = 0; + f32 spacing = 0; for(auto index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; @@ -57,7 +57,7 @@ auto mHorizontalLayout::minimumSize() const -> Size { spacing = cell.spacing(); } - float height = 0; + f32 height = 0; for(auto index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; @@ -90,7 +90,7 @@ auto mHorizontalLayout::remove(sHorizontalLayoutCell cell) -> type& { auto offset = cell->offset(); cell->setParent(); state.cells.remove(offset); - for(uint n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); + for(u32 n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); return synchronize(); } @@ -104,7 +104,7 @@ auto mHorizontalLayout::resize() -> type& { return *this; } -auto mHorizontalLayout::setAlignment(maybe alignment) -> type& { +auto mHorizontalLayout::setAlignment(maybe alignment) -> type& { state.alignment = alignment; return synchronize(); } @@ -130,13 +130,13 @@ auto mHorizontalLayout::setGeometry(Geometry requestedGeometry) -> type& { geometry.setWidth (geometry.width() - padding().x() - padding().width()); geometry.setHeight(geometry.height() - padding().y() - padding().height()); - vector widths; + vector widths; widths.resize(cellCount()); - uint maximumWidths = 0; - for(uint index : range(cellCount())) { + u32 maximumWidths = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; - float width = 0; + f32 width = 0; if(cell.size().width() == Size::Maximum) { width = Size::Maximum; maximumWidths++; @@ -148,9 +148,9 @@ auto mHorizontalLayout::setGeometry(Geometry requestedGeometry) -> type& { widths[index] = width; } - float fixedWidth = 0; - float spacing = 0; - for(uint index : range(cellCount())) { + f32 fixedWidth = 0; + f32 spacing = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; if(widths[index] != Size::Maximum) fixedWidth += widths[index]; @@ -158,13 +158,13 @@ auto mHorizontalLayout::setGeometry(Geometry requestedGeometry) -> type& { spacing = cell.spacing(); } - float maximumWidth = (geometry.width() - fixedWidth) / maximumWidths; + f32 maximumWidth = (geometry.width() - fixedWidth) / maximumWidths; for(auto& width : widths) { if(width == Size::Maximum) width = maximumWidth; } - float height = 0; - for(uint index : range(cellCount())) { + f32 height = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; if(cell.size().height() == Size::Maximum) { @@ -177,22 +177,22 @@ auto mHorizontalLayout::setGeometry(Geometry requestedGeometry) -> type& { } } - float geometryX = geometry.x(); - float geometryY = geometry.y(); - for(uint index : range(cellCount())) { + f32 geometryX = geometry.x(); + f32 geometryY = geometry.y(); + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; - float geometryWidth = widths[index]; - float geometryHeight = height; + f32 geometryWidth = widths[index]; + f32 geometryHeight = height; auto alignment = cell.alignment(); if(!alignment) alignment = this->alignment(); if(!alignment) alignment = 0.5; - float cellWidth = geometryWidth; - float cellHeight = cell.size().height(); + f32 cellWidth = geometryWidth; + f32 cellHeight = cell.size().height(); if(cellHeight == Size::Minimum) cellHeight = cell.sizable()->minimumSize().height(); if(cellHeight == Size::Maximum) cellHeight = geometryHeight; - float cellX = geometryX; - float cellY = geometryY + alignment() * (geometryHeight - cellHeight); + f32 cellX = geometryX; + f32 cellY = geometryY + alignment() * (geometryHeight - cellHeight); cell.sizable().setGeometry({cellX, cellY, cellWidth, cellHeight}); geometryX += geometryWidth + cell.spacing(); } @@ -206,14 +206,14 @@ auto mHorizontalLayout::setPadding(Geometry padding) -> type& { return synchronize(); } -auto mHorizontalLayout::setParent(mObject* parent, int offset) -> type& { +auto mHorizontalLayout::setParent(mObject* parent, s32 offset) -> type& { for(auto& cell : reverse(state.cells)) cell->destruct(); mSizable::setParent(parent, offset); for(auto& cell : state.cells) cell->setParent(this, cell->offset()); return *this; } -auto mHorizontalLayout::setSpacing(float spacing) -> type& { +auto mHorizontalLayout::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } @@ -224,7 +224,7 @@ auto mHorizontalLayout::setVisible(bool visible) -> type& { return synchronize(); } -auto mHorizontalLayout::spacing() const -> float { +auto mHorizontalLayout::spacing() const -> f32 { return state.spacing; } @@ -235,7 +235,7 @@ auto mHorizontalLayout::synchronize() -> type& { // -auto mHorizontalLayoutCell::alignment() const -> maybe { +auto mHorizontalLayoutCell::alignment() const -> maybe { return state.alignment; } @@ -249,7 +249,7 @@ auto mHorizontalLayoutCell::destruct() -> void { mObject::destruct(); } -auto mHorizontalLayoutCell::setAlignment(maybe alignment) -> type& { +auto mHorizontalLayoutCell::setAlignment(maybe alignment) -> type& { state.alignment = alignment; return synchronize(); } @@ -266,7 +266,7 @@ auto mHorizontalLayoutCell::setFont(const Font& font) -> type& { return *this; } -auto mHorizontalLayoutCell::setParent(mObject* parent, int offset) -> type& { +auto mHorizontalLayoutCell::setParent(mObject* parent, s32 offset) -> type& { state.sizable->destruct(); mObject::setParent(parent, offset); state.sizable->setParent(this, 0); @@ -283,7 +283,7 @@ auto mHorizontalLayoutCell::setSize(Size size) -> type& { return synchronize(); } -auto mHorizontalLayoutCell::setSpacing(float spacing) -> type& { +auto mHorizontalLayoutCell::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } @@ -302,7 +302,7 @@ auto mHorizontalLayoutCell::size() const -> Size { return state.size; } -auto mHorizontalLayoutCell::spacing() const -> float { +auto mHorizontalLayoutCell::spacing() const -> f32 { return state.spacing; } diff --git a/hiro/extension/horizontal-layout.hpp b/hiro/extension/horizontal-layout.hpp index bad2b15c6a..4f9e6901a7 100644 --- a/hiro/extension/horizontal-layout.hpp +++ b/hiro/extension/horizontal-layout.hpp @@ -13,66 +13,66 @@ struct mHorizontalLayout : mSizable { using type = mHorizontalLayout; using mSizable::remove; - auto alignment() const -> maybe; - auto append(sSizable sizable, Size size, float spacing = 5_sy) -> type&; - auto cell(uint position) const -> HorizontalLayoutCell; + auto alignment() const -> maybe; + auto append(sSizable sizable, Size size, f32 spacing = 5_sy) -> type&; + auto cell(u32 position) const -> HorizontalLayoutCell; auto cell(sSizable sizable) const -> HorizontalLayoutCell; auto cells() const -> vector; - auto cellCount() const -> uint; + auto cellCount() const -> u32; auto minimumSize() const -> Size override; auto padding() const -> Geometry; auto remove(sSizable sizable) -> type&; auto remove(sHorizontalLayoutCell cell) -> type&; auto reset() -> type& override; auto resize() -> type&; - auto setAlignment(maybe alignment) -> type&; + auto setAlignment(maybe alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; auto setGeometry(Geometry geometry) -> type& override; auto setPadding(Geometry padding) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type&; - auto setSpacing(float spacing) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setSpacing(f32 spacing) -> type&; auto setVisible(bool visible) -> type& override; - auto spacing() const -> float; + auto spacing() const -> f32; auto synchronize() -> type&; private: auto destruct() -> void override; struct State { - maybe alignment; + maybe alignment; vector cells; Geometry padding; - float spacing = 5_sx; + f32 spacing = 5_sx; } state; }; struct mHorizontalLayoutCell : mObject { using type = mHorizontalLayoutCell; - auto alignment() const -> maybe; + auto alignment() const -> maybe; auto collapsible() const -> bool; - auto setAlignment(maybe alignment) -> type&; + auto setAlignment(maybe alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSizable(sSizable sizable) -> type&; auto setSize(Size size) -> type&; - auto setSpacing(float spacing) -> type&; + auto setSpacing(f32 spacing) -> type&; auto setVisible(bool visible) -> type& override; auto sizable() const -> Sizable; auto size() const -> Size; - auto spacing() const -> float; + auto spacing() const -> f32; auto synchronize() -> type&; private: auto destruct() -> void override; struct State { - maybe alignment; + maybe alignment; sSizable sizable; Size size; - float spacing = 5_sx; + f32 spacing = 5_sx; } state; friend class mHorizontalLayout; diff --git a/hiro/extension/horizontal-resize-grip.cpp b/hiro/extension/horizontal-resize-grip.cpp index fdd8d3cb37..5079134a39 100644 --- a/hiro/extension/horizontal-resize-grip.cpp +++ b/hiro/extension/horizontal-resize-grip.cpp @@ -3,7 +3,7 @@ mHorizontalResizeGrip::mHorizontalResizeGrip() { image icon; icon.allocate(5, 15); - for(uint y : range(icon.height())) { + for(u32 y : range(icon.height())) { auto data = icon.data() + y * icon.pitch(); icon.write(data, 0x00000000); data += icon.stride(); icon.write(data, 0xff9f9f9f); data += icon.stride(); @@ -33,7 +33,7 @@ auto mHorizontalResizeGrip::doActivate() const -> void { if(state.onActivate) state.onActivate(); } -auto mHorizontalResizeGrip::doResize(int offset) const -> void { +auto mHorizontalResizeGrip::doResize(s32 offset) const -> void { if(state.onResize) state.onResize(offset); } @@ -42,7 +42,7 @@ auto mHorizontalResizeGrip::onActivate(const function& callback) -> typ return *this; } -auto mHorizontalResizeGrip::onResize(const function& callback) -> type& { +auto mHorizontalResizeGrip::onResize(const function& callback) -> type& { state.onResize = callback; return *this; } diff --git a/hiro/extension/horizontal-resize-grip.hpp b/hiro/extension/horizontal-resize-grip.hpp index 8f7b588bfe..fbaf9d96ad 100644 --- a/hiro/extension/horizontal-resize-grip.hpp +++ b/hiro/extension/horizontal-resize-grip.hpp @@ -9,15 +9,15 @@ struct mHorizontalResizeGrip : mCanvas { mHorizontalResizeGrip(); auto doActivate() const -> void; - auto doResize(int offset) const -> void; + auto doResize(s32 offset) const -> void; auto onActivate(const function& callback) -> type&; - auto onResize(const function& callback) -> type&; + auto onResize(const function& callback) -> type&; //private: struct State { function onActivate; - function onResize; - int offset = 0; + function onResize; + s32 offset = 0; Position origin; Timer timer; } state; diff --git a/hiro/extension/list-view.cpp b/hiro/extension/list-view.cpp index 812703d7cb..f796f22a83 100644 --- a/hiro/extension/list-view.cpp +++ b/hiro/extension/list-view.cpp @@ -37,7 +37,7 @@ auto mListView::doToggle(ListViewItem item) const -> void { if(state.onToggle) state.onToggle(item); } -auto mListView::item(uint position) const -> ListViewItem { +auto mListView::item(u32 position) const -> ListViewItem { return ListViewItem{mTableView::item(position)}; } diff --git a/hiro/extension/list-view.hpp b/hiro/extension/list-view.hpp index 37bb971d68..2c17cdd646 100644 --- a/hiro/extension/list-view.hpp +++ b/hiro/extension/list-view.hpp @@ -20,7 +20,7 @@ struct mListView : mTableView { auto doChange() const -> void; auto doContext() const -> void; auto doToggle(ListViewItem) const -> void; - auto item(uint position) const -> ListViewItem; + auto item(u32 position) const -> ListViewItem; auto items() const -> vector; auto onActivate(const function& callback) -> type&; auto onChange(const function& callback) -> type&; @@ -29,7 +29,7 @@ struct mListView : mTableView { auto reset() -> type& override; auto resizeColumn() -> type&; auto selected() const -> ListViewItem; - auto setVisible(bool visible = true) -> type&; + auto setVisible(bool visible = true) -> type& override; //private: struct State { diff --git a/hiro/extension/message-dialog.cpp b/hiro/extension/message-dialog.cpp index ff35cba70f..81b1926039 100644 --- a/hiro/extension/message-dialog.cpp +++ b/hiro/extension/message-dialog.cpp @@ -99,9 +99,9 @@ auto MessageDialog::_run() -> string { button.setFocused(); //the last button will have effective focus } - int widthMessage = 5_sx + 16 + 5_sx + Font().size(state.text).width() + 5_sx; - int widthButtons = 5_sx + state.buttons.size() * 85_sx; - int width = max(320_sx, widthMessage, widthButtons); + s32 widthMessage = 5_sx + 16 + 5_sx + Font().size(state.text).width() + 5_sx; + s32 widthButtons = 5_sx + state.buttons.size() * 85_sx; + s32 width = max(320_sx, widthMessage, widthButtons); window.onClose([&] { //if the dialog is dismissed (escape pressed, or window manager close button clicked), diff --git a/hiro/extension/table-layout.cpp b/hiro/extension/table-layout.cpp index 5e240f987f..7fbc1f0095 100644 --- a/hiro/extension/table-layout.cpp +++ b/hiro/extension/table-layout.cpp @@ -17,11 +17,11 @@ auto mTableLayout::append(sSizable sizable, Size size) -> type& { return *this; } -auto mTableLayout::cell(uint position) const -> TableLayoutCell { +auto mTableLayout::cell(u32 position) const -> TableLayoutCell { return state.cells(position, {}); } -auto mTableLayout::cell(uint x, uint y) const -> TableLayoutCell { +auto mTableLayout::cell(u32 x, u32 y) const -> TableLayoutCell { if(auto cell = state.cells(y * columnCount() + x, {})) return cell; return {}; } @@ -37,11 +37,11 @@ auto mTableLayout::cells() const -> vector { return state.cells; } -auto mTableLayout::cellCount() const -> uint { +auto mTableLayout::cellCount() const -> u32 { return state.cells.size(); } -auto mTableLayout::column(uint position) const -> TableLayoutColumn { +auto mTableLayout::column(u32 position) const -> TableLayoutColumn { return state.columns(position, {}); } @@ -49,7 +49,7 @@ auto mTableLayout::columns() const -> vector { return state.columns; } -auto mTableLayout::columnCount() const -> uint { +auto mTableLayout::columnCount() const -> u32 { return state.columns.size(); } @@ -61,11 +61,11 @@ auto mTableLayout::destruct() -> void { } auto mTableLayout::minimumSize() const -> Size { - float minimumWidth = 0; - for(uint x : range(columnCount())) { - float width = 0; + f32 minimumWidth = 0; + for(u32 x : range(columnCount())) { + f32 width = 0; auto column = this->column(x); - for(uint y : range(rowCount())) { + for(u32 y : range(rowCount())) { auto row = this->row(y); auto cell = this->cell(x, y); if(cell.size().width() == Size::Minimum || cell.size().width() == Size::Maximum) { @@ -78,11 +78,11 @@ auto mTableLayout::minimumSize() const -> Size { if(x != columnCount() - 1) minimumWidth += column.spacing(); } - float minimumHeight = 0; - for(uint y : range(rowCount())) { - float height = 0; + f32 minimumHeight = 0; + for(u32 y : range(rowCount())) { + f32 height = 0; auto row = this->row(y); - for(uint x : range(columnCount())) { + for(u32 x : range(columnCount())) { auto column = this->column(x); auto cell = this->cell(x, y); if(cell.size().height() == Size::Minimum || cell.size().height() == Size::Maximum) { @@ -117,7 +117,7 @@ auto mTableLayout::remove(sTableLayoutCell cell) -> type& { auto offset = cell->offset(); cell->setParent(); state.cells.remove(offset); - for(uint n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); + for(u32 n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); return synchronize(); } @@ -131,7 +131,7 @@ auto mTableLayout::resize() -> type& { return *this; } -auto mTableLayout::row(uint position) const -> TableLayoutRow { +auto mTableLayout::row(u32 position) const -> TableLayoutRow { return state.rows(position, {}); } @@ -139,7 +139,7 @@ auto mTableLayout::rows() const -> vector { return state.rows; } -auto mTableLayout::rowCount() const -> uint { +auto mTableLayout::rowCount() const -> u32 { return state.rows.size(); } @@ -169,13 +169,13 @@ auto mTableLayout::setGeometry(Geometry requestedGeometry) -> type& { geometry.setWidth (geometry.width() - padding().x() - padding().width()); geometry.setHeight(geometry.height() - padding().y() - padding().height()); - vector widths; + vector widths; widths.resize(columnCount()); - uint maximumWidths = 0; - for(uint x : range(columnCount())) { - float width = 0; + u32 maximumWidths = 0; + for(u32 x : range(columnCount())) { + f32 width = 0; auto column = this->column(x); - for(uint y : range(rowCount())) { + for(u32 y : range(rowCount())) { auto row = this->row(y); auto cell = this->cell(x, y); if(cell.size().width() == Size::Maximum) { @@ -192,13 +192,13 @@ auto mTableLayout::setGeometry(Geometry requestedGeometry) -> type& { widths[x] = width; } - vector heights; + vector heights; heights.resize(rowCount()); - uint maximumHeights = 0; - for(uint y : range(rowCount())) { - float height = 0; + u32 maximumHeights = 0; + for(u32 y : range(rowCount())) { + f32 height = 0; auto row = this->row(y); - for(uint x : range(columnCount())) { + for(u32 x : range(columnCount())) { auto column = this->column(x); auto cell = this->cell(x, y); if(cell.size().height() == Size::Maximum) { @@ -215,51 +215,51 @@ auto mTableLayout::setGeometry(Geometry requestedGeometry) -> type& { heights[y] = height; } - float fixedWidth = 0; - for(uint x : range(columnCount())) { + f32 fixedWidth = 0; + for(u32 x : range(columnCount())) { if(widths[x] != Size::Maximum) fixedWidth += widths[x]; if(x != columnCount() - 1) fixedWidth += column(x)->spacing(); } - float maximumWidth = (geometry.width() - fixedWidth) / maximumWidths; + f32 maximumWidth = (geometry.width() - fixedWidth) / maximumWidths; for(auto& width : widths) { if(width == Size::Maximum) width = maximumWidth; } - float fixedHeight = 0; - for(uint y : range(rowCount())) { + f32 fixedHeight = 0; + for(u32 y : range(rowCount())) { if(heights[y] != Size::Maximum) fixedHeight += heights[y]; if(y != rowCount() - 1) fixedHeight += row(y)->spacing(); } - float maximumHeight = (geometry.height() - fixedHeight) / maximumHeights; + f32 maximumHeight = (geometry.height() - fixedHeight) / maximumHeights; for(auto& height : heights) { if(height == Size::Maximum) height = maximumHeight; } - float geometryY = geometry.y(); - for(uint y : range(rowCount())) { - float geometryX = geometry.x(); + f32 geometryY = geometry.y(); + for(u32 y : range(rowCount())) { + f32 geometryX = geometry.x(); auto row = this->row(y); - for(uint x : range(columnCount())) { + for(u32 x : range(columnCount())) { auto column = this->column(x); auto cell = this->cell(x, y); - float geometryWidth = widths [x]; - float geometryHeight = heights[y]; + f32 geometryWidth = widths [x]; + f32 geometryHeight = heights[y]; auto alignment = cell.alignment(); if(!alignment) alignment = column.alignment(); if(!alignment) alignment = row.alignment(); if(!alignment) alignment = this->alignment(); if(!alignment) alignment = {0.0, 0.5}; - float cellWidth = cell.size().width(); + f32 cellWidth = cell.size().width(); if(cellWidth == Size::Minimum) cellWidth = cell.sizable()->minimumSize().width(); if(cellWidth == Size::Maximum) cellWidth = geometryWidth; cellWidth = min(cellWidth, geometryWidth); - float cellHeight = cell.size().height(); + f32 cellHeight = cell.size().height(); if(cellHeight == Size::Minimum) cellHeight = cell.sizable()->minimumSize().height(); if(cellHeight == Size::Maximum) cellHeight = geometryHeight; cellHeight = min(cellHeight, geometryHeight); - float cellX = geometryX + alignment.horizontal() * (geometryWidth - cellWidth); - float cellY = geometryY + alignment.vertical() * (geometryHeight - cellHeight); + f32 cellX = geometryX + alignment.horizontal() * (geometryWidth - cellWidth); + f32 cellY = geometryY + alignment.vertical() * (geometryHeight - cellHeight); cell.sizable()->setGeometry({cellX, cellY, cellWidth, cellHeight}); geometryX += widths[x] + column.spacing(); @@ -276,7 +276,7 @@ auto mTableLayout::setPadding(Geometry padding) -> type& { return synchronize(); } -auto mTableLayout::setParent(mObject* parent, int offset) -> type& { +auto mTableLayout::setParent(mObject* parent, s32 offset) -> type& { for(auto& cell : reverse(state.cells)) cell->destruct(); for(auto& column : reverse(state.columns)) column->destruct(); for(auto& row : reverse(state.rows)) row->destruct(); @@ -322,12 +322,12 @@ auto mTableLayoutColumn::setAlignment(Alignment alignment) -> type& { return synchronize(); } -auto mTableLayoutColumn::setSpacing(float spacing) -> type& { +auto mTableLayoutColumn::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } -auto mTableLayoutColumn::spacing() const -> float { +auto mTableLayoutColumn::spacing() const -> f32 { return state.spacing; } @@ -351,12 +351,12 @@ auto mTableLayoutRow::setAlignment(Alignment alignment) -> type& { return synchronize(); } -auto mTableLayoutRow::setSpacing(float spacing) -> type& { +auto mTableLayoutRow::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } -auto mTableLayoutRow::spacing() const -> float { +auto mTableLayoutRow::spacing() const -> f32 { return state.spacing; } @@ -397,7 +397,7 @@ auto mTableLayoutCell::setFont(const Font& font) -> type& { return *this; } -auto mTableLayoutCell::setParent(mObject* parent, int offset) -> type& { +auto mTableLayoutCell::setParent(mObject* parent, s32 offset) -> type& { state.sizable->destruct(); mObject::setParent(parent, offset); state.sizable->setParent(this, 0); diff --git a/hiro/extension/table-layout.hpp b/hiro/extension/table-layout.hpp index b9cc4cc0ac..59dc949fc5 100644 --- a/hiro/extension/table-layout.hpp +++ b/hiro/extension/table-layout.hpp @@ -21,29 +21,29 @@ struct mTableLayout : mSizable { auto alignment() const -> Alignment; auto append(sSizable sizable, Size size) -> type&; - auto cell(uint position) const -> TableLayoutCell; - auto cell(uint x, uint y) const -> TableLayoutCell; + auto cell(u32 position) const -> TableLayoutCell; + auto cell(u32 x, u32 y) const -> TableLayoutCell; auto cell(sSizable sizable) const -> TableLayoutCell; auto cells() const -> vector; - auto cellCount() const -> uint; - auto column(uint position) const -> TableLayoutColumn; + auto cellCount() const -> u32; + auto column(u32 position) const -> TableLayoutColumn; auto columns() const -> vector; - auto columnCount() const -> uint; + auto columnCount() const -> u32; auto minimumSize() const -> Size override; auto padding() const -> Geometry; auto remove(sSizable sizable) -> type&; auto remove(sTableLayoutCell cell) -> type&; auto reset() -> type& override; auto resize() -> type&; - auto row(uint position) const -> TableLayoutRow; + auto row(u32 position) const -> TableLayoutRow; auto rows() const -> vector; - auto rowCount() const -> uint; + auto rowCount() const -> u32; auto setAlignment(Alignment alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; auto setGeometry(Geometry geometry) -> type& override; auto setPadding(Geometry padding) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSize(Size size) -> type&; auto setVisible(bool visible) -> type& override; auto size() const -> Size; @@ -67,14 +67,14 @@ struct mTableLayoutColumn : mObject { auto alignment() const -> Alignment; auto setAlignment(Alignment alignment) -> type&; - auto setSpacing(float spacing) -> type&; - auto spacing() const -> float; + auto setSpacing(f32 spacing) -> type&; + auto spacing() const -> f32; auto synchronize() -> type&; private: struct State { Alignment alignment; - float spacing = 5_sx; + f32 spacing = 5_sx; } state; friend class mTableLayout; @@ -85,14 +85,14 @@ struct mTableLayoutRow : mObject { auto alignment() const -> Alignment; auto setAlignment(Alignment alignment) -> type&; - auto setSpacing(float spacing) -> type&; - auto spacing() const -> float; + auto setSpacing(f32 spacing) -> type&; + auto spacing() const -> f32; auto synchronize() -> type&; private: struct State { Alignment alignment; - float spacing = 5_sy; + f32 spacing = 5_sy; } state; friend class mTableLayout; @@ -105,7 +105,7 @@ struct mTableLayoutCell : mObject { auto setAlignment(Alignment alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSizable(sSizable sizable) -> type&; auto setSize(Size size) -> type&; auto setVisible(bool visible) -> type& override; diff --git a/hiro/extension/vertical-layout.cpp b/hiro/extension/vertical-layout.cpp index f487968f05..98f2ef2d7f 100644 --- a/hiro/extension/vertical-layout.cpp +++ b/hiro/extension/vertical-layout.cpp @@ -1,10 +1,10 @@ #if defined(Hiro_VerticalLayout) -auto mVerticalLayout::alignment() const -> maybe { +auto mVerticalLayout::alignment() const -> maybe { return state.alignment; } -auto mVerticalLayout::append(sSizable sizable, Size size, float spacing) -> type& { +auto mVerticalLayout::append(sSizable sizable, Size size, f32 spacing) -> type& { for(auto& cell : state.cells) { if(cell->state.sizable == sizable) return *this; } @@ -18,7 +18,7 @@ auto mVerticalLayout::append(sSizable sizable, Size size, float spacing) -> type return synchronize(); } -auto mVerticalLayout::cell(uint position) const -> VerticalLayoutCell { +auto mVerticalLayout::cell(u32 position) const -> VerticalLayoutCell { return state.cells(position, {}); } @@ -33,7 +33,7 @@ auto mVerticalLayout::cells() const -> vector { return state.cells; } -auto mVerticalLayout::cellCount() const -> uint { +auto mVerticalLayout::cellCount() const -> u32 { return state.cells.size(); } @@ -43,7 +43,7 @@ auto mVerticalLayout::destruct() -> void { } auto mVerticalLayout::minimumSize() const -> Size { - float width = 0; + f32 width = 0; for(auto index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; @@ -54,8 +54,8 @@ auto mVerticalLayout::minimumSize() const -> Size { width = max(width, cell.size().width()); } - float height = 0; - float spacing = 0; + f32 height = 0; + f32 spacing = 0; for(auto index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; @@ -90,7 +90,7 @@ auto mVerticalLayout::remove(sVerticalLayoutCell cell) -> type& { auto offset = cell->offset(); cell->setParent(); state.cells.remove(offset); - for(uint n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); + for(u32 n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1); return synchronize(); } @@ -104,7 +104,7 @@ auto mVerticalLayout::resize() -> type& { return *this; } -auto mVerticalLayout::setAlignment(maybe alignment) -> type& { +auto mVerticalLayout::setAlignment(maybe alignment) -> type& { state.alignment = alignment; return synchronize(); } @@ -130,8 +130,8 @@ auto mVerticalLayout::setGeometry(Geometry requestedGeometry) -> type& { geometry.setWidth (geometry.width() - padding().x() - padding().width()); geometry.setHeight(geometry.height() - padding().y() - padding().height()); - float width = 0; - for(uint index : range(cellCount())) { + f32 width = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; if(cell.size().width() == Size::Maximum) { @@ -144,13 +144,13 @@ auto mVerticalLayout::setGeometry(Geometry requestedGeometry) -> type& { } } - vector heights; + vector heights; heights.resize(cellCount()); - uint maximumHeights = 0; - for(uint index : range(cellCount())) { + u32 maximumHeights = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; - float height = 0; + f32 height = 0; if(cell.size().height() == Size::Maximum) { height = Size::Maximum; maximumHeights++; @@ -162,9 +162,9 @@ auto mVerticalLayout::setGeometry(Geometry requestedGeometry) -> type& { heights[index] = height; } - float fixedHeight = 0; - float spacing = 0; - for(uint index : range(cellCount())) { + f32 fixedHeight = 0; + f32 spacing = 0; + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; if(heights[index] != Size::Maximum) fixedHeight += heights[index]; @@ -172,27 +172,27 @@ auto mVerticalLayout::setGeometry(Geometry requestedGeometry) -> type& { spacing = cell.spacing(); } - float maximumHeight = (geometry.height() - fixedHeight) / maximumHeights; + f32 maximumHeight = (geometry.height() - fixedHeight) / maximumHeights; for(auto& height : heights) { if(height == Size::Maximum) height = maximumHeight; } - float geometryX = geometry.x(); - float geometryY = geometry.y(); - for(uint index : range(cellCount())) { + f32 geometryX = geometry.x(); + f32 geometryY = geometry.y(); + for(u32 index : range(cellCount())) { auto cell = this->cell(index); if(cell.collapsible()) continue; - float geometryWidth = width; - float geometryHeight = heights[index]; + f32 geometryWidth = width; + f32 geometryHeight = heights[index]; auto alignment = cell.alignment(); if(!alignment) alignment = this->alignment(); if(!alignment) alignment = 0.0; - float cellWidth = cell.size().width(); - float cellHeight = geometryHeight; + f32 cellWidth = cell.size().width(); + f32 cellHeight = geometryHeight; if(cellWidth == Size::Minimum) cellWidth = cell.sizable()->minimumSize().width(); if(cellWidth == Size::Maximum) cellWidth = geometryWidth; - float cellX = geometryX + alignment() * (geometryWidth - cellWidth); - float cellY = geometryY; + f32 cellX = geometryX + alignment() * (geometryWidth - cellWidth); + f32 cellY = geometryY; cell.sizable().setGeometry({cellX, cellY, cellWidth, cellHeight}); geometryY += geometryHeight + cell.spacing(); } @@ -206,14 +206,14 @@ auto mVerticalLayout::setPadding(Geometry padding) -> type& { return synchronize(); } -auto mVerticalLayout::setParent(mObject* parent, int offset) -> type& { +auto mVerticalLayout::setParent(mObject* parent, s32 offset) -> type& { for(auto& cell : reverse(state.cells)) cell->destruct(); mSizable::setParent(parent, offset); for(auto& cell : state.cells) cell->setParent(this, cell->offset()); return *this; } -auto mVerticalLayout::setSpacing(float spacing) -> type& { +auto mVerticalLayout::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } @@ -224,7 +224,7 @@ auto mVerticalLayout::setVisible(bool visible) -> type& { return synchronize(); } -auto mVerticalLayout::spacing() const -> float { +auto mVerticalLayout::spacing() const -> f32 { return state.spacing; } @@ -235,7 +235,7 @@ auto mVerticalLayout::synchronize() -> type& { // -auto mVerticalLayoutCell::alignment() const -> maybe { +auto mVerticalLayoutCell::alignment() const -> maybe { return state.alignment; } @@ -249,7 +249,7 @@ auto mVerticalLayoutCell::destruct() -> void { mObject::destruct(); } -auto mVerticalLayoutCell::setAlignment(maybe alignment) -> type& { +auto mVerticalLayoutCell::setAlignment(maybe alignment) -> type& { state.alignment = alignment; return synchronize(); } @@ -266,7 +266,7 @@ auto mVerticalLayoutCell::setFont(const Font& font) -> type& { return *this; } -auto mVerticalLayoutCell::setParent(mObject* parent, int offset) -> type& { +auto mVerticalLayoutCell::setParent(mObject* parent, s32 offset) -> type& { state.sizable->destruct(); mObject::setParent(parent, offset); state.sizable->setParent(this, 0); @@ -283,7 +283,7 @@ auto mVerticalLayoutCell::setSize(Size size) -> type& { return synchronize(); } -auto mVerticalLayoutCell::setSpacing(float spacing) -> type& { +auto mVerticalLayoutCell::setSpacing(f32 spacing) -> type& { state.spacing = spacing; return synchronize(); } @@ -302,7 +302,7 @@ auto mVerticalLayoutCell::size() const -> Size { return state.size; } -auto mVerticalLayoutCell::spacing() const -> float { +auto mVerticalLayoutCell::spacing() const -> f32 { return state.spacing; } diff --git a/hiro/extension/vertical-layout.hpp b/hiro/extension/vertical-layout.hpp index b68a3d39de..73314fe893 100644 --- a/hiro/extension/vertical-layout.hpp +++ b/hiro/extension/vertical-layout.hpp @@ -13,66 +13,66 @@ struct mVerticalLayout : mSizable { using type = mVerticalLayout; using mSizable::remove; - auto alignment() const -> maybe; - auto append(sSizable sizable, Size size, float spacing = 5_sy) -> type&; - auto cell(uint position) const -> VerticalLayoutCell; + auto alignment() const -> maybe; + auto append(sSizable sizable, Size size, f32 spacing = 5_sy) -> type&; + auto cell(u32 position) const -> VerticalLayoutCell; auto cell(sSizable sizable) const -> VerticalLayoutCell; auto cells() const -> vector; - auto cellCount() const -> uint; + auto cellCount() const -> u32; auto minimumSize() const -> Size override; auto padding() const -> Geometry; auto remove(sSizable sizable) -> type&; auto remove(sVerticalLayoutCell cell) -> type&; auto reset() -> type& override; auto resize() -> type&; - auto setAlignment(maybe alignment) -> type&; + auto setAlignment(maybe alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; auto setGeometry(Geometry geometry) -> type& override; auto setPadding(Geometry padding) -> type&; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; - auto setSpacing(float spacing) -> type&; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; + auto setSpacing(f32 spacing) -> type&; auto setVisible(bool visible) -> type& override; - auto spacing() const -> float; + auto spacing() const -> f32; auto synchronize() -> type&; private: auto destruct() -> void override; struct State { - maybe alignment; + maybe alignment; vector cells; Geometry padding; - float spacing = 5_sy; + f32 spacing = 5_sy; } state; }; struct mVerticalLayoutCell : mObject { using type = mVerticalLayoutCell; - auto alignment() const -> maybe; + auto alignment() const -> maybe; auto collapsible() const -> bool; - auto setAlignment(maybe alignment) -> type&; + auto setAlignment(maybe alignment) -> type&; auto setEnabled(bool enabled) -> type& override; auto setFont(const Font& font) -> type& override; - auto setParent(mObject* parent = nullptr, int offset = -1) -> type& override; + auto setParent(mObject* parent = nullptr, s32 offset = -1) -> type& override; auto setSizable(sSizable sizable) -> type&; auto setSize(Size size) -> type&; - auto setSpacing(float spacing) -> type&; + auto setSpacing(f32 spacing) -> type&; auto setVisible(bool visible) -> type& override; auto sizable() const -> Sizable; auto size() const -> Size; - auto spacing() const -> float; + auto spacing() const -> f32; auto synchronize() -> type&; private: auto destruct() -> void override; struct State { - maybe alignment; + maybe alignment; sSizable sizable; Size size; - float spacing = 5_sy; + f32 spacing = 5_sy; } state; friend class mVerticalLayout; diff --git a/hiro/extension/vertical-resize-grip.cpp b/hiro/extension/vertical-resize-grip.cpp index 51a0ed7462..4eac1952ec 100644 --- a/hiro/extension/vertical-resize-grip.cpp +++ b/hiro/extension/vertical-resize-grip.cpp @@ -3,7 +3,7 @@ mVerticalResizeGrip::mVerticalResizeGrip() { image icon; icon.allocate(15, 5); - for(uint x : range(icon.width())) { + for(u32 x : range(icon.width())) { auto data = icon.data() + x * icon.stride(); icon.write(data, 0x00000000); data += icon.pitch(); icon.write(data, 0xff9f9f9f); data += icon.pitch(); @@ -33,7 +33,7 @@ auto mVerticalResizeGrip::doActivate() const -> void { if(state.onActivate) state.onActivate(); } -auto mVerticalResizeGrip::doResize(int offset) const -> void { +auto mVerticalResizeGrip::doResize(s32 offset) const -> void { if(state.onResize) state.onResize(offset); } @@ -42,7 +42,7 @@ auto mVerticalResizeGrip::onActivate(const function& callback) -> type& return *this; } -auto mVerticalResizeGrip::onResize(const function& callback) -> type& { +auto mVerticalResizeGrip::onResize(const function& callback) -> type& { state.onResize = callback; return *this; } diff --git a/hiro/extension/vertical-resize-grip.hpp b/hiro/extension/vertical-resize-grip.hpp index 68e31e805c..11a41b9080 100644 --- a/hiro/extension/vertical-resize-grip.hpp +++ b/hiro/extension/vertical-resize-grip.hpp @@ -9,15 +9,15 @@ struct mVerticalResizeGrip : mCanvas { mVerticalResizeGrip(); auto doActivate() const -> void; - auto doResize(int offset) const -> void; + auto doResize(s32 offset) const -> void; auto onActivate(const function& callback) -> type&; - auto onResize(const function& callback) -> type&; + auto onResize(const function& callback) -> type&; //private: struct State { function onActivate; - function onResize; - int offset = 0; + function onResize; + s32 offset = 0; Position origin; Timer timer; } state; diff --git a/hiro/gtk/desktop.cpp b/hiro/gtk/desktop.cpp index 8ff555f826..76656f1af5 100644 --- a/hiro/gtk/desktop.cpp +++ b/hiro/gtk/desktop.cpp @@ -18,15 +18,15 @@ auto pDesktop::workspace() -> Geometry { #if defined(DISPLAY_XORG) auto display = XOpenDisplay(nullptr); - int screen = DefaultScreen(display); + s32 screen = DefaultScreen(display); - int format; + s32 format; unsigned char* data = nullptr; unsigned long items, after; XlibAtom returnAtom; XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibTrue); - int result = XGetWindowProperty( + s32 result = XGetWindowProperty( display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse, XInternAtom(display, "CARDINAL", XlibTrue), &returnAtom, &format, &items, &after, &data ); @@ -35,7 +35,7 @@ auto pDesktop::workspace() -> Geometry { if(result == Success && returnAtom == cardinal && format == 32 && items == 4) { unsigned long* workarea = (unsigned long*)data; XCloseDisplay(display); - return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]}; + return {(s32)workarea[0], (s32)workarea[1], (s32)workarea[2], (s32)workarea[3]}; } XCloseDisplay(display); diff --git a/hiro/gtk/font.cpp b/hiro/gtk/font.cpp index 04907eebd3..88b0fcf909 100644 --- a/hiro/gtk/font.cpp +++ b/hiro/gtk/font.cpp @@ -14,7 +14,7 @@ auto pFont::size(PangoFontDescription* font, const string& text) -> Size { PangoLayout* layout = pango_layout_new(context); pango_layout_set_font_description(layout, font); pango_layout_set_text(layout, text, -1); - int width = 0, height = 0; + s32 width = 0, height = 0; pango_layout_get_pixel_size(layout, &width, &height); g_object_unref(layout); g_object_unref(context); diff --git a/hiro/gtk/keyboard.cpp b/hiro/gtk/keyboard.cpp index 85f5870a25..dcb26a37de 100644 --- a/hiro/gtk/keyboard.cpp +++ b/hiro/gtk/keyboard.cpp @@ -16,7 +16,7 @@ auto pKeyboard::poll() -> vector { return result; } -auto pKeyboard::pressed(uint code) -> bool { +auto pKeyboard::pressed(u32 code) -> bool { char state[256]; #if defined(DISPLAY_XORG) XQueryKeymap(pApplication::state().display, state); @@ -24,9 +24,9 @@ auto pKeyboard::pressed(uint code) -> bool { return _pressed(state, code); } -auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool { - uint8_t lo = code >> 0; - uint8_t hi = code >> 8; +auto pKeyboard::_pressed(const char* state, u16 code) -> bool { + u8 lo = code >> 0; + u8 hi = code >> 8; #if defined(DISPLAY_WINDOWS) if(lo && GetAsyncKeyState(lo) & 0x8000) return true; @@ -41,7 +41,7 @@ auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool { return false; } -auto pKeyboard::_translate(uint code) -> int { +auto pKeyboard::_translate(u32 code) -> s32 { switch(code) { case GDK_KEY_Escape: return 0; case GDK_KEY_F1: return 0; @@ -224,10 +224,10 @@ auto pKeyboard::_translate(uint code) -> int { } auto pKeyboard::initialize() -> void { - auto append = [](uint lo, uint hi = 0) { + auto append = [](u32 lo, u32 hi = 0) { #if defined(DISPLAY_XORG) - lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::state().display, lo) : 0; - hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::state().display, hi) : 0; + lo = lo ? (u8)XKeysymToKeycode(pApplication::state().display, lo) : 0; + hi = hi ? (u8)XKeysymToKeycode(pApplication::state().display, hi) : 0; #endif settings.keycodes.append(lo | (hi << 8)); }; diff --git a/hiro/gtk/keyboard.hpp b/hiro/gtk/keyboard.hpp index aa6a567237..5315c627c1 100644 --- a/hiro/gtk/keyboard.hpp +++ b/hiro/gtk/keyboard.hpp @@ -4,10 +4,10 @@ namespace hiro { struct pKeyboard { static auto poll() -> vector; - static auto pressed(uint code) -> bool; + static auto pressed(u32 code) -> bool; - static auto _pressed(const char* state, uint16_t code) -> bool; - static auto _translate(uint code) -> signed; + static auto _pressed(const char* state, u16 code) -> bool; + static auto _translate(u32 code) -> s32; static auto initialize() -> void; }; diff --git a/hiro/gtk/monitor.cpp b/hiro/gtk/monitor.cpp index 25e1ba8cde..cf430f5a4c 100644 --- a/hiro/gtk/monitor.cpp +++ b/hiro/gtk/monitor.cpp @@ -5,7 +5,7 @@ namespace hiro { -auto pMonitor::count() -> uint { +auto pMonitor::count() -> u32 { #if HIRO_GTK==2 || 1 return gdk_screen_get_n_monitors(gdk_screen_get_default()); #elif HIRO_GTK==3 @@ -13,7 +13,7 @@ auto pMonitor::count() -> uint { #endif } -auto pMonitor::dpi(uint monitor) -> Position { +auto pMonitor::dpi(u32 monitor) -> Position { #if HIRO_GTK==2 || 1 //GTK2 does not support either per-monitor or per-axis DPI reporting float dpi = round(gdk_screen_get_resolution(gdk_screen_get_default())); @@ -27,7 +27,7 @@ auto pMonitor::dpi(uint monitor) -> Position { #endif } -auto pMonitor::geometry(uint monitor) -> Geometry { +auto pMonitor::geometry(u32 monitor) -> Geometry { GdkRectangle rectangle = {}; #if HIRO_GTK==2 || 1 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), monitor, &rectangle); @@ -38,7 +38,7 @@ auto pMonitor::geometry(uint monitor) -> Geometry { return {rectangle.x, rectangle.y, rectangle.width, rectangle.height}; } -auto pMonitor::primary() -> uint { +auto pMonitor::primary() -> u32 { #if HIRO_GTK==2 || 1 return gdk_screen_get_primary_monitor(gdk_screen_get_default()); #elif HIRO_GTK==3 @@ -46,7 +46,7 @@ auto pMonitor::primary() -> uint { #endif } -auto pMonitor::workspace(uint monitor) -> Geometry { +auto pMonitor::workspace(u32 monitor) -> Geometry { #if HIRO_GTK==2 || 1 if(Monitor::count() == 1) { return Desktop::workspace(); diff --git a/hiro/gtk/monitor.hpp b/hiro/gtk/monitor.hpp index 1effa3dad3..3e0ef670bb 100644 --- a/hiro/gtk/monitor.hpp +++ b/hiro/gtk/monitor.hpp @@ -3,11 +3,11 @@ namespace hiro { struct pMonitor { - static auto count() -> uint; - static auto dpi(uint monitor) -> Position; - static auto geometry(uint monitor) -> Geometry; - static auto primary() -> uint; - static auto workspace(uint monitor) -> Geometry; + static auto count() -> u32; + static auto dpi(u32 monitor) -> Position; + static auto geometry(u32 monitor) -> Geometry; + static auto primary() -> u32; + static auto workspace(u32 monitor) -> Geometry; }; } diff --git a/hiro/gtk/mouse.cpp b/hiro/gtk/mouse.cpp index cb3e695635..be91e14d52 100644 --- a/hiro/gtk/mouse.cpp +++ b/hiro/gtk/mouse.cpp @@ -4,15 +4,15 @@ namespace hiro { auto pMouse::position() -> Position { #if defined(DISPLAY_WINDOWS) - POINT point{0}; + POINT point{}; GetCursorPos(&point); return {point.x, point.y}; #endif #if defined(DISPLAY_XORG) XlibWindow root, child; - int rootx, rooty, winx, winy; - uint mask; + s32 rootx, rooty, winx, winy; + u32 mask; XQueryPointer(pApplication::state().display, DefaultRootWindow(pApplication::state().display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); return {rootx, rooty}; #endif @@ -29,8 +29,8 @@ auto pMouse::pressed(Mouse::Button button) -> bool { #if defined(DISPLAY_XORG) XlibWindow root, child; - int rootx, rooty, winx, winy; - uint mask; + s32 rootx, rooty, winx, winy; + u32 mask; XQueryPointer(pApplication::state().display, DefaultRootWindow(pApplication::state().display), &root, &child, &rootx, &rooty, &winx, &winy, &mask); switch(button) { case Mouse::Button::Left: return mask & Button1Mask; diff --git a/hiro/gtk/popup-menu.hpp b/hiro/gtk/popup-menu.hpp index 2c44cf7f87..b1f8154384 100644 --- a/hiro/gtk/popup-menu.hpp +++ b/hiro/gtk/popup-menu.hpp @@ -8,7 +8,7 @@ struct pPopupMenu : pObject { auto append(sAction action) -> void; auto remove(sAction action) -> void; auto setFont(const Font& font) -> void override; - auto setVisible(bool visible) -> void; + auto setVisible(bool visible) -> void override; GtkWidget* gtkMenu = nullptr; }; diff --git a/hiro/gtk/settings.hpp b/hiro/gtk/settings.hpp index ed17252a2d..d120d60721 100644 --- a/hiro/gtk/settings.hpp +++ b/hiro/gtk/settings.hpp @@ -4,15 +4,15 @@ struct Settings { Settings(); ~Settings(); - vector keycodes; + vector keycodes; struct Geometry { - int frameX = 4; - int frameY = 24; - int frameWidth = 8; - int frameHeight = 28; - int menuHeight = 8; - int statusHeight = 4; + s32 frameX = 4; + s32 frameY = 24; + s32 frameWidth = 8; + s32 frameHeight = 28; + s32 menuHeight = 8; + s32 statusHeight = 4; } geometry; struct Theme { diff --git a/hiro/gtk/timer.cpp b/hiro/gtk/timer.cpp index fda75e705c..42ba51950b 100644 --- a/hiro/gtk/timer.cpp +++ b/hiro/gtk/timer.cpp @@ -30,7 +30,7 @@ auto pTimer::setEnabled(bool enabled) -> void { } } -auto pTimer::setInterval(uint interval) -> void { +auto pTimer::setInterval(u32 interval) -> void { } } diff --git a/hiro/gtk/timer.hpp b/hiro/gtk/timer.hpp index ce0d950d99..f8d1fca026 100644 --- a/hiro/gtk/timer.hpp +++ b/hiro/gtk/timer.hpp @@ -6,7 +6,7 @@ struct pTimer : pObject { Declare(Timer, Object) auto setEnabled(bool enabled) -> void override; - auto setInterval(uint interval) -> void; + auto setInterval(u32 interval) -> void; }; } diff --git a/hiro/gtk/utility.cpp b/hiro/gtk/utility.cpp index ab6886cf9b..a5bbf3074b 100644 --- a/hiro/gtk/utility.cpp +++ b/hiro/gtk/utility.cpp @@ -41,7 +41,7 @@ static auto DropPaths(GtkSelectionData* data) -> vector { if(uris == nullptr) return {}; vector paths; - for(uint n = 0; uris[n] != nullptr; n++) { + for(u32 n = 0; uris[n] != nullptr; n++) { gchar* pathname = g_filename_from_uri(uris[n], nullptr, nullptr); if(pathname == nullptr) continue; diff --git a/hiro/gtk/widget/canvas.cpp b/hiro/gtk/widget/canvas.cpp index 70a7f17863..630f1e202d 100644 --- a/hiro/gtk/widget/canvas.cpp +++ b/hiro/gtk/widget/canvas.cpp @@ -3,18 +3,18 @@ namespace hiro { //GTK3 -static auto Canvas_draw(GtkWidget* widget, cairo_t* context, pCanvas* p) -> int { +static auto Canvas_draw(GtkWidget* widget, cairo_t* context, pCanvas* p) -> s32 { p->_onDraw(context); return true; } //GTK2 -static auto Canvas_expose(GtkWidget* widget, GdkEventExpose* event, pCanvas* p) -> int { +static auto Canvas_expose(GtkWidget* widget, GdkEventExpose* event, pCanvas* p) -> s32 { p->_onExpose(event); return true; } -static auto Canvas_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* p) -> int { +static auto Canvas_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* p) -> s32 { //canvass that have been set focusable are intended for games. //to prevent arrow keys, tab, etc from losing focus on the game viewport, block key propagation here. if(p->self().focusable()) return true; @@ -23,7 +23,7 @@ static auto Canvas_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* p) return false; } -static auto Canvas_mousePress(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> int { +static auto Canvas_mousePress(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> s32 { //gtk_widget_set_focus_on_click() is a GTK 3.2+ feature. //implement this functionality manually for GTK 2.0+ compatibility. if(event->button == 1 && p->self().focusable()) gtk_widget_grab_focus(widget); @@ -78,7 +78,7 @@ auto pCanvas::handle() const -> uintptr { } auto pCanvas::minimumSize() const -> Size { - if(auto& icon = state().icon) return {(int)icon.width(), (int)icon.height()}; + if(auto& icon = state().icon) return {(s32)icon.width(), (s32)icon.height()}; return {0, 0}; } @@ -115,8 +115,8 @@ auto pCanvas::update() -> void { auto pCanvas::_onDraw(cairo_t* context) -> void { if(!surface) return; - int sx = 0, sy = 0, dx = 0, dy = 0; - int width = surfaceWidth, height = surfaceHeight; + s32 sx = 0, sy = 0, dx = 0, dy = 0; + s32 width = surfaceWidth, height = surfaceHeight; auto geometry = pSizable::state().geometry; auto alignment = state().alignment ? state().alignment : Alignment{0.5, 0.5}; @@ -152,8 +152,8 @@ auto pCanvas::_onExpose(GdkEventExpose* expose) -> void { } auto pCanvas::_rasterize() -> void { - int width = 0; - int height = 0; + s32 width = 0; + s32 height = 0; if(auto& icon = state().icon) { width = icon.width(); @@ -169,10 +169,10 @@ auto pCanvas::_rasterize() -> void { surfaceHeight = height; if(!surface) surface = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height); - auto buffer = (uint32_t*)gdk_pixbuf_get_pixels(surface); + auto buffer = (u32*)gdk_pixbuf_get_pixels(surface); if(auto& icon = state().icon) { - memory::copy(buffer, state().icon.data(), width * height); + memory::copy(buffer, state().icon.data(), width * height); } else if(auto& gradient = state().gradient) { auto& colors = gradient.state.colors; image fill; @@ -180,13 +180,13 @@ auto pCanvas::_rasterize() -> void { fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value()); memory::copy(buffer, fill.data(), fill.size()); } else { - uint32_t color = state().color.value(); + u32 color = state().color.value(); for(auto n : range(width * height)) buffer[n] = color; } //ARGB -> ABGR conversion for(auto n : range(width * height)) { - uint32_t color = *buffer; + u32 color = *buffer; color = (color & 0xff00ff00) | ((color & 0xff0000) >> 16) | ((color & 0x0000ff) << 16); *buffer++ = color; } diff --git a/hiro/gtk/widget/canvas.hpp b/hiro/gtk/widget/canvas.hpp index 2bae3ef9a3..15b662fe42 100644 --- a/hiro/gtk/widget/canvas.hpp +++ b/hiro/gtk/widget/canvas.hpp @@ -6,7 +6,7 @@ struct pCanvas : pWidget { Declare(Canvas, Widget) auto handle() const -> uintptr; - auto minimumSize() const -> Size; + auto minimumSize() const -> Size override; auto setAlignment(Alignment) -> void; auto setColor(Color color) -> void; auto setFocusable(bool focusable) -> void override; @@ -22,8 +22,8 @@ struct pCanvas : pWidget { auto _release() -> void; GdkPixbuf* surface = nullptr; - uint surfaceWidth = 0; - uint surfaceHeight = 0; + u32 surfaceWidth = 0; + u32 surfaceHeight = 0; }; } diff --git a/hiro/gtk/widget/check-label.hpp b/hiro/gtk/widget/check-label.hpp index 30375739d0..05cec40b16 100644 --- a/hiro/gtk/widget/check-label.hpp +++ b/hiro/gtk/widget/check-label.hpp @@ -5,7 +5,7 @@ namespace hiro { struct pCheckLabel : pWidget { Declare(CheckLabel, Widget) - auto minimumSize() const -> Size; + auto minimumSize() const -> Size override; auto setChecked(bool checked) -> void; auto setText(const string& text) -> void; }; diff --git a/hiro/gtk/widget/combo-button.cpp b/hiro/gtk/widget/combo-button.cpp index c51f33d55e..ed035d1be8 100644 --- a/hiro/gtk/widget/combo-button.cpp +++ b/hiro/gtk/widget/combo-button.cpp @@ -31,7 +31,7 @@ auto pComboButton::append(sComboButtonItem item) -> void { auto pComboButton::minimumSize() const -> Size { auto font = self().font(true); - int maximumWidth = 0; + s32 maximumWidth = 0; for(auto& item : state().items) { maximumWidth = max(maximumWidth, (item->state.icon ? pFont::size(font, " ").height() + 2 : 0) @@ -78,7 +78,7 @@ auto pComboButton::_append(sComboButtonItem item) -> void { auto pComboButton::_updateSelected() -> void { for(auto& item : state().items) item->state.selected = false; - int selected = gtk_combo_box_get_active(gtkComboBox); + s32 selected = gtk_combo_box_get_active(gtkComboBox); if(selected >= 0) { if(auto item = self().item(selected)) { item->state.selected = true; diff --git a/hiro/gtk/widget/combo-button.hpp b/hiro/gtk/widget/combo-button.hpp index ad076ad829..86210f7138 100644 --- a/hiro/gtk/widget/combo-button.hpp +++ b/hiro/gtk/widget/combo-button.hpp @@ -8,7 +8,7 @@ struct pComboButton : pWidget { auto append(sComboButtonItem item) -> void; auto minimumSize() const -> Size override; auto remove(sComboButtonItem item) -> void; - auto reset() -> void; + auto reset() -> void override; auto setFont(const Font& font) -> void override; auto _append(sComboButtonItem item) -> void; diff --git a/hiro/gtk/widget/combo-edit.cpp b/hiro/gtk/widget/combo-edit.cpp index f90dae4f2f..f5aef58bfe 100644 --- a/hiro/gtk/widget/combo-edit.cpp +++ b/hiro/gtk/widget/combo-edit.cpp @@ -23,8 +23,8 @@ auto pComboEdit::construct() -> void { //however, this API call throws a Gtk-CRITICAL assertion that column 1 is not a cell renderer //this is, however, incorrect. it *is* a renderer, and the API call works as expected //so in order to suppress the error message, we redirect stderr to /dev/null temporarily - int stdErr = dup(STDERR_FILENO); - int devNull = open("/dev/null", 0); + s32 stdErr = dup(STDERR_FILENO); + s32 devNull = open("/dev/null", 0); dup2(devNull, STDERR_FILENO); gtk_combo_box_set_entry_text_column(gtkComboBox, 1); dup2(stdErr, STDERR_FILENO); @@ -58,7 +58,7 @@ auto pComboEdit::append(sComboEditItem item) -> void { auto pComboEdit::minimumSize() const -> Size { auto font = self().font(true); - int maximumWidth = 0; + s32 maximumWidth = 0; for(auto& item : state().items) { maximumWidth = max(maximumWidth, (item->state.icon ? pFont::size(font, " ").height() + 2 : 0) diff --git a/hiro/gtk/widget/combo-edit.hpp b/hiro/gtk/widget/combo-edit.hpp index f5d48116e5..124fde98d5 100644 --- a/hiro/gtk/widget/combo-edit.hpp +++ b/hiro/gtk/widget/combo-edit.hpp @@ -8,7 +8,7 @@ struct pComboEdit : pWidget { auto append(sComboEditItem item) -> void; auto minimumSize() const -> Size override; auto remove(sComboEditItem item) -> void; - auto reset() -> void; + auto reset() -> void override; auto setBackgroundColor(Color color) -> void; auto setEditable(bool editable) -> void; auto setForegroundColor(Color color) -> void; diff --git a/hiro/gtk/widget/console.cpp b/hiro/gtk/widget/console.cpp index 59360b8dcd..29fa9c21f7 100644 --- a/hiro/gtk/widget/console.cpp +++ b/hiro/gtk/widget/console.cpp @@ -2,7 +2,7 @@ namespace hiro { -static auto Console_keyPress(GtkWidget*, GdkEventKey* event, pConsole* p) -> int { +static auto Console_keyPress(GtkWidget*, GdkEventKey* event, pConsole* p) -> s32 { return p->_keyPress(event->keyval, event->state); } @@ -67,7 +67,7 @@ auto pConsole::setPrompt(const string& prompt) -> void { _seekToEnd(); } -auto pConsole::_keyPress(uint scancode, uint mask) -> bool { +auto pConsole::_keyPress(u32 scancode, u32 mask) -> bool { if(mask & (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK)) return false; //allow actions such as Ctrl+C (copy) GtkTextMark* mark = gtk_text_buffer_get_mark(textBuffer, "insert"); diff --git a/hiro/gtk/widget/console.hpp b/hiro/gtk/widget/console.hpp index b5bbbbccc2..efa246c554 100644 --- a/hiro/gtk/widget/console.hpp +++ b/hiro/gtk/widget/console.hpp @@ -6,12 +6,12 @@ struct pConsole : pWidget { Declare(Console, Widget) auto print(const string& text) -> void; - auto reset() -> void; + auto reset() -> void override; auto setBackgroundColor(Color color) -> void; auto setForegroundColor(Color color) -> void; auto setPrompt(const string& prompt) -> void; - auto _keyPress(uint scancode, uint mask) -> bool; + auto _keyPress(u32 scancode, u32 mask) -> bool; auto _seekToEnd() -> void; auto _seekToMark() -> void; @@ -19,7 +19,7 @@ struct pConsole : pWidget { GtkTextBuffer* textBuffer = nullptr; string previousPrompt; vector history; - uint historyOffset = 0; + u32 historyOffset = 0; }; } diff --git a/hiro/gtk/widget/hex-edit.cpp b/hiro/gtk/widget/hex-edit.cpp index 29dcf7c022..d0286322ed 100644 --- a/hiro/gtk/widget/hex-edit.cpp +++ b/hiro/gtk/widget/hex-edit.cpp @@ -2,12 +2,12 @@ namespace hiro { -static auto HexEdit_keyPress(GtkWidget* widget, GdkEventKey* event, pHexEdit* p) -> int { +static auto HexEdit_keyPress(GtkWidget* widget, GdkEventKey* event, pHexEdit* p) -> s32 { return p->keyPress(event->keyval, event->state); } -static auto HexEdit_mouseScroll(GtkWidget* widget, GdkEventScroll* event, pHexEdit* p) -> int { - double position = gtk_range_get_value(GTK_RANGE(p->scrollBar)); +static auto HexEdit_mouseScroll(GtkWidget* widget, GdkEventScroll* event, pHexEdit* p) -> s32 { + f64 position = gtk_range_get_value(GTK_RANGE(p->scrollBar)); if(event->direction == GDK_SCROLL_UP) { p->scroll(position - 1); @@ -20,8 +20,8 @@ static auto HexEdit_mouseScroll(GtkWidget* widget, GdkEventScroll* event, pHexEd return true; //do not propagate event further } -static auto HexEdit_scroll(GtkRange* range, GtkScrollType scroll, double value, pHexEdit* p) -> int { - p->scroll((int)value); +static auto HexEdit_scroll(GtkRange* range, GtkScrollType scroll, f64 value, pHexEdit* p) -> s32 { + p->scroll((s32)value); return true; //do not propagate event further } @@ -88,7 +88,7 @@ auto pHexEdit::focused() const -> bool { return gtk_widget_has_focus(subWidget) || gtk_widget_has_focus(scrollBar); } -auto pHexEdit::setAddress(uint address) -> void { +auto pHexEdit::setAddress(u32 address) -> void { setScroll(); updateScroll(); update(); @@ -99,7 +99,7 @@ auto pHexEdit::setBackgroundColor(Color color) -> void { gtk_widget_modify_base(subWidget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr); } -auto pHexEdit::setColumns(uint columns) -> void { +auto pHexEdit::setColumns(u32 columns) -> void { setScroll(); update(); } @@ -109,12 +109,12 @@ auto pHexEdit::setForegroundColor(Color color) -> void { gtk_widget_modify_text(subWidget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr); } -auto pHexEdit::setLength(uint length) -> void { +auto pHexEdit::setLength(u32 length) -> void { setScroll(); update(); } -auto pHexEdit::setRows(uint rows) -> void { +auto pHexEdit::setRows(u32 rows) -> void { setScroll(); update(); } @@ -125,10 +125,10 @@ auto pHexEdit::update() -> void { return; } - uint position = cursorPosition(); + u32 position = cursorPosition(); string output; - uint address = state().address; + u32 address = state().address; for(auto row : range(state().rows)) { output.append(hex(address, 8L)); output.append(" "); @@ -137,7 +137,7 @@ auto pHexEdit::update() -> void { string ansidata = " "; for(auto column : range(state().columns)) { if(address < state().length) { - uint8_t data = self().doRead(address++); + u8 data = self().doRead(address++); hexdata.append(hex(data, 2L)); hexdata.append(" "); ansidata.append(data >= 0x20 && data <= 0x7e ? (char)data : '.'); @@ -158,21 +158,21 @@ auto pHexEdit::update() -> void { setCursorPosition(position); } -auto pHexEdit::cursorPosition() -> uint { +auto pHexEdit::cursorPosition() -> u32 { GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); return gtk_text_iter_get_offset(&iter); } -auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { +auto pHexEdit::keyPress(u32 scancode, u32 mask) -> bool { if(!state().onRead) return false; if(mask & (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK)) return false; //allow actions such as Ctrl+C (copy) - int position = cursorPosition(); - int lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 1; - int cursorY = position / lineWidth; - int cursorX = position % lineWidth; + s32 position = cursorPosition(); + s32 lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 1; + s32 cursorY = position / lineWidth; + s32 cursorX = position % lineWidth; if(scancode == GDK_KEY_Home) { setCursorPosition(cursorY * lineWidth + 10); @@ -187,7 +187,7 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { if(scancode == GDK_KEY_Up) { if(cursorY != 0) return false; - int newAddress = state().address - state().columns; + s32 newAddress = state().address - state().columns; if(newAddress >= 0) { self().setAddress(newAddress); update(); @@ -199,7 +199,7 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { if(cursorY >= rows() - 1) return true; if(cursorY != state().rows - 1) return false; - int newAddress = state().address + state().columns; + s32 newAddress = state().address + state().columns; if(newAddress + state().columns * state().rows - (state().columns - 1) <= state().length) { self().setAddress(newAddress); update(); @@ -208,7 +208,7 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { } if(scancode == GDK_KEY_Page_Up) { - int newAddress = state().address - state().columns * state().rows; + s32 newAddress = state().address - state().columns * state().rows; if(newAddress >= 0) { self().setAddress(newAddress); } else { @@ -219,7 +219,7 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { } if(scancode == GDK_KEY_Page_Down) { - int newAddress = state().address + state().columns * state().rows; + s32 newAddress = state().address + state().columns * state().rows; for(auto n : range(state().rows)) { if(newAddress + state().columns * state().rows - (state().columns - 1) <= state().length) { self().setAddress(newAddress); @@ -246,10 +246,10 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { cursorX /= 3; if(cursorX < state().columns) { //not in ANSI region - uint address = state().address + (cursorY * state().columns + cursorX); + u32 address = state().address + (cursorY * state().columns + cursorX); if(address >= state().length) return false; //do not edit past end of data - uint8_t data = self().doRead(address); + u8 data = self().doRead(address); //write modified value if(cursorNibble == 1) { @@ -274,29 +274,29 @@ auto pHexEdit::keyPress(uint scancode, uint mask) -> bool { } //number of actual rows -auto pHexEdit::rows() -> int { +auto pHexEdit::rows() -> s32 { return (max(1u, state().length) + state().columns - 1) / state().columns; } //number of scrollable row positions -auto pHexEdit::rowsScrollable() -> int { +auto pHexEdit::rowsScrollable() -> s32 { return max(0u, rows() - state().rows); } -auto pHexEdit::scroll(int position) -> void { +auto pHexEdit::scroll(s32 position) -> void { if(position > rowsScrollable()) position = rowsScrollable(); if(position < 0) position = 0; self().setAddress(position * state().columns); } -auto pHexEdit::setCursorPosition(uint position) -> void { +auto pHexEdit::setCursorPosition(u32 position) -> void { GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor); //GTK+ will throw many errors to the terminal if you set iterator past end of buffer GtkTextIter endIter; gtk_text_buffer_get_end_iter(textBuffer, &iter); - uint endPosition = gtk_text_iter_get_offset(&iter); + u32 endPosition = gtk_text_iter_get_offset(&iter); gtk_text_iter_set_offset(&iter, min(position, endPosition)); gtk_text_buffer_place_cursor(textBuffer, &iter); @@ -312,7 +312,7 @@ auto pHexEdit::setScroll() -> void { } auto pHexEdit::updateScroll() -> void { - uint row = state().address / state().columns; + u32 row = state().address / state().columns; gtk_range_set_value(GTK_RANGE(scrollBar), row); } diff --git a/hiro/gtk/widget/hex-edit.hpp b/hiro/gtk/widget/hex-edit.hpp index 42875c6fbe..d4b92eeb35 100644 --- a/hiro/gtk/widget/hex-edit.hpp +++ b/hiro/gtk/widget/hex-edit.hpp @@ -6,20 +6,20 @@ struct pHexEdit : pWidget { Declare(HexEdit, Widget) auto focused() const -> bool override; - auto setAddress(uint address) -> void; + auto setAddress(u32 address) -> void; auto setBackgroundColor(Color color) -> void; - auto setColumns(uint columns) -> void; + auto setColumns(u32 columns) -> void; auto setForegroundColor(Color color) -> void; - auto setLength(uint length) -> void; - auto setRows(uint rows) -> void; + auto setLength(u32 length) -> void; + auto setRows(u32 rows) -> void; auto update() -> void; - auto cursorPosition() -> uint; - auto keyPress(uint scancode, uint mask) -> bool; - auto rows() -> int; - auto rowsScrollable() -> int; - auto scroll(int position) -> void; - auto setCursorPosition(uint position) -> void; + auto cursorPosition() -> u32; + auto keyPress(u32 scancode, u32 mask) -> bool; + auto rows() -> s32; + auto rowsScrollable() -> s32; + auto scroll(s32 position) -> void; + auto setCursorPosition(u32 position) -> void; auto setScroll() -> void; auto updateScroll() -> void; diff --git a/hiro/gtk/widget/horizontal-scroll-bar.cpp b/hiro/gtk/widget/horizontal-scroll-bar.cpp index 5a3e35aed3..c15207f2e0 100644 --- a/hiro/gtk/widget/horizontal-scroll-bar.cpp +++ b/hiro/gtk/widget/horizontal-scroll-bar.cpp @@ -3,7 +3,7 @@ namespace hiro { static auto HorizontalScrollBar_change(GtkRange* gtkRange, pHorizontalScrollBar* p) -> void { - auto position = (uint)gtk_range_get_value(gtkRange); + auto position = (u32)gtk_range_get_value(gtkRange); if(p->state().position == position) return; p->state().position = position; if(!p->locked()) p->self().doChange(); @@ -32,14 +32,14 @@ auto pHorizontalScrollBar::minimumSize() const -> Size { return {0, 20}; } -auto pHorizontalScrollBar::setLength(uint length) -> void { +auto pHorizontalScrollBar::setLength(u32 length) -> void { auto lock = acquire(); length += length == 0; gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); } -auto pHorizontalScrollBar::setPosition(uint position) -> void { +auto pHorizontalScrollBar::setPosition(u32 position) -> void { gtk_range_set_value(GTK_RANGE(gtkWidget), position); } diff --git a/hiro/gtk/widget/horizontal-scroll-bar.hpp b/hiro/gtk/widget/horizontal-scroll-bar.hpp index 9654fd1e33..610d574334 100644 --- a/hiro/gtk/widget/horizontal-scroll-bar.hpp +++ b/hiro/gtk/widget/horizontal-scroll-bar.hpp @@ -5,9 +5,9 @@ namespace hiro { struct pHorizontalScrollBar : pWidget { Declare(HorizontalScrollBar, Widget) - auto minimumSize() const -> Size; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto minimumSize() const -> Size override; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/gtk/widget/horizontal-slider.cpp b/hiro/gtk/widget/horizontal-slider.cpp index b26e0acaf6..c08c47255f 100644 --- a/hiro/gtk/widget/horizontal-slider.cpp +++ b/hiro/gtk/widget/horizontal-slider.cpp @@ -3,7 +3,7 @@ namespace hiro { static auto HorizontalSlider_change(GtkRange* gtkRange, pHorizontalSlider* p) -> void { - auto position = (uint)gtk_range_get_value(gtkRange); + auto position = (u32)gtk_range_get_value(gtkRange); if(p->state().position == position) return; p->state().position = position; if(!p->locked()) p->self().doChange(); @@ -33,13 +33,13 @@ auto pHorizontalSlider::minimumSize() const -> Size { return {3, 20}; } -auto pHorizontalSlider::setLength(uint length) -> void { +auto pHorizontalSlider::setLength(u32 length) -> void { length += length == 0; gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); } -auto pHorizontalSlider::setPosition(uint position) -> void { +auto pHorizontalSlider::setPosition(u32 position) -> void { gtk_range_set_value(GTK_RANGE(gtkWidget), position); } diff --git a/hiro/gtk/widget/horizontal-slider.hpp b/hiro/gtk/widget/horizontal-slider.hpp index 20cd16a75d..cace71bba8 100644 --- a/hiro/gtk/widget/horizontal-slider.hpp +++ b/hiro/gtk/widget/horizontal-slider.hpp @@ -6,8 +6,8 @@ struct pHorizontalSlider : pWidget { Declare(HorizontalSlider, Widget) auto minimumSize() const -> Size override; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/gtk/widget/icon-view.cpp b/hiro/gtk/widget/icon-view.cpp index 7eedb19e9e..fad5e32241 100644 --- a/hiro/gtk/widget/icon-view.cpp +++ b/hiro/gtk/widget/icon-view.cpp @@ -6,7 +6,7 @@ static auto IconView_activate(GtkIconView* iconView, GtkTreePath* path, pIconVie if(!p->locked()) p->self().doActivate(); } -static auto IconView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pIconView* p) -> int { +static auto IconView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pIconView* p) -> s32 { if(event->type == GDK_BUTTON_RELEASE && event->button == 3) { if(!p->locked()) p->self().doContext(); return false; @@ -121,7 +121,7 @@ auto pIconView::setGeometry(Geometry geometry) -> void { } } -auto pIconView::setItemIcon(uint position, const image& icon) -> void { +auto pIconView::setItemIcon(u32 position, const image& icon) -> void { if(position >= self().itemCount()) return; GtkTreeIter iter; if(gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, string{position})) { @@ -134,7 +134,7 @@ auto pIconView::setItemIcon(uint position, const image& icon) -> void { } } -auto pIconView::setItemSelected(uint position, bool selected) -> void { +auto pIconView::setItemSelected(u32 position, bool selected) -> void { if(position >= self().itemCount()) return; lock(); GtkTreePath* path = gtk_tree_path_new_from_string(string{position}); @@ -148,7 +148,7 @@ auto pIconView::setItemSelected(uint position, bool selected) -> void { unlock(); } -auto pIconView::setItemSelected(const vector& selections) -> void { +auto pIconView::setItemSelected(const vector& selections) -> void { lock(); setItemSelectedNone(); for(auto& position : selections) setItemSelected(position, true); @@ -170,7 +170,7 @@ auto pIconView::setItemSelectedNone() -> void { unlock(); } -auto pIconView::setItemText(uint position, const string& text) -> void { +auto pIconView::setItemText(u32 position, const string& text) -> void { if(position >= self().itemCount()) return; GtkTreeIter iter; if(gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, string{position})) { @@ -185,7 +185,7 @@ auto pIconView::setOrientation(Orientation orientation) -> void { } auto pIconView::_updateSelected() -> void { - vector selected; + vector selected; GList* list = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(subWidget)); GList* p = list; @@ -193,7 +193,7 @@ auto pIconView::_updateSelected() -> void { while(p) { auto path = (GtkTreePath*)p->data; char* pathString = gtk_tree_path_to_string(path); - uint position = toNatural(pathString); + u32 position = toNatural(pathString); g_free(pathString); selected.append(position); p = p->next; @@ -204,7 +204,7 @@ auto pIconView::_updateSelected() -> void { bool identical = selected.size() == currentSelection.size(); if(identical) { - for(uint n = 0; n < selected.size(); n++) { + for(u32 n = 0; n < selected.size(); n++) { if(selected[n] != currentSelection[n]) { identical = false; break; diff --git a/hiro/gtk/widget/icon-view.hpp b/hiro/gtk/widget/icon-view.hpp index 6eb46e82e7..f69cee0ca6 100644 --- a/hiro/gtk/widget/icon-view.hpp +++ b/hiro/gtk/widget/icon-view.hpp @@ -7,25 +7,25 @@ struct pIconView : pWidget { auto append(sIconViewItem item) -> void; auto remove(sIconViewItem item) -> void; - auto reset() -> void; + auto reset() -> void override; auto setBackgroundColor(Color color) -> void; auto setBatchable(bool batchable) -> void; auto setFlow(Orientation flow) -> void; auto setForegroundColor(Color color) -> void; - auto setGeometry(Geometry geometry) -> void; - auto setItemIcon(uint position, const image& icon) -> void; - auto setItemSelected(uint position, bool selected) -> void; - auto setItemSelected(const vector& selections) -> void; + auto setGeometry(Geometry geometry) -> void override; + auto setItemIcon(u32 position, const image& icon) -> void; + auto setItemSelected(u32 position, bool selected) -> void; + auto setItemSelected(const vector& selections) -> void; auto setItemSelectedAll() -> void; auto setItemSelectedNone() -> void; - auto setItemText(uint position, const string& text) -> void; + auto setItemText(u32 position, const string& text) -> void; auto setOrientation(Orientation orientation) -> void; auto _updateSelected() -> void; GtkWidget* subWidget = nullptr; GtkListStore* store = nullptr; - vector currentSelection; + vector currentSelection; }; } diff --git a/hiro/gtk/widget/label.cpp b/hiro/gtk/widget/label.cpp index 7f3c3c07a3..56806f8de4 100644 --- a/hiro/gtk/widget/label.cpp +++ b/hiro/gtk/widget/label.cpp @@ -2,17 +2,17 @@ namespace hiro { -static auto Label_draw(GtkWidget* widget, cairo_t* context, pLabel* p) -> int { +static auto Label_draw(GtkWidget* widget, cairo_t* context, pLabel* p) -> s32 { auto color = p->state().backgroundColor; if(auto window = p->self().parentWindow(true)) { if(!color) color = window->backgroundColor(); } if(color) { - double red = (double)color.red() / 255.0; - double green = (double)color.green() / 255.0; - double blue = (double)color.blue() / 255.0; - double alpha = (double)color.alpha() / 255.0; + f64 red = (f64)color.red() / 255.0; + f64 green = (f64)color.green() / 255.0; + f64 blue = (f64)color.blue() / 255.0; + f64 alpha = (f64)color.alpha() / 255.0; if(gdk_screen_is_composited(gdk_screen_get_default()) && gdk_screen_get_rgba_visual(gdk_screen_get_default()) @@ -39,24 +39,24 @@ static auto Label_draw(GtkWidget* widget, cairo_t* context, pLabel* p) -> int { return false; } -static auto Label_expose(GtkWidget* widget, GdkEvent* event, pLabel* p) -> int { +static auto Label_expose(GtkWidget* widget, GdkEvent* event, pLabel* p) -> s32 { cairo_t* context = gdk_cairo_create(gtk_widget_get_window(widget)); Label_draw(widget, context, p); cairo_destroy(context); return false; } -static auto Label_mouseEnter(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> int { +static auto Label_mouseEnter(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> s32 { Widget_mouseEnter(widget, event, p); return true; } -static auto Label_mouseLeave(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> int { +static auto Label_mouseLeave(GtkWidget* widget, GdkEventButton* event, pCanvas* p) -> s32 { Widget_mouseLeave(widget, event, p); return true; } -static auto Label_mousePress(GtkWidget* widget, GdkEventButton* event, pLabel* p) -> int { +static auto Label_mousePress(GtkWidget* widget, GdkEventButton* event, pLabel* p) -> s32 { switch(event->button) { case 1: p->self().doMousePress(Mouse::Button::Left); break; case 2: p->self().doMousePress(Mouse::Button::Middle); break; @@ -65,7 +65,7 @@ static auto Label_mousePress(GtkWidget* widget, GdkEventButton* event, pLabel* p return true; } -static auto Label_mouseRelease(GtkWidget* widget, GdkEventButton* event, pLabel* p) -> int { +static auto Label_mouseRelease(GtkWidget* widget, GdkEventButton* event, pLabel* p) -> s32 { switch(event->button) { case 1: p->self().doMouseRelease(Mouse::Button::Left); break; case 2: p->self().doMouseRelease(Mouse::Button::Middle); break; diff --git a/hiro/gtk/widget/line-edit.hpp b/hiro/gtk/widget/line-edit.hpp index 591fe14155..465381c3af 100644 --- a/hiro/gtk/widget/line-edit.hpp +++ b/hiro/gtk/widget/line-edit.hpp @@ -5,7 +5,7 @@ namespace hiro { struct pLineEdit : pWidget { Declare(LineEdit, Widget) - auto minimumSize() const -> Size; + auto minimumSize() const -> Size override; auto setBackgroundColor(Color color) -> void; auto setEditable(bool editable) -> void; auto setForegroundColor(Color color) -> void; diff --git a/hiro/gtk/widget/progress-bar.cpp b/hiro/gtk/widget/progress-bar.cpp index 8ed74b517f..70cdee2c44 100644 --- a/hiro/gtk/widget/progress-bar.cpp +++ b/hiro/gtk/widget/progress-bar.cpp @@ -18,9 +18,9 @@ auto pProgressBar::minimumSize() const -> Size { return {0, 25}; } -auto pProgressBar::setPosition(uint position) -> void { +auto pProgressBar::setPosition(u32 position) -> void { position = position <= 100 ? position : 0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (double)position / 100.0); + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (f64)position / 100.0); } } diff --git a/hiro/gtk/widget/progress-bar.hpp b/hiro/gtk/widget/progress-bar.hpp index 3e647c4aab..32cdf3a0d9 100644 --- a/hiro/gtk/widget/progress-bar.hpp +++ b/hiro/gtk/widget/progress-bar.hpp @@ -5,8 +5,8 @@ namespace hiro { struct pProgressBar : pWidget { Declare(ProgressBar, Widget) - auto minimumSize() const -> Size; - auto setPosition(uint position) -> void; + auto minimumSize() const -> Size override; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/gtk/widget/radio-button.hpp b/hiro/gtk/widget/radio-button.hpp index 2be014dd5b..8117d4ccd3 100644 --- a/hiro/gtk/widget/radio-button.hpp +++ b/hiro/gtk/widget/radio-button.hpp @@ -5,7 +5,7 @@ namespace hiro { struct pRadioButton : pWidget { Declare(RadioButton, Widget) - auto minimumSize() const -> Size; + auto minimumSize() const -> Size override; auto setBordered(bool bordered) -> void; auto setChecked() -> void; auto setGroup(sGroup group) -> void; diff --git a/hiro/gtk/widget/radio-label.hpp b/hiro/gtk/widget/radio-label.hpp index 25bb71b43f..61363e4b3b 100644 --- a/hiro/gtk/widget/radio-label.hpp +++ b/hiro/gtk/widget/radio-label.hpp @@ -5,7 +5,7 @@ namespace hiro { struct pRadioLabel : pWidget { Declare(RadioLabel, Widget) - auto minimumSize() const -> Size; + auto minimumSize() const -> Size override; auto setChecked() -> void; auto setGroup(sGroup group) -> void; auto setText(const string& text) -> void; diff --git a/hiro/gtk/widget/source-edit.cpp b/hiro/gtk/widget/source-edit.cpp index fd363b1f4a..debc851564 100644 --- a/hiro/gtk/widget/source-edit.cpp +++ b/hiro/gtk/widget/source-edit.cpp @@ -112,7 +112,7 @@ auto pSourceEdit::setTextCursor(TextCursor cursor) -> void { GtkTextIter offset, length; gtk_text_buffer_get_end_iter(gtkTextBuffer, &offset); gtk_text_buffer_get_end_iter(gtkTextBuffer, &length); - int end = gtk_text_iter_get_offset(&offset); + s32 end = gtk_text_iter_get_offset(&offset); gtk_text_iter_set_offset(&offset, max(0, min(end, cursor.offset()))); gtk_text_iter_set_offset(&length, max(0, min(end, cursor.offset() + cursor.length()))); gtk_text_buffer_select_range(gtkTextBuffer, &offset, &length); @@ -141,16 +141,16 @@ auto pSourceEdit::text() const -> string { auto pSourceEdit::textCursor() const -> TextCursor { TextCursor cursor; - int offset = 0; + s32 offset = 0; g_object_get(G_OBJECT(gtkSourceBuffer), "cursor-position", &offset, nullptr); cursor.setOffset(offset); GtkTextIter start, end; if(gtk_text_buffer_get_selection_bounds(gtkTextBuffer, &start, &end)) { //if selecting text from left to right, the cursor may be ahead of the selection start ... //since hiro combines selection bounds (end-start) into length, move the offset to the start - int origin = gtk_text_iter_get_offset(&start); + s32 origin = gtk_text_iter_get_offset(&start); cursor.setOffset(origin); - int length = gtk_text_iter_get_offset(&end) - origin; + s32 length = gtk_text_iter_get_offset(&end) - origin; cursor.setLength(length); } return cursor; diff --git a/hiro/gtk/widget/tab-frame.cpp b/hiro/gtk/widget/tab-frame.cpp index bdaa01d4b7..f8e408a2e0 100644 --- a/hiro/gtk/widget/tab-frame.cpp +++ b/hiro/gtk/widget/tab-frame.cpp @@ -2,7 +2,7 @@ namespace hiro { -static auto TabFrame_change(GtkNotebook* notebook, GtkWidget* page, uint position, pTabFrame* p) -> void { +static auto TabFrame_change(GtkNotebook* notebook, GtkWidget* page, u32 position, pTabFrame* p) -> void { for(auto& item : p->state().items) item->state.selected = false; if(auto item = p->self().item(position)) item->state.selected = true; @@ -11,7 +11,7 @@ static auto TabFrame_change(GtkNotebook* notebook, GtkWidget* page, uint positio } static auto TabFrame_close(GtkButton* button, pTabFrame* p) -> void { - maybe position; + maybe position; for(auto n : range(p->tabs.size())) { if(button == (GtkButton*)p->tabs[n].close) { position = n; @@ -23,12 +23,12 @@ static auto TabFrame_close(GtkButton* button, pTabFrame* p) -> void { } } -static auto TabFrame_move(GtkNotebook* notebook, GtkWidget* page, uint moveTo, pTabFrame* p) -> void { - uint position = gtk_notebook_get_current_page(notebook); +static auto TabFrame_move(GtkNotebook* notebook, GtkWidget* page, u32 moveTo, pTabFrame* p) -> void { + u32 position = gtk_notebook_get_current_page(notebook); for(auto& item : p->state().items) item->state.selected = false; if(auto item = p->self().item(position)) item->state.selected = true; - maybe moveFrom; + maybe moveFrom; for(auto n : range(p->tabs.size())) { if(page == p->tabs[n].child) { moveFrom = n; @@ -83,7 +83,7 @@ auto pTabFrame::container(mWidget& widget) -> GtkWidget* { break; } - uint position = 0; + u32 position = 0; for(auto& item : state().items) { if(item->state.sizable.data() == object) return tabs[position].child; position++; @@ -97,7 +97,7 @@ auto pTabFrame::remove(sTabFrameItem item) -> void { //if we are removing the current tab, we have to select another tab manually if(item->offset() == gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkWidget))) { //the new tab will be the one after this one - uint displacement = 1; + u32 displacement = 1; //... unless it's the last tab, in which case it's the one before it if(item->offset() == self().itemCount() - 1) displacement = -1; //... unless there are no tabs left, in which case nothing is selected @@ -108,7 +108,7 @@ auto pTabFrame::remove(sTabFrameItem item) -> void { tabs.remove(item->offset()); gtk_notebook_remove_page(GTK_NOTEBOOK(gtkWidget), item->offset()); - uint position = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkWidget)); + u32 position = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkWidget)); for(auto& item : state().items) item->state.selected = false; if(auto item = self().item(position)) item->state.selected = true; unlock(); @@ -140,31 +140,31 @@ auto pTabFrame::setGeometry(Geometry geometry) -> void { } } -auto pTabFrame::setItemClosable(uint position, bool closable) -> void { +auto pTabFrame::setItemClosable(u32 position, bool closable) -> void { _synchronizeTab(position); } -auto pTabFrame::setItemIcon(uint position, const image& icon) -> void { +auto pTabFrame::setItemIcon(u32 position, const image& icon) -> void { _synchronizeTab(position); } -auto pTabFrame::setItemMovable(uint position, bool movable) -> void { +auto pTabFrame::setItemMovable(u32 position, bool movable) -> void { lock(); gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gtkWidget), tabs[position].child, movable); unlock(); } -auto pTabFrame::setItemSelected(uint position) -> void { +auto pTabFrame::setItemSelected(u32 position) -> void { lock(); gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkWidget), position); unlock(); } -auto pTabFrame::setItemSizable(uint position, sSizable sizable) -> void { +auto pTabFrame::setItemSizable(u32 position, sSizable sizable) -> void { //if(layout->self()) layout->self()->setParent(); } -auto pTabFrame::setItemText(uint position, const string& text) -> void { +auto pTabFrame::setItemText(u32 position, const string& text) -> void { _synchronizeTab(position); } @@ -226,12 +226,12 @@ auto pTabFrame::_synchronizeLayout() -> void { } } -auto pTabFrame::_synchronizeTab(uint position) -> void { +auto pTabFrame::_synchronizeTab(u32 position) -> void { auto& item = state().items[position]; auto& tab = tabs[position]; gtk_widget_set_visible(tab.close, item->closable()); if(auto& icon = item->state.icon) { - uint size = pFont::size(self().font(true), " ").height(); + u32 size = pFont::size(self().font(true), " ").height(); auto pixbuf = CreatePixbuf(icon, true); gtk_image_set_from_pixbuf(GTK_IMAGE(tab.image), pixbuf); } else { @@ -246,8 +246,8 @@ auto pTabFrame::_synchronizeTab(uint position) -> void { } //compute the height of the tallest tab for child layout geometry calculations -auto pTabFrame::_tabHeight() -> uint { - int height = 1; +auto pTabFrame::_tabHeight() -> u32 { + s32 height = 1; for(auto n : range(self().itemCount())) { GtkAllocation imageAllocation, titleAllocation, closeAllocation; @@ -263,8 +263,8 @@ auto pTabFrame::_tabHeight() -> uint { return height; } -auto pTabFrame::_tabWidth() -> uint { - int width = 1; +auto pTabFrame::_tabWidth() -> u32 { + s32 width = 1; for(auto n : range(self().itemCount())) { GtkAllocation imageAllocation, titleAllocation, closeAllocation; diff --git a/hiro/gtk/widget/tab-frame.hpp b/hiro/gtk/widget/tab-frame.hpp index 53a31a1648..5c94a298dc 100644 --- a/hiro/gtk/widget/tab-frame.hpp +++ b/hiro/gtk/widget/tab-frame.hpp @@ -10,19 +10,19 @@ struct pTabFrame : pWidget { auto remove(sTabFrameItem item) -> void; auto setFont(const Font& font) -> void override; auto setGeometry(Geometry geometry) -> void override; - auto setItemClosable(uint position, bool closable) -> void; - auto setItemIcon(uint position, const image& icon) -> void; - auto setItemMovable(uint position, bool movable) -> void; - auto setItemSelected(uint position) -> void; - auto setItemSizable(uint position, sSizable sizable) -> void; - auto setItemText(uint position, const string& text) -> void; + auto setItemClosable(u32 position, bool closable) -> void; + auto setItemIcon(u32 position, const image& icon) -> void; + auto setItemMovable(u32 position, bool movable) -> void; + auto setItemSelected(u32 position) -> void; + auto setItemSizable(u32 position, sSizable sizable) -> void; + auto setItemText(u32 position, const string& text) -> void; auto setNavigation(Navigation navigation) -> void; auto _append() -> void; auto _synchronizeLayout() -> void; - auto _synchronizeTab(uint position) -> void; - auto _tabHeight() -> uint; - auto _tabWidth() -> uint; + auto _synchronizeTab(u32 position) -> void; + auto _tabHeight() -> u32; + auto _tabWidth() -> u32; struct Tab { GtkWidget* child = nullptr; diff --git a/hiro/gtk/widget/table-view-column.cpp b/hiro/gtk/widget/table-view-column.cpp index bb423fc4e5..ee624e18f1 100644 --- a/hiro/gtk/widget/table-view-column.cpp +++ b/hiro/gtk/widget/table-view-column.cpp @@ -5,7 +5,7 @@ namespace hiro { auto pTableViewColumn::construct() -> void { if(auto parent = _parent()) { auto handle = parent.data(); - uint offset = self().offset(); + u32 offset = self().offset(); #if HIRO_GTK==2 gtkHeader = gtk_hbox_new(false, 0); @@ -125,7 +125,7 @@ auto pTableViewColumn::setVisible(bool visible) -> void { gtk_tree_view_column_set_visible(gtkColumn, visible); } -auto pTableViewColumn::setWidth(int width) -> void { +auto pTableViewColumn::setWidth(s32 width) -> void { if(auto parent = _parent()) { parent->resizeColumns(); } diff --git a/hiro/gtk/widget/table-view-column.hpp b/hiro/gtk/widget/table-view-column.hpp index 23136182f4..22dbcc1937 100644 --- a/hiro/gtk/widget/table-view-column.hpp +++ b/hiro/gtk/widget/table-view-column.hpp @@ -19,7 +19,7 @@ struct pTableViewColumn : pObject { auto setText(const string& text) -> void; auto setVerticalAlignment(double) -> void {} auto setVisible(bool visible) -> void override; - auto setWidth(int width) -> void; + auto setWidth(s32 width) -> void; auto _parent() -> maybe; diff --git a/hiro/gtk/widget/table-view-item.hpp b/hiro/gtk/widget/table-view-item.hpp index 8289d687b3..0ddc48013e 100644 --- a/hiro/gtk/widget/table-view-item.hpp +++ b/hiro/gtk/widget/table-view-item.hpp @@ -9,7 +9,7 @@ struct pTableViewItem : pObject { auto remove(sTableViewCell cell) -> void; auto setAlignment(Alignment alignment) -> void; auto setBackgroundColor(Color color) -> void; - auto setFocused() -> void; + auto setFocused() -> void override; auto setForegroundColor(Color color) -> void; auto setSelected(bool selected) -> void; diff --git a/hiro/gtk/widget/table-view.cpp b/hiro/gtk/widget/table-view.cpp index ee631ddb65..2f755a5331 100644 --- a/hiro/gtk/widget/table-view.cpp +++ b/hiro/gtk/widget/table-view.cpp @@ -3,12 +3,12 @@ namespace hiro { static auto TableView_activate(GtkTreeView*, GtkTreePath* gtkRow, GtkTreeViewColumn* gtkColumn, pTableView* p) -> void { return p->_doActivate(gtkRow, gtkColumn); } -static auto TableView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pTableView* p) -> int { return p->_doEvent(event); } +static auto TableView_buttonEvent(GtkTreeView* treeView, GdkEventButton* event, pTableView* p) -> s32 { return p->_doEvent(event); } static auto TableView_change(GtkTreeSelection*, pTableView* p) -> void { return p->_doChange(); } static auto TableView_edit(GtkCellRendererText* renderer, const char* path, const char* text, pTableView* p) -> void { return p->_doEdit(renderer, path, text); } static auto TableView_headerActivate(GtkTreeViewColumn* column, pTableView* p) -> void { return p->_doHeaderActivate(column); } static auto TableView_keyPressEvent(GtkTreeView* treeView, GdkEventKey* event, pTableView* p) -> bool { return p->_doKeyPress(event); } -static auto TableView_mouseMoveEvent(GtkWidget*, GdkEvent*, pTableView* p) -> int { return p->_doMouseMove(); } +static auto TableView_mouseMoveEvent(GtkWidget*, GdkEvent*, pTableView* p) -> s32 { return p->_doMouseMove(); } static auto TableView_popup(GtkTreeView*, pTableView* p) -> void { return p->_doContext(); } static auto TableView_dataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter, pTableView* p) -> void { return p->_doDataFunc(column, renderer, iter); } @@ -17,7 +17,7 @@ static auto TableView_toggle(GtkCellRendererToggle* toggle, const char* path, pT static auto TableView_realize(GtkTreeView*, pTableView* p) -> void { //the initial geometry for column sizing is most likely wrong at this point: //having to call processEvents() twice is very heavy-handed, but necessary here. - for(uint repeat : range(2)) { + for(u32 repeat : range(2)) { Application::processEvents(); p->resizeColumns(); } @@ -88,31 +88,31 @@ auto pTableView::remove(sTableViewItem item) -> void { auto pTableView::resizeColumns() -> void { auto lock = acquire(); - vector widths; - int minimumWidth = 0; - int expandable = 0; - for(uint position : range(self().columnCount())) { - int width = _width(position); + vector widths; + s32 minimumWidth = 0; + s32 expandable = 0; + for(u32 position : range(self().columnCount())) { + s32 width = _width(position); widths.append(width); minimumWidth += width; if(self().column(position).expandable()) expandable++; } - int maximumWidth = self().geometry().width() - 6; + s32 maximumWidth = self().geometry().width() - 6; if(auto scrollBar = gtk_scrolled_window_get_vscrollbar(gtkScrolledWindow)) { GtkAllocation allocation; gtk_widget_get_allocation(scrollBar, &allocation); if(gtk_widget_get_visible(scrollBar)) maximumWidth -= allocation.width; } - int expandWidth = 0; + s32 expandWidth = 0; if(expandable && maximumWidth > minimumWidth) { expandWidth = (maximumWidth - minimumWidth) / expandable; } - for(uint position : range(self().columnCount())) { + for(u32 position : range(self().columnCount())) { if(auto column = self().column(position)->self()) { - int width = widths[position]; + s32 width = widths[position]; if(column->state().expandable) width += expandWidth; gtk_tree_view_column_set_fixed_width(column->gtkColumn, width); } @@ -181,8 +181,8 @@ auto pTableView::setSortable(bool sortable) -> void { } } -auto pTableView::_cellWidth(uint _row, uint _column) -> uint { - uint width = 8; +auto pTableView::_cellWidth(u32 _row, u32 _column) -> u32 { + u32 width = 8; if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(cell->state.checkable) { @@ -199,8 +199,8 @@ auto pTableView::_cellWidth(uint _row, uint _column) -> uint { return width; } -auto pTableView::_columnWidth(uint _column) -> uint { - uint width = 6; +auto pTableView::_columnWidth(u32 _column) -> u32 { + u32 width = 6; if(auto column = self().column(_column)) { if(auto& icon = column->state.icon) { width += icon.width() + 2; @@ -335,7 +335,7 @@ auto pTableView::_doEdit(GtkCellRendererText* gtkCellRendererText, const char* p } } -auto pTableView::_doEvent(GdkEventButton* gdkEvent) -> int { +auto pTableView::_doEvent(GdkEventButton* gdkEvent) -> s32 { if(gdkEvent->type == GDK_BUTTON_PRESS) { //detect when the empty space of the GtkTreeView is clicked; and clear the selection GtkTreePath* gtkPath = nullptr; @@ -394,7 +394,7 @@ auto pTableView::_doKeyPress(GdkEventKey* event) -> bool { //this code detects said case, blocks the key from being propagated, and calls the activate callback directly //the result is that the enter key can be used to activate multiple selected items at a time //there are four ways to activate items via the keyboard in GTK, so we have to detect all of them here - uint modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_SUPER_MASK); //ignore other modifiers (eg mouse buttons) + u32 modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_SUPER_MASK); //ignore other modifiers (eg mouse buttons) if((event->keyval == GDK_KEY_Return && !modifiers) || (event->keyval == GDK_KEY_KP_Enter && !modifiers) || (event->keyval == GDK_KEY_space && !modifiers) @@ -409,7 +409,7 @@ auto pTableView::_doKeyPress(GdkEventKey* event) -> bool { //GtkTreeView::cursor-changed and GtkTreeSelection::changed do not send signals for changes during rubber-banding selection //so here we capture motion-notify-event, and if the selections have changed, invoke TableView::onChange -auto pTableView::_doMouseMove() -> int { +auto pTableView::_doMouseMove() -> s32 { if(gtk_tree_view_is_rubber_banding_active(gtkTreeView)) { if(!locked()) _updateSelected(); } @@ -461,7 +461,7 @@ auto pTableView::_updateSelected() -> void { return; } - vector selected; + vector selected; GList* list = gtk_tree_selection_get_selected_rows(gtkTreeSelection, >kTreeModel); GList* p = list; @@ -470,7 +470,7 @@ auto pTableView::_updateSelected() -> void { GtkTreeIter iter; if(gtk_tree_model_get_iter(gtkTreeModel, &iter, (GtkTreePath*)p->data)) { char* pathname = gtk_tree_model_get_string_from_iter(gtkTreeModel, &iter); - uint selection = toNatural(pathname); + u32 selection = toNatural(pathname); g_free(pathname); selected.append(selection); } @@ -501,9 +501,9 @@ auto pTableView::_updateSelected() -> void { if(!locked()) self().doChange(); } -auto pTableView::_width(uint column) -> uint { +auto pTableView::_width(u32 column) -> u32 { if(auto width = self().column(column).width()) return width; - uint width = 1; + u32 width = 1; if(!self().column(column).visible()) return width; if(self().headered()) width = max(width, _columnWidth(column)); for(auto row : range(self().itemCount())) { diff --git a/hiro/gtk/widget/table-view.hpp b/hiro/gtk/widget/table-view.hpp index a403826a46..24192afbf8 100644 --- a/hiro/gtk/widget/table-view.hpp +++ b/hiro/gtk/widget/table-view.hpp @@ -22,22 +22,22 @@ struct pTableView : pWidget { auto setHeadered(bool headered) -> void; auto setSortable(bool sortable) -> void; - auto _cellWidth(uint row, uint column) -> uint; - auto _columnWidth(uint column) -> uint; + auto _cellWidth(u32 row, u32 column) -> u32; + auto _columnWidth(u32 column) -> u32; auto _createModel() -> void; auto _doActivate(GtkTreePath* = nullptr, GtkTreeViewColumn* = nullptr) -> void; auto _doChange() -> void; auto _doContext() -> void; auto _doDataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeIter* iter) -> void; auto _doEdit(GtkCellRendererText* gtkCellRendererText, const char* path, const char* text) -> void; - auto _doEvent(GdkEventButton* event) -> int; + auto _doEvent(GdkEventButton* event) -> s32; auto _doHeaderActivate(GtkTreeViewColumn* column) -> void; auto _doKeyPress(GdkEventKey* event) -> bool; - auto _doMouseMove() -> int; + auto _doMouseMove() -> s32; auto _doToggle(GtkCellRendererToggle* gtkCellRendererToggle, const char* path) -> void; auto _updateRulesHint() -> void; auto _updateSelected() -> void; - auto _width(uint column) -> uint; + auto _width(u32 column) -> u32; GtkScrolledWindow* gtkScrolledWindow = nullptr; GtkWidget* gtkWidgetChild = nullptr; @@ -46,7 +46,7 @@ struct pTableView : pWidget { GtkListStore* gtkListStore = nullptr; GtkTreeModel* gtkTreeModel = nullptr; GtkEntry* gtkEntry = nullptr; - vector currentSelection; + vector currentSelection; bool suppressChange = false; }; diff --git a/hiro/gtk/widget/text-edit.cpp b/hiro/gtk/widget/text-edit.cpp index 6f39fe9408..a3ec1b6c84 100644 --- a/hiro/gtk/widget/text-edit.cpp +++ b/hiro/gtk/widget/text-edit.cpp @@ -76,7 +76,7 @@ auto pTextEdit::setTextCursor(TextCursor cursor) -> void { GtkTextIter offset, length; gtk_text_buffer_get_end_iter(textBuffer, &offset); gtk_text_buffer_get_end_iter(textBuffer, &length); - int end = gtk_text_iter_get_offset(&offset); + s32 end = gtk_text_iter_get_offset(&offset); gtk_text_iter_set_offset(&offset, max(0, min(end, cursor.offset()))); gtk_text_iter_set_offset(&length, max(0, min(end, cursor.offset() + cursor.length()))); gtk_text_buffer_select_range(textBuffer, &offset, &length); @@ -104,16 +104,16 @@ auto pTextEdit::text() const -> string { auto pTextEdit::textCursor() const -> TextCursor { TextCursor cursor; - int offset = 0; + s32 offset = 0; g_object_get(G_OBJECT(textBuffer), "cursor-position", &offset, nullptr); cursor.setOffset(offset); GtkTextIter start, end; if(gtk_text_buffer_get_selection_bounds(textBuffer, &start, &end)) { //if selecting text from left to right, the cursor may be ahead of the selection start ... //since hiro combines selection bounds (end-start) into length, move the offset to the start - int origin = gtk_text_iter_get_offset(&start); + s32 origin = gtk_text_iter_get_offset(&start); cursor.setOffset(origin); - int length = gtk_text_iter_get_offset(&end) - origin; + s32 length = gtk_text_iter_get_offset(&end) - origin; cursor.setLength(length); } return cursor; diff --git a/hiro/gtk/widget/tree-view-item.cpp b/hiro/gtk/widget/tree-view-item.cpp index 3a6fe613d5..72433b7851 100644 --- a/hiro/gtk/widget/tree-view-item.cpp +++ b/hiro/gtk/widget/tree-view-item.cpp @@ -105,8 +105,8 @@ auto pTreeViewItem::setText(const string& text) -> void { // //recursive function to find the minimum (pre-computed / cached) width of a TreeViewItem tree -auto pTreeViewItem::_minimumWidth(uint depth) -> uint { - uint width = TreeViewIndentation * depth + _width; +auto pTreeViewItem::_minimumWidth(u32 depth) -> u32 { + u32 width = TreeViewIndentation * depth + _width; for(auto& item : state().items) { if(auto self = item->self()) { width = max(width, self->_minimumWidth(depth + 1)); diff --git a/hiro/gtk/widget/tree-view-item.hpp b/hiro/gtk/widget/tree-view-item.hpp index e0abc49340..7970d35652 100644 --- a/hiro/gtk/widget/tree-view-item.hpp +++ b/hiro/gtk/widget/tree-view-item.hpp @@ -11,19 +11,19 @@ struct pTreeViewItem : pObject { auto setCheckable(bool checkable) -> void; auto setChecked(bool checked) -> void; auto setExpanded(bool expanded) -> void; - auto setFocused() -> void; + auto setFocused() -> void override; auto setForegroundColor(Color color) -> void; auto setIcon(const image& icon) -> void; auto setSelected() -> void; auto setText(const string& text) -> void; - auto _minimumWidth(uint depth = 0) -> uint; + auto _minimumWidth(u32 depth = 0) -> u32; auto _parentItem() -> pTreeViewItem*; auto _parentWidget() -> pTreeView*; auto _updateWidth() -> void; GtkTreeIter gtkIter; - uint _width = 0; + u32 _width = 0; }; } diff --git a/hiro/gtk/widget/tree-view.cpp b/hiro/gtk/widget/tree-view.cpp index 705c596812..23f7cb92cc 100644 --- a/hiro/gtk/widget/tree-view.cpp +++ b/hiro/gtk/widget/tree-view.cpp @@ -2,17 +2,17 @@ namespace hiro { -static const uint TreeViewIndentation = 20; +static const u32 TreeViewIndentation = 20; //gtk_tree_view_collapse_all(gtkTreeView); //gtk_tree_view_expand_all(gtkTreeView); static auto TreeView_activate(GtkTreeView*, GtkTreePath* gtkPath, GtkTreeViewColumn*, pTreeView* p) -> void { p->_activatePath(gtkPath); } -static auto TreeView_buttonEvent(GtkTreeView*, GdkEventButton* gdkEvent, pTreeView* p) -> int { return p->_buttonEvent(gdkEvent); } +static auto TreeView_buttonEvent(GtkTreeView*, GdkEventButton* gdkEvent, pTreeView* p) -> s32 { return p->_buttonEvent(gdkEvent); } static auto TreeView_change(GtkTreeSelection*, pTreeView* p) -> void { p->_updateSelected(); } static auto TreeView_context(GtkTreeView*, pTreeView* p) -> void { p->self().doContext(); } static auto TreeView_dataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter, pTreeView* p) -> void { return p->_doDataFunc(column, renderer, iter); } -static auto TreeView_keyPress(GtkWidget*, GdkEventKey*, pTreeView* p) -> int { p->suppressActivate = false; return false; } +static auto TreeView_keyPress(GtkWidget*, GdkEventKey*, pTreeView* p) -> s32 { p->suppressActivate = false; return false; } static auto TreeView_toggle(GtkCellRendererToggle*, char* path, pTreeView* p) -> void { p->_togglePath(path); } auto pTreeView::construct() -> void { @@ -134,7 +134,7 @@ auto pTreeView::_activatePath(GtkTreePath* gtkPath) -> void { g_free(path); } -auto pTreeView::_buttonEvent(GdkEventButton* gdkEvent) -> int { +auto pTreeView::_buttonEvent(GdkEventButton* gdkEvent) -> s32 { if(gdkEvent->type == GDK_BUTTON_PRESS) { //detect when the empty space of the GtkTreeView is clicked; and clear the selection GtkTreePath* gtkPath = nullptr; @@ -246,14 +246,14 @@ auto pTreeView::_togglePath(string path) -> void { //checkability, icon, or text is updated. in other words, whenever the need for a horizontal //scroll bar to show all items in the tree is necessary or not. auto pTreeView::_updateScrollBars() -> void { - int maximumWidth = self().geometry().width() - 6; + s32 maximumWidth = self().geometry().width() - 6; if(auto scrollBar = gtk_scrolled_window_get_vscrollbar(gtkScrolledWindow)) { GtkAllocation allocation; gtk_widget_get_allocation(scrollBar, &allocation); if(gtk_widget_get_visible(scrollBar)) maximumWidth -= allocation.width; } - int minimumWidth = 0; + s32 minimumWidth = 0; for(auto& item : state().items) { if(auto self = item->self()) { minimumWidth = max(minimumWidth, self->_minimumWidth()); diff --git a/hiro/gtk/widget/tree-view.hpp b/hiro/gtk/widget/tree-view.hpp index b881de36c7..360d5c118d 100644 --- a/hiro/gtk/widget/tree-view.hpp +++ b/hiro/gtk/widget/tree-view.hpp @@ -11,16 +11,16 @@ struct pTreeView : pWidget { auto setBackgroundColor(Color color) -> void; auto setFocused() -> void override; auto setForegroundColor(Color color) -> void; - auto setGeometry(Geometry geometry) -> void; + auto setGeometry(Geometry geometry) -> void override; auto _activatePath(GtkTreePath* gtkPath) -> void; - auto _buttonEvent(GdkEventButton* gdkEvent) -> int; + auto _buttonEvent(GdkEventButton* gdkEvent) -> s32; auto _doDataFunc(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeIter* iter) -> void; auto _togglePath(string path) -> void; auto _updateScrollBars() -> void; auto _updateSelected() -> void; - auto _width(sTreeViewItem item, uint depth = 0) -> uint; - auto _widthRecursive() -> uint; + auto _width(sTreeViewItem item, u32 depth = 0) -> u32; + auto _widthRecursive() -> u32; GtkScrolledWindow* gtkScrolledWindow = nullptr; GtkWidget* gtkWidgetChild = nullptr; diff --git a/hiro/gtk/widget/vertical-scroll-bar.cpp b/hiro/gtk/widget/vertical-scroll-bar.cpp index 04b3bec709..9fb3fd8153 100644 --- a/hiro/gtk/widget/vertical-scroll-bar.cpp +++ b/hiro/gtk/widget/vertical-scroll-bar.cpp @@ -3,7 +3,7 @@ namespace hiro { static auto VerticalScrollBar_change(GtkRange* gtkRange, pVerticalScrollBar* p) -> void { - auto position = (uint)gtk_range_get_value(gtkRange); + auto position = (u32)gtk_range_get_value(gtkRange); if(p->state().position == position) return; p->state().position = position; if(!p->locked()) p->self().doChange(); @@ -32,14 +32,14 @@ auto pVerticalScrollBar::minimumSize() const -> Size { return {20, 0}; } -auto pVerticalScrollBar::setLength(uint length) -> void { +auto pVerticalScrollBar::setLength(u32 length) -> void { auto lock = acquire(); length += length == 0; gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); } -auto pVerticalScrollBar::setPosition(uint position) -> void { +auto pVerticalScrollBar::setPosition(u32 position) -> void { gtk_range_set_value(GTK_RANGE(gtkWidget), position); } diff --git a/hiro/gtk/widget/vertical-scroll-bar.hpp b/hiro/gtk/widget/vertical-scroll-bar.hpp index 4fd833cfbd..e2b6910846 100644 --- a/hiro/gtk/widget/vertical-scroll-bar.hpp +++ b/hiro/gtk/widget/vertical-scroll-bar.hpp @@ -5,9 +5,9 @@ namespace hiro { struct pVerticalScrollBar : pWidget { Declare(VerticalScrollBar, Widget) - auto minimumSize() const -> Size; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto minimumSize() const -> Size override; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/gtk/widget/vertical-slider.cpp b/hiro/gtk/widget/vertical-slider.cpp index a71ad25bdf..f9511893a2 100644 --- a/hiro/gtk/widget/vertical-slider.cpp +++ b/hiro/gtk/widget/vertical-slider.cpp @@ -3,7 +3,7 @@ namespace hiro { static auto VerticalSlider_change(GtkRange* gtkRange, pVerticalSlider* p) -> void { - auto position = (uint)gtk_range_get_value(gtkRange); + auto position = (u32)gtk_range_get_value(gtkRange); if(p->state().position == position) return; p->state().position = position; if(!p->locked()) p->self().doChange(); @@ -33,13 +33,13 @@ auto pVerticalSlider::minimumSize() const -> Size { return {20, 3}; } -auto pVerticalSlider::setLength(uint length) -> void { +auto pVerticalSlider::setLength(u32 length) -> void { length += length == 0; gtk_range_set_range(GTK_RANGE(gtkWidget), 0, max(1u, length - 1)); gtk_range_set_increments(GTK_RANGE(gtkWidget), 1, length >> 3); } -auto pVerticalSlider::setPosition(uint position) -> void { +auto pVerticalSlider::setPosition(u32 position) -> void { gtk_range_set_value(GTK_RANGE(gtkWidget), position); } diff --git a/hiro/gtk/widget/vertical-slider.hpp b/hiro/gtk/widget/vertical-slider.hpp index 301924cc7d..a4f1d76e0b 100644 --- a/hiro/gtk/widget/vertical-slider.hpp +++ b/hiro/gtk/widget/vertical-slider.hpp @@ -6,8 +6,8 @@ struct pVerticalSlider : pWidget { Declare(VerticalSlider, Widget) auto minimumSize() const -> Size override; - auto setLength(uint length) -> void; - auto setPosition(uint position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/gtk/widget/viewport.cpp b/hiro/gtk/widget/viewport.cpp index f926b0e127..716d6e1b17 100644 --- a/hiro/gtk/widget/viewport.cpp +++ b/hiro/gtk/widget/viewport.cpp @@ -3,18 +3,18 @@ namespace hiro { //GTK3 -static auto Viewport_draw(GtkWidget* widget, cairo_t* context, pViewport* p) -> int { +static auto Viewport_draw(GtkWidget* widget, cairo_t* context, pViewport* p) -> s32 { p->_onDraw(context); return true; } //GTK2 -static auto Viewport_expose(GtkWidget* widget, GdkEventExpose* event, pViewport* p) -> int { +static auto Viewport_expose(GtkWidget* widget, GdkEventExpose* event, pViewport* p) -> s32 { p->_onExpose(event); return true; } -static auto Viewport_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* p) -> int { +static auto Viewport_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* p) -> s32 { //viewports that have been set focusable are intended for games. //to prevent arrow keys, tab, etc from losing focus on the game viewport, block key propagation here. if(p->self().focusable()) return true; @@ -23,7 +23,7 @@ static auto Viewport_keyPress(GtkWidget* widget, GdkEventKey* event, pViewport* return false; } -static auto Viewport_mousePress(GtkWidget* widget, GdkEventButton* event, pViewport* p) -> int { +static auto Viewport_mousePress(GtkWidget* widget, GdkEventButton* event, pViewport* p) -> s32 { //gtk_widget_set_focus_on_click() is a GTK 3.2+ feature. //implement this functionality manually for GTK 2.0+ compatibility. if(event->button == 1 && p->self().focusable()) gtk_widget_grab_focus(widget); diff --git a/hiro/gtk/widget/widget.cpp b/hiro/gtk/widget/widget.cpp index 9be92cfa50..2b2bd54e4d 100644 --- a/hiro/gtk/widget/widget.cpp +++ b/hiro/gtk/widget/widget.cpp @@ -2,15 +2,15 @@ namespace hiro { -static auto Widget_drop(GtkWidget* widget, GdkDragContext* context, int x, int y, -GtkSelectionData* data, uint type, uint timestamp, pWidget* p) -> void { +static auto Widget_drop(GtkWidget* widget, GdkDragContext* context, s32 x, s32 y, +GtkSelectionData* data, u32 type, u32 timestamp, pWidget* p) -> void { if(!p->state().droppable) return; auto paths = DropPaths(data); if(!paths) return; p->self().doDrop(paths); } -static auto Widget_mouseEnter(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> int { +static auto Widget_mouseEnter(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> s32 { if(auto cursor = p->gdkMouseCursor) { if(auto window = gtk_widget_get_parent_window(widget)) { gdk_window_set_cursor(window, cursor); @@ -20,7 +20,7 @@ static auto Widget_mouseEnter(GtkWidget* widget, GdkEventButton* event, pWidget* return true; } -static auto Widget_mouseLeave(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> int { +static auto Widget_mouseLeave(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> s32 { if(auto cursor = p->gdkMouseCursor) { if(auto window = gtk_widget_get_parent_window(widget)) { gdk_window_set_cursor(window, nullptr); @@ -30,12 +30,12 @@ static auto Widget_mouseLeave(GtkWidget* widget, GdkEventButton* event, pWidget* return true; } -static auto Widget_mouseMove(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> int { - p->self().doMouseMove({(int)event->x, (int)event->y}); +static auto Widget_mouseMove(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> s32 { + p->self().doMouseMove({(s32)event->x, (s32)event->y}); return true; } -static auto Widget_mousePress(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> int { +static auto Widget_mousePress(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> s32 { switch(event->button) { case 1: p->self().doMousePress(Mouse::Button::Left); break; case 2: p->self().doMousePress(Mouse::Button::Middle); break; @@ -44,7 +44,7 @@ static auto Widget_mousePress(GtkWidget* widget, GdkEventButton* event, pWidget* return true; } -static auto Widget_mouseRelease(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> int { +static auto Widget_mouseRelease(GtkWidget* widget, GdkEventButton* event, pWidget* p) -> s32 { switch(event->button) { case 1: p->self().doMouseRelease(Mouse::Button::Left); break; case 2: p->self().doMouseRelease(Mouse::Button::Middle); break; diff --git a/hiro/gtk/window.cpp b/hiro/gtk/window.cpp index 25792408b3..ae71208c67 100644 --- a/hiro/gtk/window.cpp +++ b/hiro/gtk/window.cpp @@ -2,7 +2,7 @@ namespace hiro { -static auto Window_close(GtkWidget* widget, GdkEvent* event, pWindow* p) -> int { +static auto Window_close(GtkWidget* widget, GdkEvent* event, pWindow* p) -> s32 { if(p->state().onClose) { p->self().doClose(); } else { @@ -13,12 +13,12 @@ static auto Window_close(GtkWidget* widget, GdkEvent* event, pWindow* p) -> int } //GTK3 draw: called into by GTK2 expose-event -static auto Window_draw(GtkWidget* widget, cairo_t* context, pWindow* p) -> int { +static auto Window_draw(GtkWidget* widget, cairo_t* context, pWindow* p) -> s32 { if(auto color = p->state().backgroundColor) { - double red = (double)color.red() / 255.0; - double green = (double)color.green() / 255.0; - double blue = (double)color.blue() / 255.0; - double alpha = (double)color.alpha() / 255.0; + f64 red = (f64)color.red() / 255.0; + f64 green = (f64)color.green() / 255.0; + f64 blue = (f64)color.blue() / 255.0; + f64 alpha = (f64)color.alpha() / 255.0; if(gdk_screen_is_composited(gdk_screen_get_default()) && gdk_screen_get_rgba_visual(gdk_screen_get_default()) @@ -43,41 +43,41 @@ static auto Window_draw(GtkWidget* widget, cairo_t* context, pWindow* p) -> int } //GTK2 expose-event -static auto Window_expose(GtkWidget* widget, GdkEvent* event, pWindow* p) -> int { +static auto Window_expose(GtkWidget* widget, GdkEvent* event, pWindow* p) -> s32 { cairo_t* context = gdk_cairo_create(gtk_widget_get_window(widget)); Window_draw(widget, context, p); cairo_destroy(context); return false; } -static auto Window_configure(GtkWidget* widget, GdkEvent* event, pWindow* p) -> int { +static auto Window_configure(GtkWidget* widget, GdkEvent* event, pWindow* p) -> s32 { p->_synchronizeMargin(); return false; } -static auto Window_drop(GtkWidget* widget, GdkDragContext* context, int x, int y, -GtkSelectionData* data, uint type, uint timestamp, pWindow* p) -> void { +static auto Window_drop(GtkWidget* widget, GdkDragContext* context, s32 x, s32 y, +GtkSelectionData* data, u32 type, u32 timestamp, pWindow* p) -> void { if(!p->state().droppable) return; auto paths = DropPaths(data); if(!paths) return; p->self().doDrop(paths); } -static auto Window_getPreferredWidth(GtkWidget* widget, int* minimalWidth, int* naturalWidth) -> void { +static auto Window_getPreferredWidth(GtkWidget* widget, s32* minimalWidth, s32* naturalWidth) -> void { if(auto p = (pWindow*)g_object_get_data(G_OBJECT(widget), "hiro::window")) { *minimalWidth = 1; *naturalWidth = p->state().geometry.width(); } } -static auto Window_getPreferredHeight(GtkWidget* widget, int* minimalHeight, int* naturalHeight) -> void { +static auto Window_getPreferredHeight(GtkWidget* widget, s32* minimalHeight, s32* naturalHeight) -> void { if(auto p = (pWindow*)g_object_get_data(G_OBJECT(widget), "hiro::window")) { *minimalHeight = 1; *naturalHeight = p->state().geometry.height(); } } -static auto Window_keyPress(GtkWidget* widget, GdkEventKey* event, pWindow* p) -> int { +static auto Window_keyPress(GtkWidget* widget, GdkEventKey* event, pWindow* p) -> s32 { if(auto key = pKeyboard::_translate(event->keyval)) { p->self().doKeyPress(key); } @@ -92,7 +92,7 @@ static auto Window_keyPress(GtkWidget* widget, GdkEventKey* event, pWindow* p) - return false; } -static auto Window_keyRelease(GtkWidget* widget, GdkEventKey* event, pWindow* p) -> int { +static auto Window_keyRelease(GtkWidget* widget, GdkEventKey* event, pWindow* p) -> s32 { if(auto key = pKeyboard::_translate(event->keyval)) { p->self().doKeyRelease(key); } @@ -211,7 +211,7 @@ auto pWindow::construct() -> void { } auto pWindow::destruct() -> void { - for(uint offset : range(pApplication::state().windows.size())) { + for(u32 offset : range(pApplication::state().windows.size())) { if(pApplication::state().windows[offset] == this) { pApplication::state().windows.remove(offset); break; @@ -255,7 +255,7 @@ auto pWindow::frameMargin() const -> Geometry { }; } -auto pWindow::handle() const -> uintptr_t { +auto pWindow::handle() const -> uintptr { #if defined(DISPLAY_WINDOWS) return (uintptr)GDK_WINDOW_HWND(gtk_widget_get_window(widget)); #endif @@ -267,7 +267,7 @@ auto pWindow::handle() const -> uintptr_t { return (uintptr)nullptr; } -auto pWindow::monitor() const -> uint { +auto pWindow::monitor() const -> u32 { if(!gtk_widget_get_realized(widget)) return 0; auto window = gtk_widget_get_window(widget); return gdk_screen_get_monitor_at_window(gdk_screen_get_default(), window); @@ -447,7 +447,7 @@ auto pWindow::_append(mMenu& menu) -> void { } } -auto pWindow::_menuHeight() const -> int { +auto pWindow::_menuHeight() const -> s32 { if(auto& menuBar = state().menuBar) { if(menuBar->visible()) { return settings.geometry.menuHeight + _menuTextHeight(); @@ -456,8 +456,8 @@ auto pWindow::_menuHeight() const -> int { return 0; } -auto pWindow::_menuTextHeight() const -> int { - int height = 0; +auto pWindow::_menuTextHeight() const -> s32 { + s32 height = 0; if(auto& menuBar = state().menuBar) { for(auto& menu : menuBar->state.menus) { height = max(height, menu->font(true).size(menu->text()).height()); @@ -519,7 +519,7 @@ auto pWindow::_setStatusVisible(bool visible) -> void { setResizable(self().resizable()); } -auto pWindow::_statusHeight() const -> int { +auto pWindow::_statusHeight() const -> s32 { if(auto& statusBar = state().statusBar) { if(statusBar->visible()) { return settings.geometry.statusHeight + _statusTextHeight(); @@ -528,8 +528,8 @@ auto pWindow::_statusHeight() const -> int { return 0; } -auto pWindow::_statusTextHeight() const -> int { - int height = 0; +auto pWindow::_statusTextHeight() const -> s32 { + s32 height = 0; if(auto& statusBar = state().statusBar) { height = statusBar->font(true).size(statusBar->text()).height(); } @@ -653,14 +653,14 @@ auto pWindow::_synchronizeState() -> void { #if defined(DISPLAY_XORG) auto display = XOpenDisplay(nullptr); - int screen = DefaultScreen(display); + s32 screen = DefaultScreen(display); auto window = GDK_WINDOW_XID(gtk_widget_get_window(widget)); XlibAtom wmState = XInternAtom(display, "_NET_WM_STATE", XlibTrue); XlibAtom atom; - int format; + s32 format; unsigned long items, after; unsigned char* data = nullptr; - int result = XGetWindowProperty( + s32 result = XGetWindowProperty( display, window, wmState, 0, LONG_MAX, XlibFalse, AnyPropertyType, &atom, &format, &items, &after, &data ); auto atoms = (unsigned long*)data; diff --git a/hiro/gtk/window.hpp b/hiro/gtk/window.hpp index 9a31f5e305..7096755dfa 100644 --- a/hiro/gtk/window.hpp +++ b/hiro/gtk/window.hpp @@ -10,8 +10,8 @@ struct pWindow : pObject { auto append(sStatusBar statusBar) -> void; auto focused() const -> bool override; auto frameMargin() const -> Geometry; - auto handle() const -> uintptr_t; - auto monitor() const -> uint; + auto handle() const -> uintptr; + auto monitor() const -> u32; auto remove(sMenuBar menuBar) -> void; auto remove(sSizable sizable) -> void; auto remove(sStatusBar statusBar) -> void; @@ -33,8 +33,8 @@ struct pWindow : pObject { auto _append(mWidget& widget) -> void; auto _append(mMenu& menu) -> void; - auto _menuHeight() const -> int; - auto _menuTextHeight() const -> int; + auto _menuHeight() const -> s32; + auto _menuTextHeight() const -> s32; auto _setIcon(const string& basename) -> bool; auto _setMenuEnabled(bool enabled) -> void; auto _setMenuFont(const Font& font) -> void; @@ -43,8 +43,8 @@ struct pWindow : pObject { auto _setStatusFont(const Font& font) -> void; auto _setStatusText(const string& text) -> void; auto _setStatusVisible(bool visible) -> void; - auto _statusHeight() const -> int; - auto _statusTextHeight() const -> int; + auto _statusHeight() const -> s32; + auto _statusTextHeight() const -> s32; auto _synchronizeGeometry() -> void; auto _synchronizeMargin() -> void; auto _synchronizeState() -> void; @@ -55,8 +55,8 @@ struct pWindow : pObject { GtkWidget* statusContainer = nullptr; GtkWidget* gtkMenu = nullptr; GtkWidget* gtkStatus = nullptr; - GtkAllocation lastMove = {0}; - GtkAllocation lastSize = {0}; + GtkAllocation lastMove = {}; + GtkAllocation lastSize = {}; bool screenSaver = true; }; diff --git a/hiro/qt/desktop.cpp b/hiro/qt/desktop.cpp index 33342748fb..98969fb7ea 100644 --- a/hiro/qt/desktop.cpp +++ b/hiro/qt/desktop.cpp @@ -7,7 +7,7 @@ auto pDesktop::size() -> Size { return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)}; #elif defined(DISPLAY_XORG) auto display = XOpenDisplay(nullptr); - int screen = DefaultScreen(display); + s32 screen = DefaultScreen(display); XWindowAttributes attributes; XGetWindowAttributes(display, RootWindow(display, screen), &attributes); XCloseDisplay(display); @@ -26,15 +26,15 @@ auto pDesktop::workspace() -> Geometry { return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top}; #elif defined(DISPLAY_XORG) auto display = XOpenDisplay(nullptr); - int screen = DefaultScreen(display); + s32 screen = DefaultScreen(display); - int format; + s32 format; unsigned char* data = nullptr; unsigned long items, after; XlibAtom returnAtom; XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibTrue); - int result = XGetWindowProperty( + s32 result = XGetWindowProperty( display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse, XInternAtom(display, "CARDINAL", XlibTrue), &returnAtom, &format, &items, &after, &data ); @@ -43,7 +43,7 @@ auto pDesktop::workspace() -> Geometry { if(result == Success && returnAtom == cardinal && format == 32 && items == 4) { unsigned long* workarea = (unsigned long*)data; XCloseDisplay(display); - return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]}; + return {(s32)workarea[0], (s32)workarea[1], (s32)workarea[2], (s32)workarea[3]}; } XCloseDisplay(display); diff --git a/hiro/qt/font.cpp b/hiro/qt/font.cpp index 14f66b4788..1e371b82d2 100644 --- a/hiro/qt/font.cpp +++ b/hiro/qt/font.cpp @@ -8,7 +8,7 @@ auto pFont::size(const Font& font, const string& text) -> Size { auto pFont::size(const QFont& qtFont, const string& text) -> Size { QFontMetrics metrics(qtFont); - signed maxWidth = 0; + s32 maxWidth = 0; auto lines = text.split("\n"); for(auto& line : lines) { maxWidth = max(maxWidth, metrics.width(QString::fromUtf8(line))); diff --git a/hiro/qt/keyboard.cpp b/hiro/qt/keyboard.cpp index 7cc68891ba..deebf9ea39 100644 --- a/hiro/qt/keyboard.cpp +++ b/hiro/qt/keyboard.cpp @@ -29,9 +29,9 @@ auto pKeyboard::pressed(unsigned code) -> bool { return _pressed(state, code); } -auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool { - uint8_t lo = code >> 0; - uint8_t hi = code >> 8; +auto pKeyboard::_pressed(const char* state, u16 code) -> bool { + u8 lo = code >> 0; + u8 hi = code >> 8; #if defined(DISPLAY_XORG) if(lo && state[lo >> 3] & (1 << (lo & 7))) return true; @@ -42,10 +42,10 @@ auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool { } auto pKeyboard::initialize() -> void { - auto append = [](unsigned lo, unsigned hi = 0) { + auto append = [](u32 lo, u32 hi = 0) { #if defined(DISPLAY_XORG) - lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::state().display, lo) : 0; - hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::state().display, hi) : 0; + lo = lo ? (u8)XKeysymToKeycode(pApplication::state().display, lo) : 0; + hi = hi ? (u8)XKeysymToKeycode(pApplication::state().display, hi) : 0; #endif settings.keycodes.append(lo << 0 | hi << 8); }; diff --git a/hiro/qt/keyboard.hpp b/hiro/qt/keyboard.hpp index 74fc69e46b..d809e66e76 100644 --- a/hiro/qt/keyboard.hpp +++ b/hiro/qt/keyboard.hpp @@ -4,9 +4,9 @@ namespace hiro { struct pKeyboard { static auto poll() -> vector; - static auto pressed(unsigned code) -> bool; + static auto pressed(u32 code) -> bool; - static auto _pressed(const char* state, uint16_t code) -> bool; + static auto _pressed(const char* state, u16 code) -> bool; static auto initialize() -> void; }; diff --git a/hiro/qt/monitor.cpp b/hiro/qt/monitor.cpp index b1ebcc4afd..4d3882cc96 100644 --- a/hiro/qt/monitor.cpp +++ b/hiro/qt/monitor.cpp @@ -2,11 +2,11 @@ namespace hiro { -auto pMonitor::count() -> uint { +auto pMonitor::count() -> u32 { return QApplication::desktop()->screenCount(); } -auto pMonitor::dpi(uint monitor) -> Position { +auto pMonitor::dpi(u32 monitor) -> Position { //Qt does not support per-monitor DPI retrieval return { QApplication::desktop()->logicalDpiX(), @@ -14,16 +14,16 @@ auto pMonitor::dpi(uint monitor) -> Position { }; } -auto pMonitor::geometry(uint monitor) -> Geometry { +auto pMonitor::geometry(u32 monitor) -> Geometry { QRect rectangle = QApplication::desktop()->screenGeometry(monitor); return {rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height()}; } -auto pMonitor::primary() -> uint { +auto pMonitor::primary() -> u32 { return QApplication::desktop()->primaryScreen(); } -auto pMonitor::workspace(uint monitor) -> Geometry { +auto pMonitor::workspace(u32 monitor) -> Geometry { if(Monitor::count() == 1) { return Desktop::workspace(); } else { diff --git a/hiro/qt/monitor.hpp b/hiro/qt/monitor.hpp index 1effa3dad3..fa0b76c318 100644 --- a/hiro/qt/monitor.hpp +++ b/hiro/qt/monitor.hpp @@ -4,10 +4,10 @@ namespace hiro { struct pMonitor { static auto count() -> uint; - static auto dpi(uint monitor) -> Position; - static auto geometry(uint monitor) -> Geometry; - static auto primary() -> uint; - static auto workspace(uint monitor) -> Geometry; + static auto dpi(u32 monitor) -> Position; + static auto geometry(u32 monitor) -> Geometry; + static auto primary() -> u32; + static auto workspace(u32 monitor) -> Geometry; }; } diff --git a/hiro/qt/qt.hpp b/hiro/qt/qt.hpp index 53982627a3..0f25c5a23a 100644 --- a/hiro/qt/qt.hpp +++ b/hiro/qt/qt.hpp @@ -136,7 +136,7 @@ struct QtComboButton : public QComboBox { QtComboButton(pComboButton& p) : p(p) {} pComboButton& p; public slots: - void onChange(int offset); + void onChange(s32 offset); }; #endif @@ -238,7 +238,7 @@ struct QtTabFrame : public QTabWidget { pTabFrame& p; auto showEvent(QShowEvent*) -> void override; public slots: - void onChange(int selection); + void onChange(s32 selection); }; #endif @@ -252,11 +252,11 @@ struct QtTableView : public QTreeWidget { auto showEvent(QShowEvent*) -> void override; pTableView& p; public slots: - void onActivate(QTreeWidgetItem* item, int column); + void onActivate(QTreeWidgetItem* item, s32 column); void onChange(); void onContext(); - void onSort(int column); - void onToggle(QTreeWidgetItem* item, int column); + void onSort(s32 column); + void onToggle(QTreeWidgetItem* item, s32 column); }; struct QtTableViewDelegate : public QStyledItemDelegate { diff --git a/hiro/qt/qt.moc b/hiro/qt/qt.moc index 9c5dd1ee09..20a4d32454 100644 --- a/hiro/qt/qt.moc +++ b/hiro/qt/qt.moc @@ -614,7 +614,7 @@ static const uint qt_meta_data_hiro__QtComboButton[] = { }; static const char qt_meta_stringdata_hiro__QtComboButton[] = { - "hiro::QtComboButton\0onChange(int)\0" + "hiro::QtComboButton\0onChange(s32)\0" "offset\0\0" }; @@ -624,7 +624,7 @@ void hiro::QtComboButton::qt_static_metacall(QObject *_o, QMetaObject::Call _c, Q_ASSERT(staticMetaObject.cast(_o)); QtComboButton *_t = static_cast(_o); switch (_id) { - case 0: _t->onChange((*reinterpret_cast< int(*)>(_a[1]))); break; + case 0: _t->onChange((*reinterpret_cast< s32(*)>(_a[1]))); break; default: ; } } @@ -1260,7 +1260,7 @@ static const uint qt_meta_data_hiro__QtTabFrame[] = { }; static const char qt_meta_stringdata_hiro__QtTabFrame[] = { - "hiro::QtTabFrame\0onChange(int)\0selection\0" + "hiro::QtTabFrame\0onChange(s32)\0selection\0" "\0" }; @@ -1270,7 +1270,7 @@ void hiro::QtTabFrame::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int Q_ASSERT(staticMetaObject.cast(_o)); QtTabFrame *_t = static_cast(_o); switch (_id) { - case 0: _t->onChange((*reinterpret_cast< int(*)>(_a[1]))); break; + case 0: _t->onChange((*reinterpret_cast< s32(*)>(_a[1]))); break; default: ; } } @@ -1338,9 +1338,9 @@ static const uint qt_meta_data_hiro__QtTableView[] = { }; static const char qt_meta_stringdata_hiro__QtTableView[] = { - "hiro::QtTableView\0onActivate(QTreeWidgetItem*,int)\0" + "hiro::QtTableView\0onActivate(QTreeWidgetItem*,s32)\0" "item,column\0\0onChange()\0onContext()\0" - "onSort(int)\0column\0onToggle(QTreeWidgetItem*,int)\0" + "onSort(s32)\0column\0onToggle(QTreeWidgetItem*,s32)\0" }; void hiro::QtTableView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) @@ -1349,11 +1349,11 @@ void hiro::QtTableView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, in Q_ASSERT(staticMetaObject.cast(_o)); QtTableView *_t = static_cast(_o); switch (_id) { - case 0: _t->onActivate((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; + case 0: _t->onActivate((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< s32(*)>(_a[2]))); break; case 1: _t->onChange(); break; case 2: _t->onContext(); break; - case 3: _t->onSort((*reinterpret_cast< int(*)>(_a[1]))); break; - case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; + case 3: _t->onSort((*reinterpret_cast< s32(*)>(_a[1]))); break; + case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< s32(*)>(_a[2]))); break; default: ; } } diff --git a/hiro/qt/settings.hpp b/hiro/qt/settings.hpp index eca6181bc0..aca5303b19 100644 --- a/hiro/qt/settings.hpp +++ b/hiro/qt/settings.hpp @@ -7,12 +7,12 @@ struct Settings { vector keycodes; struct Geometry { - int frameX = 4; - int frameY = 24; - int frameWidth = 8; - int frameHeight = 28; - int menuHeight = 9; - int statusHeight = 9; + s32 frameX = 4; + s32 frameY = 24; + s32 frameWidth = 8; + s32 frameHeight = 28; + s32 menuHeight = 9; + s32 statusHeight = 9; } geometry; }; diff --git a/hiro/qt/timer.cpp b/hiro/qt/timer.cpp index 4945b9f7c7..d7e00e4b39 100644 --- a/hiro/qt/timer.cpp +++ b/hiro/qt/timer.cpp @@ -20,7 +20,7 @@ auto pTimer::setEnabled(bool enabled) -> void { } } -auto pTimer::setInterval(unsigned interval) -> void { +auto pTimer::setInterval(u32 interval) -> void { qtTimer->setInterval(interval); } diff --git a/hiro/qt/timer.hpp b/hiro/qt/timer.hpp index a3fb8f54ac..da8ac41551 100644 --- a/hiro/qt/timer.hpp +++ b/hiro/qt/timer.hpp @@ -6,7 +6,7 @@ struct pTimer : pObject { Declare(Timer, Object) auto setEnabled(bool enabled) -> void override; - auto setInterval(unsigned interval) -> void; + auto setInterval(u32 interval) -> void; QtTimer* qtTimer = nullptr; }; diff --git a/hiro/qt/utility.cpp b/hiro/qt/utility.cpp index 17008b5e3f..7207416b92 100644 --- a/hiro/qt/utility.cpp +++ b/hiro/qt/utility.cpp @@ -1,7 +1,7 @@ namespace hiro { -static auto CalculateAlignment(Alignment alignment) -> signed { - signed result = 0; +static auto CalculateAlignment(Alignment alignment) -> s32 { + s32 result = 0; if(alignment.horizontal() < 0.333) result |= Qt::AlignLeft; else if(alignment.horizontal() > 0.666) result |= Qt::AlignRight; else result |= Qt::AlignCenter; @@ -43,222 +43,4 @@ static auto DropPaths(QDropEvent* event) -> vector { return paths; } -/* -static auto GetDisplacement(Sizable* sizable) -> Position { - Position position; - while(sizable->state.parent) { - Position displacement = sizable->state.parent->p.displacement(); - position.x += displacement.x; - position.y += displacement.y; - sizable = sizable->state.parent; - } - return position; -} -*/ - -/* -static auto GetParentWidgetLayout(Sizable* sizable) -> Layout* { - while(sizable) { - if(sizable->state.parent && dynamic_cast(sizable->state.parent)) return (Layout*)sizable; - sizable = sizable->state.parent; - } - return nullptr; -} -*/ - -/* -static auto GetParentWidget(Sizable* sizable) -> Widget* { - while(sizable) { - if(sizable->state.parent && dynamic_cast(sizable->state.parent)) return (Widget*)sizable->state.parent; - sizable = sizable->state.parent; - } - return nullptr; -} -*/ - -/* -static auto Keysym(int keysym) -> Keyboard::Keycode { - switch(keysym) { - case XK_Escape: return Keyboard::Keycode::Escape; - case XK_F1: return Keyboard::Keycode::F1; - case XK_F2: return Keyboard::Keycode::F2; - case XK_F3: return Keyboard::Keycode::F3; - case XK_F4: return Keyboard::Keycode::F4; - case XK_F5: return Keyboard::Keycode::F5; - case XK_F6: return Keyboard::Keycode::F6; - case XK_F7: return Keyboard::Keycode::F7; - case XK_F8: return Keyboard::Keycode::F8; - case XK_F9: return Keyboard::Keycode::F9; - case XK_F10: return Keyboard::Keycode::F10; - case XK_F11: return Keyboard::Keycode::F11; - case XK_F12: return Keyboard::Keycode::F12; - - case XK_Print: return Keyboard::Keycode::PrintScreen; - //Keyboard::Keycode::SysRq - case XK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; - case XK_Pause: return Keyboard::Keycode::Pause; - //Keyboard::Keycode::Break - - case XK_Insert: return Keyboard::Keycode::Insert; - case XK_Delete: return Keyboard::Keycode::Delete; - case XK_Home: return Keyboard::Keycode::Home; - case XK_End: return Keyboard::Keycode::End; - case XK_Prior: return Keyboard::Keycode::PageUp; - case XK_Next: return Keyboard::Keycode::PageDown; - - case XK_Up: return Keyboard::Keycode::Up; - case XK_Down: return Keyboard::Keycode::Down; - case XK_Left: return Keyboard::Keycode::Left; - case XK_Right: return Keyboard::Keycode::Right; - - case XK_grave: return Keyboard::Keycode::Grave; - case XK_1: return Keyboard::Keycode::Number1; - case XK_2: return Keyboard::Keycode::Number2; - case XK_3: return Keyboard::Keycode::Number3; - case XK_4: return Keyboard::Keycode::Number4; - case XK_5: return Keyboard::Keycode::Number5; - case XK_6: return Keyboard::Keycode::Number6; - case XK_7: return Keyboard::Keycode::Number7; - case XK_8: return Keyboard::Keycode::Number8; - case XK_9: return Keyboard::Keycode::Number9; - case XK_0: return Keyboard::Keycode::Number0; - case XK_minus: return Keyboard::Keycode::Minus; - case XK_equal: return Keyboard::Keycode::Equal; - case XK_BackSpace: return Keyboard::Keycode::Backspace; - - case XK_asciitilde: return Keyboard::Keycode::Tilde; - case XK_exclam: return Keyboard::Keycode::Exclamation; - case XK_at: return Keyboard::Keycode::At; - case XK_numbersign: return Keyboard::Keycode::Pound; - case XK_dollar: return Keyboard::Keycode::Dollar; - case XK_percent: return Keyboard::Keycode::Percent; - case XK_asciicircum: return Keyboard::Keycode::Power; - case XK_ampersand: return Keyboard::Keycode::Ampersand; - case XK_asterisk: return Keyboard::Keycode::Asterisk; - case XK_parenleft: return Keyboard::Keycode::ParenthesisLeft; - case XK_parenright: return Keyboard::Keycode::ParenthesisRight; - case XK_underscore: return Keyboard::Keycode::Underscore; - case XK_plus: return Keyboard::Keycode::Plus; - - case XK_bracketleft: return Keyboard::Keycode::BracketLeft; - case XK_bracketright: return Keyboard::Keycode::BracketRight; - case XK_backslash: return Keyboard::Keycode::Backslash; - case XK_semicolon: return Keyboard::Keycode::Semicolon; - case XK_apostrophe: return Keyboard::Keycode::Apostrophe; - case XK_comma: return Keyboard::Keycode::Comma; - case XK_period: return Keyboard::Keycode::Period; - case XK_slash: return Keyboard::Keycode::Slash; - - case XK_braceleft: return Keyboard::Keycode::BraceLeft; - case XK_braceright: return Keyboard::Keycode::BraceRight; - case XK_bar: return Keyboard::Keycode::Pipe; - case XK_colon: return Keyboard::Keycode::Colon; - case XK_quotedbl: return Keyboard::Keycode::Quote; - case XK_less: return Keyboard::Keycode::CaretLeft; - case XK_greater: return Keyboard::Keycode::CaretRight; - case XK_question: return Keyboard::Keycode::Question; - - case XK_Tab: return Keyboard::Keycode::Tab; - case XK_Caps_Lock: return Keyboard::Keycode::CapsLock; - case XK_Return: return Keyboard::Keycode::Return; - case XK_Shift_L: return Keyboard::Keycode::ShiftLeft; - case XK_Shift_R: return Keyboard::Keycode::ShiftRight; - case XK_Control_L: return Keyboard::Keycode::ControlLeft; - case XK_Control_R: return Keyboard::Keycode::ControlRight; - case XK_Super_L: return Keyboard::Keycode::SuperLeft; - case XK_Super_R: return Keyboard::Keycode::SuperRight; - case XK_Alt_L: return Keyboard::Keycode::AltLeft; - case XK_Alt_R: return Keyboard::Keycode::AltRight; - case XK_space: return Keyboard::Keycode::Space; - case XK_Menu: return Keyboard::Keycode::Menu; - - case XK_A: return Keyboard::Keycode::A; - case XK_B: return Keyboard::Keycode::B; - case XK_C: return Keyboard::Keycode::C; - case XK_D: return Keyboard::Keycode::D; - case XK_E: return Keyboard::Keycode::E; - case XK_F: return Keyboard::Keycode::F; - case XK_G: return Keyboard::Keycode::G; - case XK_H: return Keyboard::Keycode::H; - case XK_I: return Keyboard::Keycode::I; - case XK_J: return Keyboard::Keycode::J; - case XK_K: return Keyboard::Keycode::K; - case XK_L: return Keyboard::Keycode::L; - case XK_M: return Keyboard::Keycode::M; - case XK_N: return Keyboard::Keycode::N; - case XK_O: return Keyboard::Keycode::O; - case XK_P: return Keyboard::Keycode::P; - case XK_Q: return Keyboard::Keycode::Q; - case XK_R: return Keyboard::Keycode::R; - case XK_S: return Keyboard::Keycode::S; - case XK_T: return Keyboard::Keycode::T; - case XK_U: return Keyboard::Keycode::U; - case XK_V: return Keyboard::Keycode::V; - case XK_W: return Keyboard::Keycode::W; - case XK_X: return Keyboard::Keycode::X; - case XK_Y: return Keyboard::Keycode::Y; - case XK_Z: return Keyboard::Keycode::Z; - - case XK_a: return Keyboard::Keycode::a; - case XK_b: return Keyboard::Keycode::b; - case XK_c: return Keyboard::Keycode::c; - case XK_d: return Keyboard::Keycode::d; - case XK_e: return Keyboard::Keycode::e; - case XK_f: return Keyboard::Keycode::f; - case XK_g: return Keyboard::Keycode::g; - case XK_h: return Keyboard::Keycode::h; - case XK_i: return Keyboard::Keycode::i; - case XK_j: return Keyboard::Keycode::j; - case XK_k: return Keyboard::Keycode::k; - case XK_l: return Keyboard::Keycode::l; - case XK_m: return Keyboard::Keycode::m; - case XK_n: return Keyboard::Keycode::n; - case XK_o: return Keyboard::Keycode::o; - case XK_p: return Keyboard::Keycode::p; - case XK_q: return Keyboard::Keycode::q; - case XK_r: return Keyboard::Keycode::r; - case XK_s: return Keyboard::Keycode::s; - case XK_t: return Keyboard::Keycode::t; - case XK_u: return Keyboard::Keycode::u; - case XK_v: return Keyboard::Keycode::v; - case XK_w: return Keyboard::Keycode::w; - case XK_x: return Keyboard::Keycode::x; - case XK_y: return Keyboard::Keycode::y; - case XK_z: return Keyboard::Keycode::z; - - case XK_Num_Lock: return Keyboard::Keycode::NumLock; - case XK_KP_Divide: return Keyboard::Keycode::Divide; - case XK_KP_Multiply: return Keyboard::Keycode::Multiply; - case XK_KP_Subtract: return Keyboard::Keycode::Subtract; - case XK_KP_Add: return Keyboard::Keycode::Add; - case XK_KP_Enter: return Keyboard::Keycode::Enter; - case XK_KP_Decimal: return Keyboard::Keycode::Point; - - case XK_KP_1: return Keyboard::Keycode::Keypad1; - case XK_KP_2: return Keyboard::Keycode::Keypad2; - case XK_KP_3: return Keyboard::Keycode::Keypad3; - case XK_KP_4: return Keyboard::Keycode::Keypad4; - case XK_KP_5: return Keyboard::Keycode::Keypad5; - case XK_KP_6: return Keyboard::Keycode::Keypad6; - case XK_KP_7: return Keyboard::Keycode::Keypad7; - case XK_KP_8: return Keyboard::Keycode::Keypad8; - case XK_KP_9: return Keyboard::Keycode::Keypad9; - case XK_KP_0: return Keyboard::Keycode::Keypad0; - - case XK_KP_Home: return Keyboard::Keycode::KeypadHome; - case XK_KP_End: return Keyboard::Keycode::KeypadEnd; - case XK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; - case XK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; - case XK_KP_Up: return Keyboard::Keycode::KeypadUp; - case XK_KP_Down: return Keyboard::Keycode::KeypadDown; - case XK_KP_Left: return Keyboard::Keycode::KeypadLeft; - case XK_KP_Right: return Keyboard::Keycode::KeypadRight; - case XK_KP_Begin: return Keyboard::Keycode::KeypadCenter; - case XK_KP_Insert: return Keyboard::Keycode::KeypadInsert; - case XK_KP_Delete: return Keyboard::Keycode::KeypadDelete; - } - return Keyboard::Keycode::None; -} -*/ - } diff --git a/hiro/qt/widget/canvas.cpp b/hiro/qt/widget/canvas.cpp index 677c1e3356..42fae7627f 100644 --- a/hiro/qt/widget/canvas.cpp +++ b/hiro/qt/widget/canvas.cpp @@ -57,8 +57,8 @@ auto pCanvas::update() -> void { } auto pCanvas::_rasterize() -> void { - int width = 0; - int height = 0; + s32 width = 0; + s32 height = 0; if(auto& icon = state().icon) { width = icon.width(); @@ -74,10 +74,10 @@ auto pCanvas::_rasterize() -> void { qtImageHeight = height; if(!qtImage) qtImage = new QImage(width, height, QImage::Format_ARGB32); - auto buffer = (uint32_t*)qtImage->bits(); + auto buffer = (u32*)qtImage->bits(); if(auto& icon = state().icon) { - memory::copy(buffer, state().icon.data(), width * height); + memory::copy(buffer, state().icon.data(), width * height); } else if(auto& gradient = state().gradient) { auto& colors = gradient.state.colors; image fill; @@ -85,7 +85,7 @@ auto pCanvas::_rasterize() -> void { fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value()); memory::copy(buffer, fill.data(), fill.size()); } else { - uint32_t color = state().color.value(); + u32 color = state().color.value(); for(auto n : range(width * height)) buffer[n] = color; } } @@ -136,9 +136,9 @@ auto QtCanvas::mouseReleaseEvent(QMouseEvent* event) -> void { auto QtCanvas::paintEvent(QPaintEvent* event) -> void { if(!p.qtImage) return; - signed sx = 0, sy = 0, dx = 0, dy = 0; - signed width = p.qtImageWidth; - signed height = p.qtImageHeight; + s32 sx = 0, sy = 0, dx = 0, dy = 0; + s32 width = p.qtImageWidth; + s32 height = p.qtImageHeight; auto geometry = p.pSizable::state().geometry; auto alignment = p.state().alignment ? p.state().alignment : Alignment{0.5, 0.5}; diff --git a/hiro/qt/widget/canvas.hpp b/hiro/qt/widget/canvas.hpp index 58cee99461..e7df9f8b54 100644 --- a/hiro/qt/widget/canvas.hpp +++ b/hiro/qt/widget/canvas.hpp @@ -20,8 +20,8 @@ struct pCanvas : pWidget { QtCanvas* qtCanvas = nullptr; QImage* qtImage = nullptr; - unsigned qtImageWidth = 0; - unsigned qtImageHeight = 0; + u32 qtImageWidth = 0; + u32 qtImageHeight = 0; }; } diff --git a/hiro/qt/widget/check-label.cpp b/hiro/qt/widget/check-label.cpp index d5b9de233b..cc2c71e59c 100644 --- a/hiro/qt/widget/check-label.cpp +++ b/hiro/qt/widget/check-label.cpp @@ -4,7 +4,7 @@ namespace hiro { auto pCheckLabel::construct() -> void { qtWidget = qtCheckLabel = new QtCheckLabel(*this); - qtCheckLabel->connect(qtCheckLabel, SIGNAL(stateChanged(int)), SLOT(onToggle())); + qtCheckLabel->connect(qtCheckLabel, SIGNAL(stateChanged(s32)), SLOT(onToggle())); pWidget::construct(); _setState(); diff --git a/hiro/qt/widget/combo-button.cpp b/hiro/qt/widget/combo-button.cpp index 41b76684d4..a03986e255 100644 --- a/hiro/qt/widget/combo-button.cpp +++ b/hiro/qt/widget/combo-button.cpp @@ -4,7 +4,7 @@ namespace hiro { auto pComboButton::construct() -> void { qtWidget = qtComboButton = new QtComboButton(*this); - qtComboButton->connect(qtComboButton, SIGNAL(currentIndexChanged(int)), SLOT(onChange(int))); + qtComboButton->connect(qtComboButton, SIGNAL(currentIndexChanged(s32)), SLOT(onChange(s32))); pWidget::construct(); } @@ -35,7 +35,7 @@ auto pComboButton::reset() -> void { while(qtComboButton->count()) qtComboButton->removeItem(0); } -auto QtComboButton::onChange(int offset) -> void { +auto QtComboButton::onChange(s32 offset) -> void { for(auto& item : p.state().items) { item->state.selected = false; } diff --git a/hiro/qt/widget/hex-edit.cpp b/hiro/qt/widget/hex-edit.cpp index 5607e11cc0..d2577fc913 100644 --- a/hiro/qt/widget/hex-edit.cpp +++ b/hiro/qt/widget/hex-edit.cpp @@ -19,7 +19,7 @@ auto pHexEdit::construct() -> void { qtScrollBar->setSingleStep(1); qtLayout->addWidget(qtScrollBar); - qtScrollBar->connect(qtScrollBar, SIGNAL(actionTriggered(int)), SLOT(onScroll())); + qtScrollBar->connect(qtScrollBar, SIGNAL(actionTriggered(s32)), SLOT(onScroll())); pWidget::construct(); setBackgroundColor(state().backgroundColor); @@ -36,7 +36,7 @@ auto pHexEdit::destruct() -> void { qtScrollBar = nullptr; } -auto pHexEdit::setAddress(unsigned address) -> void { +auto pHexEdit::setAddress(u32 address) -> void { _setState(); } @@ -49,7 +49,7 @@ auto pHexEdit::setBackgroundColor(Color color) -> void { qtHexEdit->setAutoFillBackground((bool)color); } -auto pHexEdit::setColumns(unsigned columns) -> void { +auto pHexEdit::setColumns(u32 columns) -> void { _setState(); } @@ -61,11 +61,11 @@ auto pHexEdit::setForegroundColor(Color color) -> void { qtHexEdit->setPalette(palette); } -auto pHexEdit::setLength(unsigned length) -> void { +auto pHexEdit::setLength(u32 length) -> void { _setState(); } -auto pHexEdit::setRows(unsigned rows) -> void { +auto pHexEdit::setRows(u32 rows) -> void { _setState(); } @@ -75,20 +75,20 @@ auto pHexEdit::update() -> void { return; } - unsigned cursorPosition = qtHexEdit->textCursor().position(); + u32 cursorPosition = qtHexEdit->textCursor().position(); string output; - unsigned address = state().address; - for(unsigned row = 0; row < state().rows; row++) { + u32 address = state().address; + for(u32 row = 0; row < state().rows; row++) { output.append(hex(address, 8L)); output.append(" "); string hexdata; string ansidata = " "; - for(unsigned column = 0; column < state().columns; column++) { + for(u32 column = 0; column < state().columns; column++) { if(address < state().length) { - uint8_t data = self().doRead(address++); + u8 data = self().doRead(address++); hexdata.append(hex(data, 2L)); hexdata.append(" "); ansidata.append(data >= 0x20 && data <= 0x7e ? (char)data : '.'); @@ -123,11 +123,11 @@ auto pHexEdit::_keyPressEvent(QKeyEvent* event) -> void { if(event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) return; QTextCursor cursor = qtHexEdit->textCursor(); - signed lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 1; - signed cursorY = cursor.position() / lineWidth; - signed cursorX = cursor.position() % lineWidth; + s32 lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 1; + s32 cursorY = cursor.position() / lineWidth; + s32 cursorX = cursor.position() % lineWidth; - unsigned nibble = 0; + u32 nibble = 0; switch(event->key()) { default: return; @@ -210,10 +210,10 @@ auto pHexEdit::_keyPressEvent(QKeyEvent* event) -> void { cursorX /= 3; if(cursorX < state().columns) { //not in ANSI region - unsigned address = state().address + (cursorY * state().columns + cursorX); + u32 address = state().address + (cursorY * state().columns + cursorX); if(address >= state().length) return; //do not edit past end of file - uint8_t data = self().doRead(address); + u8 data = self().doRead(address); //write modified value if(cursorNibble == 1) { @@ -224,7 +224,7 @@ auto pHexEdit::_keyPressEvent(QKeyEvent* event) -> void { self().doWrite(address, data); //auto-advance cursor to next nibble/byte - unsigned step = 1; + u32 step = 1; if(cursorNibble && cursorX != state().columns - 1) step = 2; cursor.setPosition(cursor.position() + step); qtHexEdit->setTextCursor(cursor); @@ -237,16 +237,16 @@ auto pHexEdit::_keyPressEvent(QKeyEvent* event) -> void { } //number of actual rows -auto pHexEdit::_rows() -> signed { +auto pHexEdit::_rows() -> s32 { return (max(1u, state().length) + state().columns - 1) / state().columns; } //number of scrollable row positions -auto pHexEdit::_rowsScrollable() -> signed { +auto pHexEdit::_rowsScrollable() -> s32 { return max(0u, _rows() - state().rows); } -auto pHexEdit::_scrollTo(signed position) -> void { +auto pHexEdit::_scrollTo(s32 position) -> void { if(position > _rowsScrollable()) position = _rowsScrollable(); if(position < 0) position = 0; qtScrollBar->setSliderPosition(position); @@ -272,7 +272,7 @@ auto QtHexEdit::keyPressEventAcknowledge(QKeyEvent* event) -> void { auto QtHexEdit::wheelEvent(QWheelEvent* event) -> void { if(event->orientation() == Qt::Vertical) { - signed offset = event->delta() < 0 ? +1 : -1; + s32 offset = event->delta() < 0 ? +1 : -1; p._scrollTo(p.qtScrollBar->sliderPosition() + offset); event->accept(); } @@ -282,7 +282,7 @@ auto QtHexEditScrollBar::event(QEvent* event) -> bool { if(event->type() == QEvent::Wheel) { auto wheelEvent = (QWheelEvent*)event; if(wheelEvent->orientation() == Qt::Vertical) { - signed offset = wheelEvent->delta() < 0 ? +1 : -1; + s32 offset = wheelEvent->delta() < 0 ? +1 : -1; p._scrollTo(sliderPosition() + offset); return true; } @@ -292,7 +292,7 @@ auto QtHexEditScrollBar::event(QEvent* event) -> bool { auto QtHexEditScrollBar::onScroll() -> void { if(p.locked()) return; - unsigned address = sliderPosition(); + u32 address = sliderPosition(); p.state().address = address * p.state().columns; p.update(); } diff --git a/hiro/qt/widget/hex-edit.hpp b/hiro/qt/widget/hex-edit.hpp index 3718a840e3..53caae79e0 100644 --- a/hiro/qt/widget/hex-edit.hpp +++ b/hiro/qt/widget/hex-edit.hpp @@ -5,18 +5,18 @@ namespace hiro { struct pHexEdit : pWidget { Declare(HexEdit, Widget) - auto setAddress(unsigned address) -> void; + auto setAddress(u32 address) -> void; auto setBackgroundColor(Color color) -> void; - auto setColumns(unsigned columns) -> void; + auto setColumns(u32 columns) -> void; auto setForegroundColor(Color color) -> void; - auto setLength(unsigned length) -> void; - auto setRows(unsigned rows) -> void; + auto setLength(u32 length) -> void; + auto setRows(u32 rows) -> void; auto update() -> void; auto _keyPressEvent(QKeyEvent*) -> void; - auto _rows() -> signed; - auto _rowsScrollable() -> signed; - auto _scrollTo(signed position) -> void; + auto _rows() -> s32; + auto _rowsScrollable() -> s32; + auto _scrollTo(s32 position) -> void; auto _setState() -> void; QtHexEdit* qtHexEdit = nullptr; diff --git a/hiro/qt/widget/horizontal-scroll-bar.cpp b/hiro/qt/widget/horizontal-scroll-bar.cpp index 284e79eb8b..cf1de8f1bf 100644 --- a/hiro/qt/widget/horizontal-scroll-bar.cpp +++ b/hiro/qt/widget/horizontal-scroll-bar.cpp @@ -6,7 +6,7 @@ auto pHorizontalScrollBar::construct() -> void { qtWidget = qtHorizontalScrollBar = new QtHorizontalScrollBar(*this); qtHorizontalScrollBar->setRange(0, 100); qtHorizontalScrollBar->setPageStep(101 >> 3); - qtHorizontalScrollBar->connect(qtHorizontalScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); + qtHorizontalScrollBar->connect(qtHorizontalScrollBar, SIGNAL(valueChanged(s32)), SLOT(onChange())); pWidget::construct(); _setState(); @@ -21,16 +21,16 @@ auto pHorizontalScrollBar::minimumSize() const -> Size { return {0, 15}; } -auto pHorizontalScrollBar::setLength(unsigned length) -> void { +auto pHorizontalScrollBar::setLength(u32 length) -> void { _setState(); } -auto pHorizontalScrollBar::setPosition(unsigned position) -> void { +auto pHorizontalScrollBar::setPosition(u32 position) -> void { _setState(); } auto pHorizontalScrollBar::_setState() -> void { - signed length = state().length + (state().length == 0); + s32 length = state().length + (state().length == 0); qtHorizontalScrollBar->setRange(0, length - 1); qtHorizontalScrollBar->setPageStep(length >> 3); qtHorizontalScrollBar->setValue(state().position); diff --git a/hiro/qt/widget/horizontal-scroll-bar.hpp b/hiro/qt/widget/horizontal-scroll-bar.hpp index f8766f04eb..9e7b9add0c 100644 --- a/hiro/qt/widget/horizontal-scroll-bar.hpp +++ b/hiro/qt/widget/horizontal-scroll-bar.hpp @@ -6,8 +6,8 @@ struct pHorizontalScrollBar : pWidget { Declare(HorizontalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto _setState() -> void; diff --git a/hiro/qt/widget/horizontal-slider.cpp b/hiro/qt/widget/horizontal-slider.cpp index 672a0423e7..dec5662551 100644 --- a/hiro/qt/widget/horizontal-slider.cpp +++ b/hiro/qt/widget/horizontal-slider.cpp @@ -6,11 +6,11 @@ auto pHorizontalSlider::minimumSize() const -> Size { return {0, 20}; } -auto pHorizontalSlider::setLength(unsigned length) -> void { +auto pHorizontalSlider::setLength(u32 length) -> void { _setState(); } -auto pHorizontalSlider::setPosition(unsigned position) -> void { +auto pHorizontalSlider::setPosition(u32 position) -> void { _setState(); } @@ -18,7 +18,7 @@ auto pHorizontalSlider::construct() -> void { qtWidget = qtHorizontalSlider = new QtHorizontalSlider(*this); qtHorizontalSlider->setRange(0, 100); qtHorizontalSlider->setPageStep(101 >> 3); - qtHorizontalSlider->connect(qtHorizontalSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); + qtHorizontalSlider->connect(qtHorizontalSlider, SIGNAL(valueChanged(s32)), SLOT(onChange())); pWidget::construct(); _setState(); @@ -30,7 +30,7 @@ auto pHorizontalSlider::destruct() -> void { } auto pHorizontalSlider::_setState() -> void { - signed length = state().length + (state().length == 0); + s32 length = state().length + (state().length == 0); qtHorizontalSlider->setRange(0, length - 1); qtHorizontalSlider->setPageStep(length >> 3); qtHorizontalSlider->setValue(state().position); diff --git a/hiro/qt/widget/horizontal-slider.hpp b/hiro/qt/widget/horizontal-slider.hpp index e1dea2f8a9..3224988ff3 100644 --- a/hiro/qt/widget/horizontal-slider.hpp +++ b/hiro/qt/widget/horizontal-slider.hpp @@ -6,8 +6,8 @@ struct pHorizontalSlider : pWidget { Declare(HorizontalSlider, Widget) auto minimumSize() const -> Size; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto _setState() -> void; diff --git a/hiro/qt/widget/progress-bar.cpp b/hiro/qt/widget/progress-bar.cpp index 995f5e270b..eadd00c8b8 100644 --- a/hiro/qt/widget/progress-bar.cpp +++ b/hiro/qt/widget/progress-bar.cpp @@ -20,7 +20,7 @@ auto pProgressBar::minimumSize() const -> Size { return {0, 25}; } -auto pProgressBar::setPosition(unsigned position) -> void { +auto pProgressBar::setPosition(u32 position) -> void { _setState(); } diff --git a/hiro/qt/widget/progress-bar.hpp b/hiro/qt/widget/progress-bar.hpp index 9e12bdda53..e82a8c9614 100644 --- a/hiro/qt/widget/progress-bar.hpp +++ b/hiro/qt/widget/progress-bar.hpp @@ -6,7 +6,7 @@ struct pProgressBar : pWidget { Declare(ProgressBar, Widget) auto minimumSize() const -> Size override; - auto setPosition(unsigned position) -> void; + auto setPosition(u32 position) -> void; auto _setState() -> void; diff --git a/hiro/qt/widget/tab-frame.cpp b/hiro/qt/widget/tab-frame.cpp index 4d30187450..63ce27aa7f 100644 --- a/hiro/qt/widget/tab-frame.cpp +++ b/hiro/qt/widget/tab-frame.cpp @@ -4,7 +4,7 @@ namespace hiro { auto pTabFrame::construct() -> void { qtWidget = qtTabFrame = new QtTabFrame(*this); - qtTabFrame->connect(qtTabFrame, SIGNAL(currentChanged(int)), SLOT(onChange(int))); + qtTabFrame->connect(qtTabFrame, SIGNAL(currentChanged(s32)), SLOT(onChange(s32))); pWidget::construct(); _setState(); @@ -53,7 +53,7 @@ auto QtTabFrame::showEvent(QShowEvent* event) -> void { p._setState(); //needed to capture geometry of TabFrame for TabFrameItem layouts } -auto QtTabFrame::onChange(int selection) -> void { +auto QtTabFrame::onChange(s32 selection) -> void { //geometry of tab frames is only valid once said tab frame is visible //as such, as need to call _setState() to update the TabFrameItem's geometry here if(auto item = p.self().item(selection)) { diff --git a/hiro/qt/widget/table-view-column.cpp b/hiro/qt/widget/table-view-column.cpp index 4a7e88bea7..3c9e4630a3 100644 --- a/hiro/qt/widget/table-view-column.cpp +++ b/hiro/qt/widget/table-view-column.cpp @@ -88,7 +88,7 @@ auto pTableViewColumn::setVisible(bool visible) -> void { _setState(); } -auto pTableViewColumn::setWidth(signed width) -> void { +auto pTableViewColumn::setWidth(s32 width) -> void { _setState(); } diff --git a/hiro/qt/widget/table-view-column.hpp b/hiro/qt/widget/table-view-column.hpp index 0355218a54..622d99abba 100644 --- a/hiro/qt/widget/table-view-column.hpp +++ b/hiro/qt/widget/table-view-column.hpp @@ -19,7 +19,7 @@ struct pTableViewColumn : pObject { auto setText(const string& text) -> void; auto setVerticalAlignment(double alignment) -> void; auto setVisible(bool visible) -> void; - auto setWidth(signed width) -> void; + auto setWidth(s32 width) -> void; auto _parent() -> maybe; auto _setState() -> void; diff --git a/hiro/qt/widget/table-view.cpp b/hiro/qt/widget/table-view.cpp index 195e2e8a35..b52a3dc593 100644 --- a/hiro/qt/widget/table-view.cpp +++ b/hiro/qt/widget/table-view.cpp @@ -17,11 +17,11 @@ auto pTableView::construct() -> void { qtTableViewDelegate = new QtTableViewDelegate(*this); qtTableView->setItemDelegate(qtTableViewDelegate); - qtTableView->connect(qtTableView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate(QTreeWidgetItem*, int))); + qtTableView->connect(qtTableView, SIGNAL(itemActivated(QTreeWidgetItem*, s32)), SLOT(onActivate(QTreeWidgetItem*, s32))); qtTableView->connect(qtTableView, SIGNAL(itemSelectionChanged()), SLOT(onChange())); qtTableView->connect(qtTableView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext())); - qtTableView->connect(qtTableView->header(), SIGNAL(sectionClicked(int)), SLOT(onSort(int))); - qtTableView->connect(qtTableView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*, int))); + qtTableView->connect(qtTableView->header(), SIGNAL(sectionClicked(s32)), SLOT(onSort(s32))); + qtTableView->connect(qtTableView, SIGNAL(itemChanged(QTreeWidgetItem*, s32)), SLOT(onToggle(QTreeWidgetItem*, s32))); setBackgroundColor(state().backgroundColor); setBatchable(state().batchable); @@ -62,28 +62,28 @@ auto pTableView::remove(sTableViewItem item) -> void { auto pTableView::resizeColumns() -> void { auto lock = acquire(); - vector widths; - signed minimumWidth = 0; - signed expandable = 0; + vector widths; + s32 minimumWidth = 0; + s32 expandable = 0; for(auto column : range(self().columnCount())) { - signed width = _width(column); + s32 width = _width(column); widths.append(width); minimumWidth += width; if(self().column(column).expandable()) expandable++; } - signed maximumWidth = self().geometry().width() - 6; + s32 maximumWidth = self().geometry().width() - 6; if(auto scrollBar = qtTableView->verticalScrollBar()) { if(scrollBar->isVisible()) maximumWidth -= scrollBar->geometry().width(); } - signed expandWidth = 0; + s32 expandWidth = 0; if(expandable && maximumWidth > minimumWidth) { expandWidth = (maximumWidth - minimumWidth) / expandable; } for(auto column : range(self().columnCount())) { - signed width = widths[column]; + s32 width = widths[column]; if(self().column(column).expandable()) width += expandWidth; qtTableView->setColumnWidth(column, width); } @@ -141,9 +141,9 @@ auto pTableView::_onSize() -> void { } } -auto pTableView::_width(unsigned column) -> unsigned { +auto pTableView::_width(u32 column) -> u32 { if(auto width = self().column(column).width()) return width; - unsigned width = 1; + u32 width = 1; if(!self().column(column).visible()) return width; if(state().headered) width = max(width, _widthOfColumn(column)); for(auto row : range(state().items.size())) { @@ -152,8 +152,8 @@ auto pTableView::_width(unsigned column) -> unsigned { return width; } -auto pTableView::_widthOfColumn(unsigned _column) -> unsigned { - unsigned width = 8; +auto pTableView::_widthOfColumn(u32 _column) -> u32 { + u32 width = 8; if(auto column = self().column(_column)) { if(auto& icon = column->state.icon) { width += icon.width() + 4; @@ -168,8 +168,8 @@ auto pTableView::_widthOfColumn(unsigned _column) -> unsigned { return width; } -auto pTableView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned { - unsigned width = 8; +auto pTableView::_widthOfCell(u32 _row, u32 _column) -> u32 { + u32 width = 8; if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(cell->state.checkable) { @@ -186,7 +186,7 @@ auto pTableView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned { return width; } -auto QtTableView::onActivate(QTreeWidgetItem* qtItem, int column) -> void { +auto QtTableView::onActivate(QTreeWidgetItem* qtItem, s32 column) -> void { if(p.locked()) return; for(auto& item : p.state().items) { @@ -216,13 +216,13 @@ auto QtTableView::onContext() -> void { if(!p.locked()) p.self().doContext(); } -auto QtTableView::onSort(int columnNumber) -> void { +auto QtTableView::onSort(s32 columnNumber) -> void { if(auto column = p.self().column(columnNumber)) { if(!p.locked() && p.state().sortable) p.self().doSort(column); } } -auto QtTableView::onToggle(QTreeWidgetItem* qtItem, int column) -> void { +auto QtTableView::onToggle(QTreeWidgetItem* qtItem, s32 column) -> void { for(auto& item : p.state().items) { if(auto self = item->self()) { if(qtItem == self->qtItem) { diff --git a/hiro/qt/widget/table-view.hpp b/hiro/qt/widget/table-view.hpp index ff1a9342aa..2328a52b70 100644 --- a/hiro/qt/widget/table-view.hpp +++ b/hiro/qt/widget/table-view.hpp @@ -19,9 +19,9 @@ struct pTableView : pWidget { auto setSortable(bool sortable) -> void; auto _onSize() -> void; - auto _width(unsigned column) -> unsigned; - auto _widthOfColumn(unsigned column) -> unsigned; - auto _widthOfCell(unsigned row, unsigned column) -> unsigned; + auto _width(u32 column) -> u32; + auto _widthOfColumn(u32 column) -> u32; + auto _widthOfCell(u32 row, u32 column) -> u32; QtTableView* qtTableView = nullptr; QtTableViewDelegate* qtTableViewDelegate = nullptr; diff --git a/hiro/qt/widget/text-edit.cpp b/hiro/qt/widget/text-edit.cpp index 75ff1beeaf..897d1fed55 100644 --- a/hiro/qt/widget/text-edit.cpp +++ b/hiro/qt/widget/text-edit.cpp @@ -62,7 +62,7 @@ auto pTextEdit::textCursor() const -> TextCursor { auto pTextEdit::_setState() -> void { QTextCursor cursor = qtTextEdit->textCursor(); - signed lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData()); + s32 lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData()); cursor.setPosition(max(0, min(lastCharacter, state().textCursor.offset()))); cursor.setPosition(max(0, min(lastCharacter, state().textCursor.offset() + state().textCursor.length())), QTextCursor::KeepAnchor); qtTextEdit->setTextCursor(cursor); diff --git a/hiro/qt/widget/vertical-scroll-bar.cpp b/hiro/qt/widget/vertical-scroll-bar.cpp index b470ffdc34..5b19dfc929 100644 --- a/hiro/qt/widget/vertical-scroll-bar.cpp +++ b/hiro/qt/widget/vertical-scroll-bar.cpp @@ -6,7 +6,7 @@ auto pVerticalScrollBar::construct() -> void { qtWidget = qtVerticalScrollBar = new QtVerticalScrollBar(*this); qtVerticalScrollBar->setRange(0, 100); qtVerticalScrollBar->setPageStep(101 >> 3); - qtVerticalScrollBar->connect(qtVerticalScrollBar, SIGNAL(valueChanged(int)), SLOT(onChange())); + qtVerticalScrollBar->connect(qtVerticalScrollBar, SIGNAL(valueChanged(s32)), SLOT(onChange())); pWidget::construct(); _setState(); @@ -21,16 +21,16 @@ auto pVerticalScrollBar::minimumSize() const -> Size { return {15, 0}; } -auto pVerticalScrollBar::setLength(unsigned length) -> void { +auto pVerticalScrollBar::setLength(u32 length) -> void { _setState(); } -auto pVerticalScrollBar::setPosition(unsigned position) -> void { +auto pVerticalScrollBar::setPosition(u32 position) -> void { _setState(); } auto pVerticalScrollBar::_setState() -> void { - signed length = state().length + (state().length == 0); + s32 length = state().length + (state().length == 0); qtVerticalScrollBar->setRange(0, length - 1); qtVerticalScrollBar->setPageStep(length >> 3); qtVerticalScrollBar->setValue(state().position); diff --git a/hiro/qt/widget/vertical-scroll-bar.hpp b/hiro/qt/widget/vertical-scroll-bar.hpp index 9a8f7619d9..881ce9322e 100644 --- a/hiro/qt/widget/vertical-scroll-bar.hpp +++ b/hiro/qt/widget/vertical-scroll-bar.hpp @@ -6,8 +6,8 @@ struct pVerticalScrollBar : pWidget { Declare(VerticalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto _setState() -> void; diff --git a/hiro/qt/widget/vertical-slider.cpp b/hiro/qt/widget/vertical-slider.cpp index 56e27c4174..faa1e57baf 100644 --- a/hiro/qt/widget/vertical-slider.cpp +++ b/hiro/qt/widget/vertical-slider.cpp @@ -6,11 +6,11 @@ auto pVerticalSlider::minimumSize() const -> Size { return {20, 0}; } -auto pVerticalSlider::setLength(unsigned length) -> void { +auto pVerticalSlider::setLength(u32 length) -> void { _setState(); } -auto pVerticalSlider::setPosition(unsigned position) -> void { +auto pVerticalSlider::setPosition(u32 position) -> void { _setState(); } @@ -19,7 +19,7 @@ auto pVerticalSlider::construct() -> void { qtVerticalSlider->setInvertedAppearance(true); qtVerticalSlider->setRange(0, 100); qtVerticalSlider->setPageStep(101 >> 3); - qtVerticalSlider->connect(qtVerticalSlider, SIGNAL(valueChanged(int)), SLOT(onChange())); + qtVerticalSlider->connect(qtVerticalSlider, SIGNAL(valueChanged(s32)), SLOT(onChange())); pWidget::construct(); _setState(); @@ -31,7 +31,7 @@ auto pVerticalSlider::destruct() -> void { } auto pVerticalSlider::_setState() -> void { - signed length = state().length + (state().length == 0); + s32 length = state().length + (state().length == 0); qtVerticalSlider->setRange(0, length - 1); qtVerticalSlider->setPageStep(length >> 3); qtVerticalSlider->setValue(state().position); diff --git a/hiro/qt/widget/vertical-slider.hpp b/hiro/qt/widget/vertical-slider.hpp index 5d126ae1d9..59329c47da 100644 --- a/hiro/qt/widget/vertical-slider.hpp +++ b/hiro/qt/widget/vertical-slider.hpp @@ -6,8 +6,8 @@ struct pVerticalSlider : pWidget { Declare(VerticalSlider, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto _setState() -> void; diff --git a/hiro/qt/window.cpp b/hiro/qt/window.cpp index e6c4180299..5cd80989d1 100644 --- a/hiro/qt/window.cpp +++ b/hiro/qt/window.cpp @@ -82,8 +82,8 @@ auto pWindow::handle() const -> uintptr_t { return (uintptr_t)qtWindow->winId(); } -auto pWindow::monitor() const -> uint { - int monitor = QDesktopWidget().screenNumber(qtWindow); +auto pWindow::monitor() const -> u32 { + s32 monitor = QDesktopWidget().screenNumber(qtWindow); if(monitor < 0) monitor = Monitor::primary(); return monitor; } @@ -250,15 +250,15 @@ auto pWindow::_append(mWidget& widget) -> void { } } -auto pWindow::_menuHeight() const -> uint { +auto pWindow::_menuHeight() const -> u32 { if(auto& menuBar = state().menuBar) { if(menuBar->visible()) return settings.geometry.menuHeight + _menuTextHeight(); } return 0; } -auto pWindow::_menuTextHeight() const -> uint { - uint height = 0; +auto pWindow::_menuTextHeight() const -> u32 { + u32 height = 0; if(auto& menuBar = state().menuBar) { for(auto& menu : menuBar->state.menus) { height = max(height, menu->font(true).size(menu->text()).height()); @@ -267,15 +267,15 @@ auto pWindow::_menuTextHeight() const -> uint { return height; } -auto pWindow::_statusHeight() const -> uint { +auto pWindow::_statusHeight() const -> u32 { if(auto& statusBar = state().statusBar) { if(statusBar->visible()) return settings.geometry.statusHeight + _statusTextHeight(); } return 0; } -auto pWindow::_statusTextHeight() const -> uint { - uint height = 0; +auto pWindow::_statusTextHeight() const -> u32 { + u32 height = 0; if(auto& statusBar = state().statusBar) { height = statusBar->font(true).size(statusBar->text()).height(); } @@ -367,8 +367,8 @@ auto QtWindow::resizeEvent(QResizeEvent* event) -> void { } auto QtWindow::sizeHint() const -> QSize { - uint width = p.state().geometry.width(); - uint height = p.state().geometry.height(); + u32 width = p.state().geometry.width(); + u32 height = p.state().geometry.height(); height += p._menuHeight(); height += p._statusHeight(); return QSize(width, height); diff --git a/hiro/qt/window.hpp b/hiro/qt/window.hpp index db5a4a1847..944a507135 100644 --- a/hiro/qt/window.hpp +++ b/hiro/qt/window.hpp @@ -11,7 +11,7 @@ struct pWindow : pObject { auto focused() const -> bool override; auto frameMargin() const -> Geometry; auto handle() const -> uintptr_t; - auto monitor() const -> uint; + auto monitor() const -> u32; auto remove(sMenuBar menuBar) -> void; auto remove(sSizable sizable) -> void; auto remove(sStatusBar statusBar) -> void; @@ -32,10 +32,10 @@ struct pWindow : pObject { auto setVisible(bool visible) -> void; auto _append(mWidget& widget) -> void; - auto _menuHeight() const -> uint; - auto _menuTextHeight() const -> uint; - auto _statusHeight() const -> uint; - auto _statusTextHeight() const -> uint; + auto _menuHeight() const -> u32; + auto _menuTextHeight() const -> u32; + auto _statusHeight() const -> u32; + auto _statusTextHeight() const -> u32; auto _updateFrameGeometry() -> void; QtWindow* qtWindow = nullptr; diff --git a/hiro/windows/action/action.hpp b/hiro/windows/action/action.hpp index a7b280f122..baa626a248 100644 --- a/hiro/windows/action/action.hpp +++ b/hiro/windows/action/action.hpp @@ -13,7 +13,7 @@ struct pAction : pObject { auto _parentPopupMenu() -> maybe; auto _synchronize() -> void; - unsigned position = 0; + u32 position = 0; }; } diff --git a/hiro/windows/action/menu.cpp b/hiro/windows/action/menu.cpp index 791d863acc..fc65194307 100644 --- a/hiro/windows/action/menu.cpp +++ b/hiro/windows/action/menu.cpp @@ -49,12 +49,12 @@ auto pMenu::_update() -> void { mi.dwStyle = MNS_NOTIFYBYPOS; //| MNS_MODELESS; SetMenuInfo(hmenu, &mi); - unsigned position = 0; + u32 position = 0; for(auto& action : state().actions) { if(!action->self()) continue; action->self()->position = position; - unsigned enabled = action->enabled() ? 0 : MF_GRAYED; + u32 enabled = action->enabled() ? 0 : MF_GRAYED; MENUITEMINFO mii{sizeof(MENUITEMINFO)}; mii.fMask = MIIM_DATA; diff --git a/hiro/windows/application.cpp b/hiro/windows/application.cpp index de70a800cd..5cb296abb7 100644 --- a/hiro/windows/application.cpp +++ b/hiro/windows/application.cpp @@ -44,6 +44,12 @@ auto pApplication::processEvents() -> void { Application_processDialogMessage(msg); } } + + //process any deferred menu updates + for(auto menu : pApplication::state().menuBarsToRebuild) { + menu->_rebuild(); + } + pApplication::state().menuBarsToRebuild.reset(); } auto Application_processDialogMessage(MSG& msg) -> void { diff --git a/hiro/windows/application.hpp b/hiro/windows/application.hpp index 241d7fe08b..3f8f7b9f72 100644 --- a/hiro/windows/application.hpp +++ b/hiro/windows/application.hpp @@ -14,9 +14,10 @@ struct pApplication { static auto initialize() -> void; struct State { - int modalCount = 0; //number of modal loops - Timer modalTimer; //to run Application during modal events - pToolTip* toolTip = nullptr; //active toolTip + vector menuBarsToRebuild; //deferred menu bars to update + s32 modalCount = 0; //number of modal loops + Timer modalTimer; //to run Application during modal events + pToolTip* toolTip = nullptr; //active toolTip }; static auto state() -> State&; }; diff --git a/hiro/windows/browser-window.cpp b/hiro/windows/browser-window.cpp index a183afd9d9..1612f5ab47 100644 --- a/hiro/windows/browser-window.cpp +++ b/hiro/windows/browser-window.cpp @@ -2,7 +2,7 @@ namespace hiro { -static auto CALLBACK BrowserWindowCallbackProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpdata) -> signed { +static auto CALLBACK BrowserWindowCallbackProc(HWND hwnd, UINT msg, LPARAM lparam, LPARAM lpdata) -> s32 { if(msg == BFFM_INITIALIZED) { if(lpdata) { auto state = (BrowserWindow::State*)lpdata; diff --git a/hiro/windows/font.cpp b/hiro/windows/font.cpp index 4c43269ac4..739d5435b5 100644 --- a/hiro/windows/font.cpp +++ b/hiro/windows/font.cpp @@ -26,7 +26,7 @@ auto pFont::family(const string& family) -> string { } auto pFont::create(const Font& font) -> HFONT { - static float dpi = Monitor::dpi().x(); + static f32 dpi = Monitor::dpi().x(); return CreateFont( -((font.size() ? font.size() : 8) * dpi / 72.0 + 0.5), 0, 0, 0, font.bold() ? FW_BOLD : FW_NORMAL, font.italic(), 0, 0, 0, 0, 0, 0, 0, diff --git a/hiro/windows/keyboard.cpp b/hiro/windows/keyboard.cpp index c269ba373f..150eb2ea34 100644 --- a/hiro/windows/keyboard.cpp +++ b/hiro/windows/keyboard.cpp @@ -10,16 +10,16 @@ auto pKeyboard::poll() -> vector { return result; } -auto pKeyboard::pressed(unsigned code) -> bool { - uint8_t lo = code >> 0; - uint8_t hi = code >> 8; +auto pKeyboard::pressed(u32 code) -> bool { + u8 lo = code >> 0; + u8 hi = code >> 8; if(lo && GetAsyncKeyState(lo) & 0x8000) return true; if(hi && GetAsyncKeyState(hi) & 0x8000) return true; return false; } auto pKeyboard::initialize() -> void { - auto append = [](unsigned lo, unsigned hi = 0) { + auto append = [](u32 lo, u32 hi = 0) { keycodes.append(lo << 0 | hi << 8); }; @@ -32,7 +32,7 @@ auto pKeyboard::initialize() -> void { #undef map } -auto pKeyboard::_translate(unsigned code, unsigned flags) -> signed { +auto pKeyboard::_translate(u32 code, u32 flags) -> s32 { bool numLock = GetKeyState(VK_NUMLOCK); bool capsLock = GetKeyState(VK_CAPITAL); bool shifted = (GetAsyncKeyState(VK_LSHIFT) & 0x8000) || (GetAsyncKeyState(VK_RSHIFT) & 0x8000); diff --git a/hiro/windows/keyboard.hpp b/hiro/windows/keyboard.hpp index 5cf00c82d6..8957482f7a 100644 --- a/hiro/windows/keyboard.hpp +++ b/hiro/windows/keyboard.hpp @@ -4,13 +4,13 @@ namespace hiro { struct pKeyboard { static auto poll() -> vector; - static auto pressed(unsigned code) -> bool; + static auto pressed(u32 code) -> bool; static auto initialize() -> void; - static auto _translate(unsigned code, unsigned flags) -> signed; + static auto _translate(u32 code, u32 flags) -> signed; - static vector keycodes; + static vector keycodes; }; } diff --git a/hiro/windows/menu-bar.cpp b/hiro/windows/menu-bar.cpp index fc2c5bc545..8b8417fdcf 100644 --- a/hiro/windows/menu-bar.cpp +++ b/hiro/windows/menu-bar.cpp @@ -7,6 +7,7 @@ auto pMenuBar::construct() -> void { } auto pMenuBar::destruct() -> void { + pApplication::state().menuBarsToRebuild.removeByValue(this); if(hmenu) { DestroyMenu(hmenu); hmenu = nullptr; } if(auto parent = _parent()) { SetMenu(parent->hwnd, nullptr); @@ -43,7 +44,7 @@ auto pMenuBar::_parent() -> maybe { return nothing; } -auto pMenuBar::_update() -> void { +auto pMenuBar::_rebuild() -> void { if(hmenu) DestroyMenu(hmenu); hmenu = CreateMenu(); @@ -52,11 +53,11 @@ auto pMenuBar::_update() -> void { mi.dwStyle = MNS_NOTIFYBYPOS; //| MNS_MODELESS; SetMenuInfo(hmenu, &mi); - unsigned position = 0; + u32 position = 0; #if defined(Hiro_Menu) for(auto& menu : state().menus) { - unsigned enabled = menu->enabled() ? 0 : MF_GRAYED; + u32 enabled = menu->enabled() ? 0 : MF_GRAYED; MENUITEMINFO mii{sizeof(MENUITEMINFO)}; mii.fMask = MIIM_DATA; @@ -78,6 +79,17 @@ auto pMenuBar::_update() -> void { } } +auto pMenuBar::_update() -> void { + //if there is no menu bar, build it immediately to ensure correct window geometry calculations + if(auto parent = _parent()) { + if(!GetMenu(parent->hwnd)) return _rebuild(); + } + + //otherwise, defer the menu bar update for later to reduce flickering + pApplication::state().menuBarsToRebuild.removeByValue(this); + pApplication::state().menuBarsToRebuild.append(this); +} + } #endif diff --git a/hiro/windows/menu-bar.hpp b/hiro/windows/menu-bar.hpp index b804f256d0..def62b7170 100644 --- a/hiro/windows/menu-bar.hpp +++ b/hiro/windows/menu-bar.hpp @@ -12,6 +12,7 @@ struct pMenuBar : pObject { auto setVisible(bool visible) -> void override; auto _parent() -> maybe; + auto _rebuild() -> void; auto _update() -> void; HMENU hmenu = 0; diff --git a/hiro/windows/monitor.cpp b/hiro/windows/monitor.cpp index baca8f085c..40975a8f8c 100644 --- a/hiro/windows/monitor.cpp +++ b/hiro/windows/monitor.cpp @@ -5,10 +5,10 @@ namespace hiro { struct MonitorInfo { - uint monitor = 0; - uint primary = 0; + u32 monitor = 0; + u32 primary = 0; Geometry geometry; - uint index = 0; + u32 index = 0; }; static auto CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL { @@ -26,32 +26,32 @@ static auto CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT l return true; } -auto pMonitor::count() -> uint { +auto pMonitor::count() -> u32 { return GetSystemMetrics(SM_CMONITORS); } auto pMonitor::dpi(uint monitor) -> Position { HDC hdc = GetDC(0); - auto dpiX = (float)GetDeviceCaps(hdc, LOGPIXELSX); - auto dpiY = (float)GetDeviceCaps(hdc, LOGPIXELSY); + auto dpiX = (f32)GetDeviceCaps(hdc, LOGPIXELSX); + auto dpiY = (f32)GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(0, hdc); return {dpiX, dpiY}; } -auto pMonitor::geometry(uint monitor) -> Geometry { +auto pMonitor::geometry(u32 monitor) -> Geometry { MonitorInfo info; info.monitor = monitor; EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, (LPARAM)&info); return info.geometry; } -auto pMonitor::primary() -> uint { +auto pMonitor::primary() -> u32 { MonitorInfo info; EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, (LPARAM)&info); return info.primary; } -auto pMonitor::workspace(uint monitor) -> Geometry { +auto pMonitor::workspace(u32 monitor) -> Geometry { return pDesktop::workspace(); } diff --git a/hiro/windows/monitor.hpp b/hiro/windows/monitor.hpp index 1effa3dad3..3e0ef670bb 100644 --- a/hiro/windows/monitor.hpp +++ b/hiro/windows/monitor.hpp @@ -3,11 +3,11 @@ namespace hiro { struct pMonitor { - static auto count() -> uint; - static auto dpi(uint monitor) -> Position; - static auto geometry(uint monitor) -> Geometry; - static auto primary() -> uint; - static auto workspace(uint monitor) -> Geometry; + static auto count() -> u32; + static auto dpi(u32 monitor) -> Position; + static auto geometry(u32 monitor) -> Geometry; + static auto primary() -> u32; + static auto workspace(u32 monitor) -> Geometry; }; } diff --git a/hiro/windows/popup-menu.cpp b/hiro/windows/popup-menu.cpp index 001fbfb7a7..909d81b63b 100644 --- a/hiro/windows/popup-menu.cpp +++ b/hiro/windows/popup-menu.cpp @@ -31,12 +31,12 @@ auto pPopupMenu::setVisible(bool visible) -> void { mi.dwStyle = MNS_NOTIFYBYPOS; //| MNS_MODELESS; SetMenuInfo(hmenu, &mi); - unsigned position = 0; + u32 position = 0; for(auto& action : state().actions) { if(!action->self()) continue; action->self()->position = position; - unsigned enabled = action->enabled() ? 0 : MF_GRAYED; + u32 enabled = action->enabled() ? 0 : MF_GRAYED; MENUITEMINFO mii{sizeof(MENUITEMINFO)}; mii.fMask = MIIM_DATA; diff --git a/hiro/windows/settings.hpp b/hiro/windows/settings.hpp index c86af68a29..418f68ca1b 100644 --- a/hiro/windows/settings.hpp +++ b/hiro/windows/settings.hpp @@ -11,10 +11,10 @@ struct Settings { //pWindow::setVisible() attempts to compute the actual window bounds to correct Window::frameMargin() //note: different window styles have different extended frame bounds struct ExtendedFrameBounds { - uint x = 0; - uint y = 0; - uint width = 0; - uint height = 0; + u32 x = 0; + u32 y = 0; + u32 width = 0; + u32 height = 0; }; //these are the default values for Windows 10 ... they will be updated later if they are incorrect diff --git a/hiro/windows/timer.cpp b/hiro/windows/timer.cpp index 572f790818..d724b48872 100644 --- a/hiro/windows/timer.cpp +++ b/hiro/windows/timer.cpp @@ -36,7 +36,7 @@ auto pTimer::setEnabled(bool enabled) -> void { } } -auto pTimer::setInterval(uint interval) -> void { +auto pTimer::setInterval(u32 interval) -> void { //destroy and recreate timer if interval changed setEnabled(self().enabled(true)); } diff --git a/hiro/windows/timer.hpp b/hiro/windows/timer.hpp index bff963444c..9cd14a6ce7 100644 --- a/hiro/windows/timer.hpp +++ b/hiro/windows/timer.hpp @@ -6,7 +6,7 @@ struct pTimer : pObject { Declare(Timer, Object) auto setEnabled(bool enabled) -> void override; - auto setInterval(uint interval) -> void; + auto setInterval(u32 interval) -> void; UINT_PTR htimer = 0; }; diff --git a/hiro/windows/tool-tip.cpp b/hiro/windows/tool-tip.cpp index b200e001ad..d93177ede1 100644 --- a/hiro/windows/tool-tip.cpp +++ b/hiro/windows/tool-tip.cpp @@ -35,7 +35,7 @@ pToolTip::~pToolTip() { auto pToolTip::drawLayered() -> void { auto hdcOutput = GetDC(nullptr); - uint32_t* below = nullptr; + u32* below = nullptr; auto hdcBelow = CreateCompatibleDC(hdcOutput); auto hbmBelow = CreateBitmap(hdcBelow, size.cx, size.cy, below); SelectObject(hdcBelow, hbmBelow); @@ -43,12 +43,12 @@ auto pToolTip::drawLayered() -> void { rc.left = 0, rc.top = 0, rc.right = size.cx, rc.bottom = size.cy; DrawThemeBackground(htheme, hdcBelow, TTP_STANDARD, TTSS_NORMAL, &rc, nullptr); - uint32_t* above = nullptr; + u32* above = nullptr; auto hdcAbove = CreateCompatibleDC(hdcOutput); auto hbmAbove = CreateBitmap(hdcAbove, size.cx, size.cy, above); SelectObject(hdcAbove, hbmAbove); - memory::copy(above, below, size.cx * size.cy); + memory::copy(above, below, size.cx * size.cy); auto hfont = pFont::create(Font()); SelectObject(hdcAbove, hfont); @@ -59,7 +59,7 @@ auto pToolTip::drawLayered() -> void { DrawText(hdcAbove, drawText, -1, &rc, DT_LEFT | DT_TOP); DeleteObject(hfont); - for(uint n : range(size.cx * size.cy)) { + for(u32 n : range(size.cx * size.cy)) { below[n] = (below[n] & 0xff000000) | (above[n] & 0x00ffffff); } diff --git a/hiro/windows/tool-tip.hpp b/hiro/windows/tool-tip.hpp index 70dff56b09..93f69026bb 100644 --- a/hiro/windows/tool-tip.hpp +++ b/hiro/windows/tool-tip.hpp @@ -1,7 +1,7 @@ namespace hiro { struct pToolTip { - enum : uint { Delay = 1000, Timeout = 10000 }; + enum : u32 { Delay = 1000, Timeout = 10000 }; pToolTip(const string& text); ~pToolTip(); diff --git a/hiro/windows/utility.cpp b/hiro/windows/utility.cpp index bde5dcd1c9..1137eb4cfa 100644 --- a/hiro/windows/utility.cpp +++ b/hiro/windows/utility.cpp @@ -1,38 +1,38 @@ namespace hiro { -static const uint Windows2000 = 0x0500; -static const uint WindowsXP = 0x0501; -static const uint WindowsVista = 0x0600; -static const uint Windows7 = 0x0601; +static constexpr u32 Windows2000 = 0x0500; +static constexpr u32 WindowsXP = 0x0501; +static constexpr u32 WindowsVista = 0x0600; +static constexpr u32 Windows7 = 0x0601; -static auto Button_CustomDraw(HWND, PAINTSTRUCT&, bool, bool, bool, unsigned, const Font&, const image&, Orientation, const string&) -> void; +static auto Button_CustomDraw(HWND, PAINTSTRUCT&, bool, bool, bool, u32, const Font&, const image&, Orientation, const string&) -> void; -static auto OsVersion() -> uint { +static auto OsVersion() -> u32 { OSVERSIONINFO versionInfo{0}; versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&versionInfo); return (versionInfo.dwMajorVersion << 8) + (versionInfo.dwMajorVersion << 0); } -static auto CreateBitmap(HDC hdc, uint width, uint height, uint32_t*& data) -> HBITMAP { +static auto CreateBitmap(HDC hdc, u32 width, u32 height, u32*& data) -> HBITMAP { BITMAPINFO info{}; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biWidth = width; - info.bmiHeader.biHeight = -(int)height; //bitmaps are stored upside down unless we negate height + info.bmiHeader.biHeight = -(s32)height; //bitmaps are stored upside down unless we negate height info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = 32; info.bmiHeader.biCompression = BI_RGB; - info.bmiHeader.biSizeImage = width * height * sizeof(uint32_t); + info.bmiHeader.biSizeImage = width * height * sizeof(u32); void* bits = nullptr; auto bitmap = CreateDIBSection(hdc, &info, DIB_RGB_COLORS, &bits, nullptr, 0); - data = (uint32_t*)bits; + data = (u32*)bits; return bitmap; } static auto CreateBitmap(image icon) -> HBITMAP { icon.alphaMultiply(); //Windows AlphaBlend() requires premultiplied image data icon.transform(); - uint32_t* data = nullptr; + u32* data = nullptr; auto hdc = GetDC(nullptr); auto bitmap = CreateBitmap(hdc, icon.width(), icon.height(), data); memory::copy(data, icon.data(), icon.size()); @@ -78,13 +78,13 @@ static auto EnumVisibleChildWindows(HWND hwnd) -> vector { return children; } -static auto GetWindowZOrder(HWND hwnd) -> unsigned { - uint z = 0; +static auto GetWindowZOrder(HWND hwnd) -> u32 { + u32 z = 0; for(HWND next = hwnd; next != nullptr; next = GetWindow(next, GW_HWNDPREV)) z++; return z; } -static auto ImageList_Append(HIMAGELIST imageList, image icon, unsigned scale) -> void { +static auto ImageList_Append(HIMAGELIST imageList, image icon, u32 scale) -> void { if(icon) { icon.scale(scale, scale); } else { @@ -104,7 +104,7 @@ static auto PostMessageOnce(HWND hwnd, UINT id, WPARAM wparam, LPARAM lparam) -> } } -static auto ScrollEvent(HWND hwnd, WPARAM wparam) -> unsigned { +static auto ScrollEvent(HWND hwnd, WPARAM wparam) -> u32 { SCROLLINFO info; memset(&info, 0, sizeof(SCROLLINFO)); info.cbSize = sizeof(SCROLLINFO); diff --git a/hiro/windows/widget/button.cpp b/hiro/windows/widget/button.cpp index 388117f04b..2e1dde0bdd 100644 --- a/hiro/windows/widget/button.cpp +++ b/hiro/windows/widget/button.cpp @@ -16,7 +16,7 @@ auto pButton::destruct() -> void { } auto pButton::minimumSize() const -> Size { - Size icon = {(int)state().icon.width(), (int)state().icon.height()}; + Size icon = {(s32)state().icon.width(), (s32)state().icon.height()}; Size text = state().text ? pFont::size(self().font(true), state().text) : Size{}; Size size; if(state().orientation == Orientation::Horizontal) { @@ -101,11 +101,11 @@ auto pButton::_setState() -> void { } //this function is designed to be used with Button, CheckButton, and RadioButton -auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, bool enabled, unsigned state, const Font& font, const image& icon, Orientation orientation, const string& text) -> void { +auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, bool enabled, u32 state, const Font& font, const image& icon, Orientation orientation, const string& text) -> void { RECT rc; GetClientRect(hwnd, &rc); Geometry geometry{rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top}, iconGeometry, textGeometry; - if(icon) iconGeometry.setSize({(int)icon.width(), (int)icon.height()}); + if(icon) iconGeometry.setSize({(s32)icon.width(), (s32)icon.height()}); if(text) textGeometry.setSize(pFont::size(font, text)); Position position; @@ -128,7 +128,7 @@ auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, if(auto theme = OpenThemeData(hwnd, L"BUTTON")) { DrawThemeParentBackground(hwnd, ps.hdc, &rc); - unsigned flags = 0; + u32 flags = 0; if(state & BST_PUSHED || checked) flags = PBS_PRESSED; else if(state & BST_HOT) flags = PBS_HOT; else if(bordered) flags = enabled ? PBS_NORMAL : PBS_DISABLED; @@ -137,12 +137,12 @@ auto Button_CustomDraw(HWND hwnd, PAINTSTRUCT& ps, bool bordered, bool checked, } else { //Windows Classic FillRect(ps.hdc, &rc, GetSysColorBrush(COLOR_3DFACE)); - unsigned flags = (state & BST_PUSHED || checked) ? DFCS_PUSHED : 0; + u32 flags = (state & BST_PUSHED || checked) ? DFCS_PUSHED : 0; if(bordered || flags) DrawFrameControl(ps.hdc, &rc, DFC_BUTTON, DFCS_BUTTONPUSH | flags | (enabled ? 0 : DFCS_INACTIVE)); } if(GetFocus() == hwnd) { - signed offset = state ? 4 : 1; + s32 offset = state ? 4 : 1; RECT rcFocus{rc.left + offset, rc.top + offset, rc.right - offset, rc.bottom - offset}; if(!(state & BST_PUSHED) && !(state & BST_HOT)) DrawFocusRect(ps.hdc, &rcFocus); } diff --git a/hiro/windows/widget/canvas.cpp b/hiro/windows/widget/canvas.cpp index 41585a6dd8..2584816d41 100644 --- a/hiro/windows/widget/canvas.cpp +++ b/hiro/windows/widget/canvas.cpp @@ -13,7 +13,7 @@ auto pCanvas::destruct() -> void { } auto pCanvas::minimumSize() const -> Size { - if(auto& icon = state().icon) return {(int)icon.width(), (int)icon.height()}; + if(auto& icon = state().icon) return {(s32)icon.width(), (s32)icon.height()}; return {0, 0}; } @@ -57,7 +57,7 @@ auto pCanvas::doMouseLeave() -> void { return self().doMouseLeave(); } -auto pCanvas::doMouseMove(int x, int y) -> void { +auto pCanvas::doMouseMove(s32 x, s32 y) -> void { return self().doMouseMove({x, y}); } @@ -93,9 +93,9 @@ auto pCanvas::_paint() -> void { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); - int sx = 0, sy = 0, dx = 0, dy = 0; - int width = this->width; - int height = this->height; + s32 sx = 0, sy = 0, dx = 0, dy = 0; + s32 width = this->width; + s32 height = this->height; auto geometry = self().geometry(); auto alignment = state().alignment ? state().alignment : Alignment{0.5, 0.5}; @@ -125,14 +125,14 @@ auto pCanvas::_paint() -> void { bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; //GDI stores bitmaps upside now; negative height flips bitmap - bmi.bmiHeader.biSizeImage = width * height * sizeof(uint32_t); + bmi.bmiHeader.biSizeImage = width * height * sizeof(u32); void* bits = nullptr; HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0); if(bits) { - for(uint y : range(height)) { - auto source = (const uint8_t*)pixels.data() + (sy + y) * this->width * sizeof(uint32_t) + sx * sizeof(uint32_t); - auto target = (uint8_t*)bits + y * width * sizeof(uint32_t); - for(uint x : range(width)) { + for(u32 y : range(height)) { + auto source = (const u8*)pixels.data() + (sy + y) * this->width * sizeof(u32) + sx * sizeof(u32); + auto target = (u8*)bits + y * width * sizeof(u32); + for(u32 x : range(width)) { target[0] = (source[0] * source[3]) / 255; target[1] = (source[1] * source[3]) / 255; target[2] = (source[2] * source[3]) / 255; @@ -170,7 +170,7 @@ auto pCanvas::_rasterize() -> void { pixels.resize(width * height); if(auto& icon = state().icon) { - memory::copy(pixels.data(), icon.data(), width * height); + memory::copy(pixels.data(), icon.data(), width * height); } else if(auto& gradient = state().gradient) { auto& colors = gradient.state.colors; image fill; @@ -178,7 +178,7 @@ auto pCanvas::_rasterize() -> void { fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value()); memory::copy(pixels.data(), fill.data(), fill.size()); } else { - uint32_t color = state().color.value(); + u32 color = state().color.value(); for(auto& pixel : pixels) pixel = color; } } diff --git a/hiro/windows/widget/canvas.hpp b/hiro/windows/widget/canvas.hpp index 76931bf8c6..e3f6ad8fd7 100644 --- a/hiro/windows/widget/canvas.hpp +++ b/hiro/windows/widget/canvas.hpp @@ -16,16 +16,16 @@ struct pCanvas : pWidget { auto update() -> void; auto doMouseLeave() -> void override; - auto doMouseMove(int x, int y) -> void override; + auto doMouseMove(s32 x, s32 y) -> void override; auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe override; auto _paint() -> void; auto _rasterize() -> void; auto _redraw() -> void; - vector pixels; - signed width = 0; - signed height = 0; + vector pixels; + s32 width = 0; + s32 height = 0; }; } diff --git a/hiro/windows/widget/check-button.cpp b/hiro/windows/widget/check-button.cpp index 3fd1dc1cf5..01e5b9b255 100644 --- a/hiro/windows/widget/check-button.cpp +++ b/hiro/windows/widget/check-button.cpp @@ -16,7 +16,7 @@ auto pCheckButton::destruct() -> void { } auto pCheckButton::minimumSize() const -> Size { - Size icon = {(int)state().icon.width(), (int)state().icon.height()}; + Size icon = {(s32)state().icon.width(), (s32)state().icon.height()}; Size text = state().text ? pFont::size(self().font(true), state().text) : Size{}; Size size; if(state().orientation == Orientation::Horizontal) { diff --git a/hiro/windows/widget/combo-button.cpp b/hiro/windows/widget/combo-button.cpp index f219e977f0..c5a08b322c 100644 --- a/hiro/windows/widget/combo-button.cpp +++ b/hiro/windows/widget/combo-button.cpp @@ -26,7 +26,7 @@ auto pComboButton::append(sComboButtonItem item) -> void { } auto pComboButton::minimumSize() const -> Size { - signed width = 0; + s32 width = 0; for(auto& item : state().items) { width = max(width, pFont::size(hfont, item->state.text).width()); } @@ -58,7 +58,7 @@ auto pComboButton::setGeometry(Geometry geometry) -> void { } auto pComboButton::onChange() -> void { - signed offset = SendMessage(hwnd, CB_GETCURSEL, 0, 0); + s32 offset = SendMessage(hwnd, CB_GETCURSEL, 0, 0); if(offset == CB_ERR) return; for(auto& item : state().items) item->state.selected = false; if(auto item = self().item(offset)) item->setSelected(); diff --git a/hiro/windows/widget/hex-edit.cpp b/hiro/windows/widget/hex-edit.cpp index 60d4fc88ce..8fd80e520c 100644 --- a/hiro/windows/widget/hex-edit.cpp +++ b/hiro/windows/widget/hex-edit.cpp @@ -27,7 +27,7 @@ auto pHexEdit::destruct() -> void { DestroyWindow(hwnd); } -auto pHexEdit::setAddress(unsigned address) -> void { +auto pHexEdit::setAddress(u32 address) -> void { SetScrollPos(scrollBar, SB_CTL, address / state().columns, true); update(); } @@ -37,20 +37,20 @@ auto pHexEdit::setBackgroundColor(Color color) -> void { backgroundBrush = CreateSolidBrush(color ? CreateRGB(color) : GetSysColor(COLOR_WINDOW)); } -auto pHexEdit::setColumns(unsigned columns) -> void { +auto pHexEdit::setColumns(u32 columns) -> void { update(); } auto pHexEdit::setForegroundColor(Color color) -> void { } -auto pHexEdit::setLength(unsigned length) -> void { +auto pHexEdit::setLength(u32 length) -> void { SetScrollRange(scrollBar, SB_CTL, 0, rowsScrollable(), true); EnableWindow(scrollBar, rowsScrollable() > 0); update(); } -auto pHexEdit::setRows(unsigned rows) -> void { +auto pHexEdit::setRows(u32 rows) -> void { update(); } @@ -60,10 +60,10 @@ auto pHexEdit::update() -> void { return; } - unsigned cursorPosition = Edit_GetSel(hwnd); + u32 cursorPosition = Edit_GetSel(hwnd); string output; - unsigned address = state().address; + u32 address = state().address; for(auto row : range(state().rows)) { output.append(hex(address, 8L)); output.append(" "); @@ -72,7 +72,7 @@ auto pHexEdit::update() -> void { string ansidata = " "; for(auto column : range(state().columns)) { if(address < state().length) { - uint8_t data = self().doRead(address++); + u8 data = self().doRead(address++); hexdata.append(hex(data, 2L)); hexdata.append(" "); ansidata.append(data >= 0x20 && data <= 0x7e ? (char)data : '.'); @@ -92,22 +92,22 @@ auto pHexEdit::update() -> void { Edit_SetSel(hwnd, LOWORD(cursorPosition), HIWORD(cursorPosition)); } -auto pHexEdit::keyPress(unsigned scancode) -> bool { +auto pHexEdit::keyPress(u32 scancode) -> bool { if(!state().onRead) return false; - signed position = LOWORD(Edit_GetSel(hwnd)); - signed lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 2; - signed cursorY = position / lineWidth; - signed cursorX = position % lineWidth; + s32 position = LOWORD(Edit_GetSel(hwnd)); + s32 lineWidth = 10 + (state().columns * 3) + 1 + state().columns + 2; + s32 cursorY = position / lineWidth; + s32 cursorX = position % lineWidth; if(scancode == VK_HOME) { - signed offset = cursorY * lineWidth + 10; + s32 offset = cursorY * lineWidth + 10; Edit_SetSel(hwnd, offset, offset); return true; } if(scancode == VK_END) { - signed offset = cursorY * lineWidth + 57; + s32 offset = cursorY * lineWidth + 57; Edit_SetSel(hwnd, offset, offset); return true; } @@ -150,10 +150,10 @@ auto pHexEdit::keyPress(unsigned scancode) -> bool { cursorX /= 3; if(cursorX < state().columns) { //not in ANSI region - unsigned address = state().address + (cursorY * state().columns + cursorX); + u32 address = state().address + (cursorY * state().columns + cursorX); if(address >= state().length) return false; //do not edit past end of data - uint8_t data = self().doRead(address); + u8 data = self().doRead(address); //write modified value if(cursorNibble == 1) { @@ -177,19 +177,19 @@ auto pHexEdit::keyPress(unsigned scancode) -> bool { return true; } -auto pHexEdit::rows() -> int { +auto pHexEdit::rows() -> s32 { return (max(1u, state().length) + state().columns - 1) / state().columns; } -auto pHexEdit::rowsScrollable() -> int { +auto pHexEdit::rowsScrollable() -> s32 { return max(0u, rows() - state().rows); } -auto pHexEdit::scrollPosition() -> int { +auto pHexEdit::scrollPosition() -> s32 { return state().address / state().columns; } -auto pHexEdit::scrollTo(signed position) -> void { +auto pHexEdit::scrollTo(s32 position) -> void { if(position > rowsScrollable()) position = rowsScrollable(); if(position < 0) position = 0; if(position == scrollPosition()) return; @@ -202,7 +202,7 @@ auto pHexEdit::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> } if(msg == WM_MOUSEWHEEL) { - int offset = -((int16_t)HIWORD(wparam) / WHEEL_DELTA); + s32 offset = -((s16)HIWORD(wparam) / WHEEL_DELTA); scrollTo(scrollPosition() + offset); return true; } diff --git a/hiro/windows/widget/hex-edit.hpp b/hiro/windows/widget/hex-edit.hpp index e6ac15aa29..2818972dc3 100644 --- a/hiro/windows/widget/hex-edit.hpp +++ b/hiro/windows/widget/hex-edit.hpp @@ -5,19 +5,19 @@ namespace hiro { struct pHexEdit : pWidget { Declare(HexEdit, Widget) - auto setAddress(unsigned address) -> void; + auto setAddress(u32 address) -> void; auto setBackgroundColor(Color color) -> void; - auto setColumns(unsigned columns) -> void; + auto setColumns(u32 columns) -> void; auto setForegroundColor(Color color) -> void; - auto setLength(unsigned length) -> void; - auto setRows(unsigned rows) -> void; + auto setLength(u32 length) -> void; + auto setRows(u32 rows) -> void; auto update() -> void; - auto keyPress(unsigned key) -> bool; - auto rows() -> signed; - auto rowsScrollable() -> signed; - auto scrollPosition() -> signed; - auto scrollTo(signed position) -> void; + auto keyPress(u32 key) -> bool; + auto rows() -> s32; + auto rowsScrollable() -> s32; + auto scrollPosition() -> s32; + auto scrollTo(s32 position) -> void; auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe override; HWND scrollBar = nullptr; diff --git a/hiro/windows/widget/horizontal-scroll-bar.cpp b/hiro/windows/widget/horizontal-scroll-bar.cpp index 570df8a5ab..d727865049 100644 --- a/hiro/windows/widget/horizontal-scroll-bar.cpp +++ b/hiro/windows/widget/horizontal-scroll-bar.cpp @@ -20,17 +20,17 @@ auto pHorizontalScrollBar::minimumSize() const -> Size { return {0, 18_sy}; } -auto pHorizontalScrollBar::setLength(unsigned length) -> void { +auto pHorizontalScrollBar::setLength(u32 length) -> void { length += (length == 0); SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); } -auto pHorizontalScrollBar::setPosition(unsigned position) -> void { +auto pHorizontalScrollBar::setPosition(u32 position) -> void { SetScrollPos(hwnd, SB_CTL, position, TRUE); } auto pHorizontalScrollBar::onChange(WPARAM wparam) -> void { - unsigned position = ScrollEvent(hwnd, wparam); + u32 position = ScrollEvent(hwnd, wparam); if(position == state().position) return; state().position = position; self().doChange(); diff --git a/hiro/windows/widget/horizontal-scroll-bar.hpp b/hiro/windows/widget/horizontal-scroll-bar.hpp index 180249f839..7eaef44c1f 100644 --- a/hiro/windows/widget/horizontal-scroll-bar.hpp +++ b/hiro/windows/widget/horizontal-scroll-bar.hpp @@ -6,8 +6,8 @@ struct pHorizontalScrollBar : pWidget { Declare(HorizontalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto onChange(WPARAM wparam) -> void; }; diff --git a/hiro/windows/widget/horizontal-slider.cpp b/hiro/windows/widget/horizontal-slider.cpp index 63cb61ad00..d8c84386d0 100644 --- a/hiro/windows/widget/horizontal-slider.cpp +++ b/hiro/windows/widget/horizontal-slider.cpp @@ -24,18 +24,18 @@ auto pHorizontalSlider::minimumSize() const -> Size { return {0, 25_sy}; } -auto pHorizontalSlider::setLength(unsigned length) -> void { +auto pHorizontalSlider::setLength(u32 length) -> void { length += (length == 0); SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); } -auto pHorizontalSlider::setPosition(unsigned position) -> void { +auto pHorizontalSlider::setPosition(u32 position) -> void { SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); } auto pHorizontalSlider::onChange() -> void { - unsigned position = SendMessage(hwnd, TBM_GETPOS, 0, 0); + u32 position = SendMessage(hwnd, TBM_GETPOS, 0, 0); if(position == state().position) return; state().position = position; self().doChange(); diff --git a/hiro/windows/widget/horizontal-slider.hpp b/hiro/windows/widget/horizontal-slider.hpp index 6a81777b69..477a819283 100644 --- a/hiro/windows/widget/horizontal-slider.hpp +++ b/hiro/windows/widget/horizontal-slider.hpp @@ -6,8 +6,8 @@ struct pHorizontalSlider : pWidget { Declare(HorizontalSlider, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto onChange() -> void; }; diff --git a/hiro/windows/widget/label.cpp b/hiro/windows/widget/label.cpp index 987162a00c..72a422cb56 100644 --- a/hiro/windows/widget/label.cpp +++ b/hiro/windows/widget/label.cpp @@ -69,15 +69,15 @@ auto pLabel::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> ma SetBkMode(hdcMemory, TRANSPARENT); SelectObject(hdcMemory, hfont); DrawText(hdcMemory, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); - uint height = rc.bottom; + u32 height = rc.bottom; GetClientRect(hwnd, &rc); rc.top = (rc.bottom - height) / 2; rc.bottom = rc.top + height; - uint horizontalAlignment = DT_CENTER; + u32 horizontalAlignment = DT_CENTER; if(state().alignment.horizontal() < 0.333) horizontalAlignment = DT_LEFT; if(state().alignment.horizontal() > 0.666) horizontalAlignment = DT_RIGHT; - uint verticalAlignment = DT_VCENTER; + u32 verticalAlignment = DT_VCENTER; if(state().alignment.vertical() < 0.333) verticalAlignment = DT_TOP; if(state().alignment.vertical() > 0.666) verticalAlignment = DT_BOTTOM; if(auto color = state().foregroundColor) { diff --git a/hiro/windows/widget/line-edit.cpp b/hiro/windows/widget/line-edit.cpp index 24abccba97..abd8d9aa87 100644 --- a/hiro/windows/widget/line-edit.cpp +++ b/hiro/windows/widget/line-edit.cpp @@ -60,7 +60,7 @@ auto pLineEdit::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> // auto pLineEdit::_text() -> string { - unsigned length = GetWindowTextLength(hwnd); + u32 length = GetWindowTextLength(hwnd); wchar_t text[length + 1]; GetWindowText(hwnd, text, length + 1); text[length] = 0; diff --git a/hiro/windows/widget/progress-bar.cpp b/hiro/windows/widget/progress-bar.cpp index 63272e68ce..e9b07ec89c 100644 --- a/hiro/windows/widget/progress-bar.cpp +++ b/hiro/windows/widget/progress-bar.cpp @@ -20,7 +20,7 @@ auto pProgressBar::minimumSize() const -> Size { return {0, 23}; } -auto pProgressBar::setPosition(unsigned position) -> void { +auto pProgressBar::setPosition(u32 position) -> void { SendMessage(hwnd, PBM_SETPOS, (WPARAM)position, 0); } diff --git a/hiro/windows/widget/progress-bar.hpp b/hiro/windows/widget/progress-bar.hpp index fc462a939b..32cdf3a0d9 100644 --- a/hiro/windows/widget/progress-bar.hpp +++ b/hiro/windows/widget/progress-bar.hpp @@ -6,7 +6,7 @@ struct pProgressBar : pWidget { Declare(ProgressBar, Widget) auto minimumSize() const -> Size override; - auto setPosition(unsigned position) -> void; + auto setPosition(u32 position) -> void; }; } diff --git a/hiro/windows/widget/radio-button.cpp b/hiro/windows/widget/radio-button.cpp index 4d0bc41e12..c9e80f42b6 100644 --- a/hiro/windows/widget/radio-button.cpp +++ b/hiro/windows/widget/radio-button.cpp @@ -16,7 +16,7 @@ auto pRadioButton::destruct() -> void { } auto pRadioButton::minimumSize() const -> Size { - Size icon = {(int)state().icon.width(), (int)state().icon.height()}; + Size icon = {(s32)state().icon.width(), (s32)state().icon.height()}; Size text = state().text ? pFont::size(self().font(true), state().text) : Size{}; Size size; if(state().orientation == Orientation::Horizontal) { diff --git a/hiro/windows/widget/tab-frame.cpp b/hiro/windows/widget/tab-frame.cpp index d15449e538..9530c1a310 100644 --- a/hiro/windows/widget/tab-frame.cpp +++ b/hiro/windows/widget/tab-frame.cpp @@ -86,7 +86,7 @@ auto pTabFrame::setVisible(bool visible) -> void { // auto pTabFrame::_buildImageList() -> void { - unsigned size = pFont::size(hfont, " ").height(); + u32 size = pFont::size(hfont, " ").height(); if(imageList) { ImageList_Destroy(imageList); imageList = nullptr; } imageList = ImageList_Create(size, size, ILC_COLOR32, 1, 0); @@ -110,14 +110,14 @@ auto pTabFrame::_synchronizeSizable() -> void { //without this call, widgets from the previous tab will remain visible //alongside widgets from the newly selected tab for about one frame ... Application::processEvents(); - uint selected = TabCtrl_GetCurSel(hwnd); + u32 selected = TabCtrl_GetCurSel(hwnd); if(auto item = self().item(selected)) { if(auto& sizable = item->state.sizable) sizable->setVisible(true); } } auto pTabFrame::onChange() -> void { - uint selected = TabCtrl_GetCurSel(hwnd); + u32 selected = TabCtrl_GetCurSel(hwnd); for(auto& item : state().items) item->state.selected = false; if(auto item = self().item(selected)) item->state.selected = true; _synchronizeSizable(); diff --git a/hiro/windows/widget/table-view-column.cpp b/hiro/windows/widget/table-view-column.cpp index e984c6fa90..d4ad8b0c59 100644 --- a/hiro/windows/widget/table-view-column.cpp +++ b/hiro/windows/widget/table-view-column.cpp @@ -43,7 +43,7 @@ auto pTableViewColumn::setExpandable(bool expandable) -> void { auto pTableViewColumn::setForegroundColor(Color color) -> void { } -auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void { +auto pTableViewColumn::setHorizontalAlignment(f64 alignment) -> void { _setState(); } @@ -63,10 +63,10 @@ auto pTableViewColumn::setText(const string& text) -> void { _setState(); } -auto pTableViewColumn::setVerticalAlignment(double alignment) -> void { +auto pTableViewColumn::setVerticalAlignment(f64 alignment) -> void { } -auto pTableViewColumn::setWidth(signed width) -> void { +auto pTableViewColumn::setWidth(s32 width) -> void { _setState(); } diff --git a/hiro/windows/widget/table-view-column.hpp b/hiro/windows/widget/table-view-column.hpp index 9d13d0d35b..7fa168d907 100644 --- a/hiro/windows/widget/table-view-column.hpp +++ b/hiro/windows/widget/table-view-column.hpp @@ -11,13 +11,13 @@ struct pTableViewColumn : pObject { auto setEditable(bool editable) -> void; auto setExpandable(bool expandable) -> void; auto setForegroundColor(Color color) -> void; - auto setHorizontalAlignment(double alignment) -> void; + auto setHorizontalAlignment(f64 alignment) -> void; auto setIcon(const image& icon) -> void; auto setResizable(bool resizable) -> void; auto setSorting(Sort sorting) -> void; auto setText(const string& text) -> void; - auto setVerticalAlignment(double alignment) -> void; - auto setWidth(signed width) -> void; + auto setVerticalAlignment(f64 alignment) -> void; + auto setWidth(s32 width) -> void; auto _parent() -> maybe; auto _setState() -> void; diff --git a/hiro/windows/widget/table-view.cpp b/hiro/windows/widget/table-view.cpp index bd5dcdc2c7..f54fcbfcbe 100644 --- a/hiro/windows/widget/table-view.cpp +++ b/hiro/windows/widget/table-view.cpp @@ -40,17 +40,17 @@ auto pTableView::remove(sTableViewItem item) -> void { auto pTableView::resizeColumns() -> void { auto lock = acquire(); - vector widths; - signed minimumWidth = 0; - signed expandable = 0; + vector widths; + s32 minimumWidth = 0; + s32 expandable = 0; for(auto column : range(self().columnCount())) { - signed width = _width(column); + s32 width = _width(column); widths.append(width); minimumWidth += width; if(state().columns[column]->expandable()) expandable++; } - signed maximumWidth = self().geometry().width() - 4; + s32 maximumWidth = self().geometry().width() - 4; SCROLLBARINFO sbInfo{sizeof(SCROLLBARINFO)}; if(GetScrollBarInfo(hwnd, OBJID_VSCROLL, &sbInfo)) { if(!(sbInfo.rgstate[0] & STATE_SYSTEM_INVISIBLE)) { @@ -58,14 +58,14 @@ auto pTableView::resizeColumns() -> void { } } - signed expandWidth = 0; + s32 expandWidth = 0; if(expandable && maximumWidth > minimumWidth) { expandWidth = (maximumWidth - minimumWidth) / expandable; } for(auto column : range(self().columnCount())) { if(auto self = state().columns[column]->self()) { - signed width = widths[column]; + s32 width = widths[column]; if(self->state().expandable) width += expandWidth; self->_width = width; self->_setState(); @@ -111,9 +111,9 @@ auto pTableView::onActivate(LPARAM lparam) -> void { ScreenToClient(nmlistview->hdr.hwndFrom, &hitTest.pt); ListView_SubItemHitTest(nmlistview->hdr.hwndFrom, &hitTest); if(hitTest.flags & LVHT_ONITEM) { - int row = hitTest.iItem; + s32 row = hitTest.iItem; if(row >= 0 && row < state().items.size()) { - int column = hitTest.iSubItem; + s32 column = hitTest.iSubItem; if(column >= 0 && column < state().columns.size()) { auto item = state().items[row]; activateCell = item->cell(column); @@ -162,13 +162,13 @@ auto pTableView::onCustomDraw(LPARAM lparam) -> LRESULT { case CDDS_ITEMPOSTPAINT: { HDC hdc = lvcd->nmcd.hdc; HDC hdcSource = CreateCompatibleDC(hdc); - unsigned row = lvcd->nmcd.dwItemSpec; + u32 row = lvcd->nmcd.dwItemSpec; for(auto column : range(self().columnCount())) { RECT rc, rcLabel; ListView_GetSubItemRect(hwnd, row, column, LVIR_BOUNDS, &rc); ListView_GetSubItemRect(hwnd, row, column, LVIR_LABEL, &rcLabel); rc.right = rcLabel.right; //bounds of column 0 returns width of entire item - signed iconSize = rc.bottom - rc.top - 1; + s32 iconSize = rc.bottom - rc.top - 1; bool selected = state().items(row)->state.selected; if(auto cell = self().item(row)->cell(column)) { @@ -183,10 +183,10 @@ auto pTableView::onCustomDraw(LPARAM lparam) -> LRESULT { if(cell->state.checkable) { if(auto htheme = OpenThemeData(hwnd, L"BUTTON")) { - unsigned state = cell->state.checked ? CBS_CHECKEDNORMAL : CBS_UNCHECKEDNORMAL; + u32 state = cell->state.checked ? CBS_CHECKEDNORMAL : CBS_UNCHECKEDNORMAL; SIZE size; GetThemePartSize(htheme, hdc, BP_CHECKBOX, state, nullptr, TS_TRUE, &size); - signed center = max(0, (rc.bottom - rc.top - size.cy) / 2); + s32 center = max(0, (rc.bottom - rc.top - size.cy) / 2); RECT rd{rc.left + center, rc.top + center, rc.left + center + size.cx, rc.top + center + size.cy}; DrawThemeBackground(htheme, hdc, BP_CHECKBOX, state, &rd, nullptr); CloseThemeData(htheme); @@ -323,7 +323,7 @@ auto pTableView::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) - // -auto pTableView::_backgroundColor(unsigned _row, unsigned _column) -> Color { +auto pTableView::_backgroundColor(u32 _row, u32 _column) -> Color { if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(auto color = cell->backgroundColor()) return color; @@ -338,8 +338,8 @@ auto pTableView::_backgroundColor(unsigned _row, unsigned _column) -> Color { return {255, 255, 255}; } -auto pTableView::_cellWidth(unsigned _row, unsigned _column) -> unsigned { - unsigned width = 6; +auto pTableView::_cellWidth(u32 _row, u32 _column) -> u32 { + u32 width = 6; if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(cell->state.checkable) { @@ -356,8 +356,8 @@ auto pTableView::_cellWidth(unsigned _row, unsigned _column) -> unsigned { return width; } -auto pTableView::_columnWidth(unsigned _column) -> unsigned { - unsigned width = 12; +auto pTableView::_columnWidth(u32 _column) -> u32 { + u32 width = 12; if(auto column = self().column(_column)) { if(auto& icon = column->state.icon) { width += 16 + 12; //yes; icon spacing in column headers is excessive @@ -372,7 +372,7 @@ auto pTableView::_columnWidth(unsigned _column) -> unsigned { return width; } -auto pTableView::_font(unsigned _row, unsigned _column) -> Font { +auto pTableView::_font(u32 _row, u32 _column) -> Font { if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(auto font = cell->font()) return font; @@ -386,7 +386,7 @@ auto pTableView::_font(unsigned _row, unsigned _column) -> Font { return {}; } -auto pTableView::_foregroundColor(unsigned _row, unsigned _column) -> Color { +auto pTableView::_foregroundColor(u32 _row, u32 _column) -> Color { if(auto item = self().item(_row)) { if(auto cell = item->cell(_column)) { if(auto color = cell->foregroundColor()) return color; @@ -430,9 +430,9 @@ auto pTableView::_setIcons() -> void { DeleteObject(bitmap); } -auto pTableView::_width(unsigned column) -> unsigned { +auto pTableView::_width(u32 column) -> u32 { if(auto width = self().column(column).width()) return width; - unsigned width = 1; + u32 width = 1; if(state().headered) width = max(width, _columnWidth(column)); for(auto row : range(state().items.size())) { width = max(width, _cellWidth(row, column)); diff --git a/hiro/windows/widget/table-view.hpp b/hiro/windows/widget/table-view.hpp index 56bf2de024..08c8a0089d 100644 --- a/hiro/windows/widget/table-view.hpp +++ b/hiro/windows/widget/table-view.hpp @@ -27,13 +27,13 @@ struct pTableView : pWidget { auto onToggle(LPARAM lparam) -> void; auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe override; - auto _backgroundColor(unsigned row, unsigned column) -> Color; - auto _cellWidth(unsigned row, unsigned column) -> unsigned; - auto _columnWidth(unsigned column) -> unsigned; - auto _font(unsigned row, unsigned column) -> Font; - auto _foregroundColor(unsigned row, unsigned column) -> Color; + auto _backgroundColor(u32 row, u32 column) -> Color; + auto _cellWidth(u32 row, u32 column) -> u32; + auto _columnWidth(u32 column) -> u32; + auto _font(u32 row, u32 column) -> Font; + auto _foregroundColor(u32 row, u32 column) -> Color; auto _setIcons() -> void; - auto _width(unsigned column) -> unsigned; + auto _width(u32 column) -> u32; TableViewCell activateCell; HIMAGELIST imageList = 0; diff --git a/hiro/windows/widget/text-edit.cpp b/hiro/windows/widget/text-edit.cpp index 8b50934589..1858ecb237 100644 --- a/hiro/windows/widget/text-edit.cpp +++ b/hiro/windows/widget/text-edit.cpp @@ -43,9 +43,9 @@ auto pTextEdit::setText(string text) -> void { } auto pTextEdit::setTextCursor(TextCursor cursor) -> void { - signed end = GetWindowTextLength(hwnd); - signed offset = max(0, min(end, cursor.offset())); - signed length = max(0, min(end, cursor.offset() + cursor.length())); + s32 end = GetWindowTextLength(hwnd); + s32 offset = max(0, min(end, cursor.offset())); + s32 length = max(0, min(end, cursor.offset() + cursor.length())); Edit_SetSel(hwnd, offset, length); Edit_ScrollCaret(hwnd); } @@ -57,7 +57,7 @@ auto pTextEdit::setWordWrap(bool wordWrap) -> void { } auto pTextEdit::text() const -> string { - unsigned length = GetWindowTextLength(hwnd); + u32 length = GetWindowTextLength(hwnd); wchar_t buffer[length + 1]; GetWindowText(hwnd, buffer, length + 1); buffer[length] = 0; diff --git a/hiro/windows/widget/vertical-scroll-bar.cpp b/hiro/windows/widget/vertical-scroll-bar.cpp index 2d9dcd90ab..d49a23bc78 100644 --- a/hiro/windows/widget/vertical-scroll-bar.cpp +++ b/hiro/windows/widget/vertical-scroll-bar.cpp @@ -20,17 +20,17 @@ auto pVerticalScrollBar::minimumSize() const -> Size { return {18_sx, 0}; } -auto pVerticalScrollBar::setLength(unsigned length) -> void { +auto pVerticalScrollBar::setLength(u32 length) -> void { length += (length == 0); SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE); } -auto pVerticalScrollBar::setPosition(unsigned position) -> void { +auto pVerticalScrollBar::setPosition(u32 position) -> void { SetScrollPos(hwnd, SB_CTL, position, TRUE); } auto pVerticalScrollBar::onChange(WPARAM wparam) -> void { - unsigned position = ScrollEvent(hwnd, wparam); + u32 position = ScrollEvent(hwnd, wparam); if(position == state().position) return; state().position = position; self().doChange(); diff --git a/hiro/windows/widget/vertical-scroll-bar.hpp b/hiro/windows/widget/vertical-scroll-bar.hpp index e849a914f8..ffaff6a461 100644 --- a/hiro/windows/widget/vertical-scroll-bar.hpp +++ b/hiro/windows/widget/vertical-scroll-bar.hpp @@ -6,8 +6,8 @@ struct pVerticalScrollBar : pWidget { Declare(VerticalScrollBar, Widget) auto minimumSize() const -> Size override; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto onChange(WPARAM wparam) -> void; }; diff --git a/hiro/windows/widget/vertical-slider.cpp b/hiro/windows/widget/vertical-slider.cpp index c1b02ff64e..21ceaad90f 100644 --- a/hiro/windows/widget/vertical-slider.cpp +++ b/hiro/windows/widget/vertical-slider.cpp @@ -24,18 +24,18 @@ auto pVerticalSlider::minimumSize() const -> Size { return {25_sx, 0}; } -auto pVerticalSlider::setLength(unsigned length) -> void { +auto pVerticalSlider::setLength(u32 length) -> void { length += (length == 0); SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1)); SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3)); } -auto pVerticalSlider::setPosition(unsigned position) -> void { +auto pVerticalSlider::setPosition(u32 position) -> void { SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position); } auto pVerticalSlider::onChange() -> void { - unsigned position = SendMessage(hwnd, TBM_GETPOS, 0, 0); + u32 position = SendMessage(hwnd, TBM_GETPOS, 0, 0); if(position == state().position) return; state().position = position; self().doChange(); diff --git a/hiro/windows/widget/vertical-slider.hpp b/hiro/windows/widget/vertical-slider.hpp index bfb4b9f0fe..fee2d0f749 100644 --- a/hiro/windows/widget/vertical-slider.hpp +++ b/hiro/windows/widget/vertical-slider.hpp @@ -6,8 +6,8 @@ struct pVerticalSlider : pWidget { Declare(VerticalSlider, Widget) auto minimumSize() const -> Size; - auto setLength(unsigned length) -> void; - auto setPosition(unsigned position) -> void; + auto setLength(u32 length) -> void; + auto setPosition(u32 position) -> void; auto onChange() -> void; }; diff --git a/hiro/windows/widget/viewport.cpp b/hiro/windows/widget/viewport.cpp index b6daef237a..a911ca16c0 100644 --- a/hiro/windows/widget/viewport.cpp +++ b/hiro/windows/widget/viewport.cpp @@ -31,7 +31,7 @@ auto pViewport::doMouseLeave() -> void { return self().doMouseLeave(); } -auto pViewport::doMouseMove(int x, int y) -> void { +auto pViewport::doMouseMove(s32 x, s32 y) -> void { return self().doMouseMove({x, y}); } diff --git a/hiro/windows/widget/viewport.hpp b/hiro/windows/widget/viewport.hpp index 40baf41be6..b2fd7fbe5e 100644 --- a/hiro/windows/widget/viewport.hpp +++ b/hiro/windows/widget/viewport.hpp @@ -10,7 +10,7 @@ struct pViewport : pWidget { auto setFocusable(bool focusable) -> void override; auto doMouseLeave() -> void override; - auto doMouseMove(int x, int y) -> void override; + auto doMouseMove(s32 x, s32 y) -> void override; auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe override; }; diff --git a/hiro/windows/widget/widget.cpp b/hiro/windows/widget/widget.cpp index f5b65c0be7..1f517d7b68 100644 --- a/hiro/windows/widget/widget.cpp +++ b/hiro/windows/widget/widget.cpp @@ -107,7 +107,7 @@ auto pWidget::doMouseHover() -> void { auto pWidget::doMouseLeave() -> void { } -auto pWidget::doMouseMove(int x, int y) -> void { +auto pWidget::doMouseMove(s32 x, s32 y) -> void { } auto pWidget::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> maybe { diff --git a/hiro/windows/widget/widget.hpp b/hiro/windows/widget/widget.hpp index d85ca90180..17f3b63d43 100644 --- a/hiro/windows/widget/widget.hpp +++ b/hiro/windows/widget/widget.hpp @@ -19,7 +19,7 @@ struct pWidget : pSizable { virtual auto doMouseHover() -> void; virtual auto doMouseLeave() -> void; - virtual auto doMouseMove(int x, int y) -> void; + virtual auto doMouseMove(s32 x, s32 y) -> void; virtual auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe; auto _parentHandle() -> HWND; diff --git a/hiro/windows/window.cpp b/hiro/windows/window.cpp index 7c6cdf6095..a7c1fd89a3 100644 --- a/hiro/windows/window.cpp +++ b/hiro/windows/window.cpp @@ -16,11 +16,11 @@ static auto CALLBACK Window_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA return Shared_windowProc(DefWindowProc, hwnd, msg, wparam, lparam); } -static const uint PopupStyle = WS_POPUP | WS_CLIPCHILDREN; -static const uint FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER | WS_CLIPCHILDREN; -static const uint ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN; +static constexpr u32 PopupStyle = WS_POPUP | WS_CLIPCHILDREN; +static constexpr u32 FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER | WS_CLIPCHILDREN; +static constexpr u32 ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN; -uint pWindow::minimumStatusHeight = 0; +u32 pWindow::minimumStatusHeight = 0; auto pWindow::initialize() -> void { pApplication::state().modalTimer.setInterval(1); @@ -67,7 +67,7 @@ auto pWindow::focused() const -> bool { auto pWindow::frameMargin() const -> Geometry { RECT rc{0, 0, 640, 480}; - uint style = state().fullScreen ? 0 : state().resizable ? ResizableStyle : FixedStyle; + u32 style = state().fullScreen ? 0 : state().resizable ? ResizableStyle : FixedStyle; bool menuVisible = state().menuBar && state().menuBar->visible(); AdjustWindowRect(&rc, style, menuVisible); auto& efb = state().fullScreen ? settings.efbPopup : !state().resizable ? settings.efbFixed : settings.efbResizable; @@ -83,7 +83,7 @@ auto pWindow::handle() const -> uintptr_t { return (uintptr_t)hwnd; } -auto pWindow::monitor() const -> uint { +auto pWindow::monitor() const -> u32 { //TODO return 0; } @@ -356,8 +356,8 @@ auto pWindow::_geometry() -> Geometry { return {x, y, width, height}; } -auto pWindow::_modalityCount() -> unsigned { - unsigned modalWindows = 0; +auto pWindow::_modalityCount() -> u32 { + u32 modalWindows = 0; for(auto& weak : windows) { if(auto object = weak.acquire()) { if(auto window = dynamic_cast(object.data())) { @@ -374,7 +374,7 @@ auto pWindow::_modalityDisabled() -> bool { } auto pWindow::_modalityUpdate() -> void { - unsigned modalWindows = _modalityCount(); + u32 modalWindows = _modalityCount(); for(auto& weak : windows) { if(auto object = weak.acquire()) { if(auto window = dynamic_cast(object.data())) { @@ -389,8 +389,8 @@ auto pWindow::_modalityUpdate() -> void { } } -auto pWindow::_statusHeight() const -> int { - int height = 0; +auto pWindow::_statusHeight() const -> s32 { + s32 height = 0; if(auto& statusBar = state().statusBar) { if(statusBar->visible()) { auto& text = statusBar->state.text; diff --git a/hiro/windows/window.hpp b/hiro/windows/window.hpp index b1082c86ee..564399a61c 100644 --- a/hiro/windows/window.hpp +++ b/hiro/windows/window.hpp @@ -7,7 +7,7 @@ struct pWindow : pObject { static auto initialize() -> void; - static uint minimumStatusHeight; + static u32 minimumStatusHeight; auto append(sMenuBar menuBar) -> void; auto append(sSizable sizable) -> void; @@ -15,7 +15,7 @@ struct pWindow : pObject { auto focused() const -> bool override; auto frameMargin() const -> Geometry; auto handle() const -> uintptr_t; - auto monitor() const -> uint; + auto monitor() const -> u32; auto remove(sMenuBar menuBar) -> void; auto remove(sSizable sizable) -> void; auto remove(sStatusBar statusBar) -> void; @@ -41,10 +41,10 @@ struct pWindow : pObject { auto windowProc(HWND, UINT, WPARAM, LPARAM) -> maybe; auto _geometry() -> Geometry; - auto _modalityCount() -> unsigned; + auto _modalityCount() -> u32; auto _modalityDisabled() -> bool; auto _modalityUpdate() -> void; - auto _statusHeight() const -> int; + auto _statusHeight() const -> s32; HWND hwnd = nullptr; HFONT hstatusfont = nullptr; diff --git a/lucia/GNUmakefile b/lucia/GNUmakefile index 3c361b6ca0..6a55e3400e 100644 --- a/lucia/GNUmakefile +++ b/lucia/GNUmakefile @@ -22,7 +22,7 @@ hiro.resource := resource/lucia.rc include $(hiro.path)/GNUmakefile profile := performance -cores := fc sfc n64 sg ms md ps1 pce msx cv gb gba ws ngp +cores := fc sfc sg ms md ps1 pce msx cv gb gba ws ngp ares.path := ../ares include $(ares.path)/GNUmakefile diff --git a/lucia/emulator/colecovision.cpp b/lucia/emulator/colecovision.cpp index b8f37d5d27..070c238f7f 100644 --- a/lucia/emulator/colecovision.cpp +++ b/lucia/emulator/colecovision.cpp @@ -18,7 +18,8 @@ ColecoVision::ColecoVision() { } auto ColecoVision::load() -> bool { - if(!ares::ColecoVision::load(root, "ColecoVision")) return false; + auto region = Emulator::region(); + if(!ares::ColecoVision::load(root, {"[Coleco] ColecoVision (", region, ")"})) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); diff --git a/lucia/emulator/emulator.cpp b/lucia/emulator/emulator.cpp index 8c096771f1..8d14ea87a2 100644 --- a/lucia/emulator/emulator.cpp +++ b/lucia/emulator/emulator.cpp @@ -157,6 +157,14 @@ auto Emulator::manifest() -> shared_pointer { game.manifest = cartridge->manifest(game.image, game.location); return vfs::memory::open(game.manifest.data(), game.manifest.size()); } + if(auto floppyDisk = medium.cast()) { + game.manifest = floppyDisk->manifest(game.image, game.location); + return vfs::memory::open(game.manifest.data(), game.manifest.size()); + } + if(auto compactDisc = medium.cast()) { + game.manifest = compactDisc->manifest(game.location); + return vfs::memory::open(game.manifest.data(), game.manifest.size()); + } return {}; } @@ -191,11 +199,28 @@ auto Emulator::manifest(const string& type, const string& location) -> shared_po return {}; } +auto Emulator::region() -> string { + auto document = BML::unserialize(game.manifest); + auto regions = document["game/region"].string().split(",").strip(); + if(!regions) return {}; + if(settings.boot.prefer == "NTSC-U" && regions.find("NTSC-U")) return "NTSC-U"; + if(settings.boot.prefer == "NTSC-J" && regions.find("NTSC-J")) return "NTSC-J"; + if(settings.boot.prefer == "NTSC-U" && regions.find("NTSC" )) return "NTSC"; + if(settings.boot.prefer == "NTSC-J" && regions.find("NTSC" )) return "NTSC"; + if(settings.boot.prefer == "PAL" && regions.find("PAL" )) return "PAL"; + if(regions.first()) return regions.first(); + if(settings.boot.prefer == "NTSC-J") return "NTSC-J"; + if(settings.boot.prefer == "NTSC-U") return "NTSC-U"; + if(settings.boot.prefer == "PAL" ) return "PAL"; + return {}; +} + auto Emulator::load(const string& location, const vector& image) -> bool { configuration.game = Location::dir(location); game.location = location; game.image = image; + if(!manifest()) return false; latch = {}; diff --git a/lucia/emulator/emulator.hpp b/lucia/emulator/emulator.hpp index c71a2f4438..a6ed44c8fa 100644 --- a/lucia/emulator/emulator.hpp +++ b/lucia/emulator/emulator.hpp @@ -6,6 +6,7 @@ struct Emulator { auto manifest() -> shared_pointer; auto manifest(const string& location) -> shared_pointer; auto manifest(const string& type, const string& location) -> shared_pointer; + auto region() -> string; auto load(const string& location, const vector& image) -> bool; auto loadFirmware(const Firmware&) -> shared_pointer; auto save() -> void; @@ -51,6 +52,7 @@ struct Emulator { u32 width = 0; u32 height = 0; u32 rotation = 0; + bool changed = false; //used to signal Program::main() to resize the presentation window } latch; }; diff --git a/lucia/emulator/famicom.cpp b/lucia/emulator/famicom.cpp index 6654e8f0bd..e7eb490699 100644 --- a/lucia/emulator/famicom.cpp +++ b/lucia/emulator/famicom.cpp @@ -27,7 +27,9 @@ Famicom::Famicom() { } auto Famicom::load() -> bool { - if(!ares::Famicom::load(root, "Famicom")) return false; + auto region = Emulator::region(); + auto system = region == "NTSC-J" ? "Famicom" : "Nintendo"; + if(!ares::Famicom::load(root, {"[Nintendo] ", system, " (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -119,7 +121,7 @@ auto FamicomDiskSystem::load(Menu menu) -> void { } auto FamicomDiskSystem::load() -> bool { - if(!ares::Famicom::load(root, "Famicom")) return false; + if(!ares::Famicom::load(root, "[Nintendo] Famicom (NTSC-J)")) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); diff --git a/lucia/emulator/game-boy-advance.cpp b/lucia/emulator/game-boy-advance.cpp index 6e231c0c72..eaa09de406 100644 --- a/lucia/emulator/game-boy-advance.cpp +++ b/lucia/emulator/game-boy-advance.cpp @@ -37,7 +37,7 @@ auto GameBoyAdvance::load(Menu menu) -> void { } auto GameBoyAdvance::load() -> bool { - if(!ares::GameBoyAdvance::load(root, "Game Boy Advance")) return false; + if(!ares::GameBoyAdvance::load(root, "[Nintendo] Game Boy Advance")) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); diff --git a/lucia/emulator/game-boy.cpp b/lucia/emulator/game-boy.cpp index a472e4f22d..f8df23fef4 100644 --- a/lucia/emulator/game-boy.cpp +++ b/lucia/emulator/game-boy.cpp @@ -23,7 +23,7 @@ GameBoy::GameBoy() { } auto GameBoy::load() -> bool { - if(!ares::GameBoy::load(root, "Game Boy")) return false; + if(!ares::GameBoy::load(root, "[Nintendo] Game Boy")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -110,7 +110,7 @@ GameBoyColor::GameBoyColor() { } auto GameBoyColor::load() -> bool { - if(!ares::GameBoy::load(root, "Game Boy Color")) return false; + if(!ares::GameBoy::load(root, "[Nintendo] Game Boy Color")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/master-system.cpp b/lucia/emulator/master-system.cpp index e60f5c3c9e..0c98c50ec6 100644 --- a/lucia/emulator/master-system.cpp +++ b/lucia/emulator/master-system.cpp @@ -23,13 +23,8 @@ MasterSystem::MasterSystem() { } auto MasterSystem::load() -> bool { - if(!ares::MasterSystem::load(root, "Master System II")) return false; - - if(auto region = root->find("Region")) { - if(settings.boot.prefer == "NTSC-U") region->setValue("NTSC-U → NTSC-J → PAL"); - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U → PAL"); - if(settings.boot.prefer == "PAL" ) region->setValue("PAL → NTSC-U → NTSC-J"); - } + auto region = Emulator::region(); + if(!ares::MasterSystem::load(root, {"[Sega] Master System (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -113,7 +108,7 @@ GameGear::GameGear() { } auto GameGear::load() -> bool { - if(!ares::MasterSystem::load(root, "Game Gear")) return false; + if(!ares::MasterSystem::load(root, "[Sega] Game Gear")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/mega-drive.cpp b/lucia/emulator/mega-drive.cpp index e8cbed4d1f..86b0df367f 100644 --- a/lucia/emulator/mega-drive.cpp +++ b/lucia/emulator/mega-drive.cpp @@ -25,13 +25,9 @@ MegaDrive::MegaDrive() { } auto MegaDrive::load() -> bool { - if(!ares::MegaDrive::load(root, "Mega Drive")) return false; - - if(auto region = root->find("Region")) { - if(settings.boot.prefer == "NTSC-U") region->setValue("NTSC-U → NTSC-J → PAL"); - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U → PAL"); - if(settings.boot.prefer == "PAL" ) region->setValue("PAL → NTSC-U → NTSC-J"); - } + auto region = Emulator::region(); + auto system = region == "NTSC-U" ? "Genesis" : "Mega Drive"; + if(!ares::MegaDrive::load(root, {"[Sega] ", system, " (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -100,22 +96,14 @@ MegaCD::MegaCD() { } auto MegaCD::load() -> bool { - if(!ares::MegaDrive::load(root, "Mega Drive")) return false; - - if(auto region = root->find("Region")) { - if(settings.boot.prefer == "NTSC-U") region->setValue("NTSC-U → NTSC-J → PAL"), regionID = 0; - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U → PAL"), regionID = 1; - if(settings.boot.prefer == "PAL" ) region->setValue("PAL → NTSC-U → NTSC-J"), regionID = 2; - } - - if(auto manifest = medium->manifest(game.location)) { - auto document = BML::unserialize(manifest); - auto regions = document["game/region"].string().split(","); - //if statements below are ordered by lowest to highest priority - if(regions.find("PAL" )) regionID = 2; - if(regions.find("NTSC-J")) regionID = 1; - if(regions.find("NTSC-U")) regionID = 0; - } + auto region = Emulator::region(); + auto system = region == "NTSC-U" ? "Genesis" : "Mega Drive"; + if(!ares::MegaDrive::load(root, {"[Sega] ", system, " (", region, ")"})) return false; + + //if statements below are ordered by lowest to highest priority + if(region == "PAL" ) regionID = 2; + if(region == "NTSC-J") regionID = 1; + if(region == "NTSC-U") regionID = 0; if(!file::exists(firmware[regionID].location)) { errorFirmwareRequired(firmware[regionID]); diff --git a/lucia/emulator/msx.cpp b/lucia/emulator/msx.cpp index 9a74089281..768c0d544e 100644 --- a/lucia/emulator/msx.cpp +++ b/lucia/emulator/msx.cpp @@ -23,7 +23,8 @@ MSX::MSX() { } auto MSX::load() -> bool { - if(!ares::MSX::load(root, "MSX")) return false; + auto region = Emulator::region(); + if(!ares::MSX::load(root, {"[Microsoft] MSX (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -80,7 +81,8 @@ MSX2::MSX2() { } auto MSX2::load() -> bool { - if(!ares::MSX::load(root, "MSX2")) return false; + auto region = Emulator::region(); + if(!ares::MSX::load(root, {"[Microsoft] MSX2 (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/neo-geo-pocket.cpp b/lucia/emulator/neo-geo-pocket.cpp index 3d760a0de0..7118ed217b 100644 --- a/lucia/emulator/neo-geo-pocket.cpp +++ b/lucia/emulator/neo-geo-pocket.cpp @@ -25,7 +25,7 @@ NeoGeoPocket::NeoGeoPocket() { } auto NeoGeoPocket::load() -> bool { - if(!ares::NeoGeoPocket::load(root, "Neo Geo Pocket")) return false; + if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket")) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); @@ -91,7 +91,7 @@ NeoGeoPocketColor::NeoGeoPocketColor() { } auto NeoGeoPocketColor::load() -> bool { - if(!ares::NeoGeoPocket::load(root, "Neo Geo Pocket Color")) return false; + if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket Color")) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); diff --git a/lucia/emulator/nintendo-64.cpp b/lucia/emulator/nintendo-64.cpp index 171b9652ea..3af04b46e3 100644 --- a/lucia/emulator/nintendo-64.cpp +++ b/lucia/emulator/nintendo-64.cpp @@ -23,7 +23,8 @@ Nintendo64::Nintendo64() { } auto Nintendo64::load() -> bool { - if(!ares::Nintendo64::load(root, "Nintendo 64")) return false; + auto region = Emulator::region(); + if(!ares::Nintendo64::load(root, {"[Nintendo] Nintendo 64 (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -103,7 +104,8 @@ Nintendo64DD::Nintendo64DD() { } auto Nintendo64DD::load() -> bool { - if(!ares::Nintendo64::load(root, "Nintendo 64")) return false; + auto region = Emulator::region(); + if(!ares::Nintendo64::load(root, {"[Nintendo] Nintendo 64 (", region, ")"})) return false; if(!file::exists(firmware[0].location)) { errorFirmwareRequired(firmware[0]); diff --git a/lucia/emulator/pc-engine.cpp b/lucia/emulator/pc-engine.cpp index a7b7490c70..f912cc9175 100644 --- a/lucia/emulator/pc-engine.cpp +++ b/lucia/emulator/pc-engine.cpp @@ -32,12 +32,9 @@ PCEngine::PCEngine() { } auto PCEngine::load() -> bool { - if(!ares::PCEngine::load(root, "PC Engine")) return false; - - if(auto region = root->find("Region")) { - if(settings.boot.prefer != "NTSC-J") region->setValue("NTSC-U → NTSC-J"); - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U"); - } + auto region = Emulator::region(); + string system = region == "NTSC-J" ? "PC Engine" : "TurboGrafx 16"; + if(!ares::PCEngine::load(root, {"[NEC] ", system, " (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -106,20 +103,13 @@ PCEngineCD::PCEngineCD() { } auto PCEngineCD::load() -> bool { - if(!ares::PCEngine::load(root, "PC Engine")) return false; + auto region = Emulator::region(); + auto system = region == "NTSC-J" ? "PC Engine" : "TurboGrafx 16"; + if(!ares::PCEngine::load(root, {"[NEC] ", system, " (", region, ")"})) return false; - if(auto region = root->find("Region")) { - if(settings.boot.prefer != "NTSC-J") region->setValue("NTSC-U → NTSC-J"), regionID = 0; - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U"), regionID = 1; - } - - if(auto manifest = medium->manifest(game.location)) { - auto document = BML::unserialize(manifest); - auto region = document["game/region"].string(); - //if statements below are ordered by lowest to highest priority - if(region == "NTSC-J") regionID = 1; - if(region == "NTSC-U") regionID = 0; - } + //if statements below are ordered by lowest to highest priority + if(region == "NTSC-J") regionID = 1; + if(region == "NTSC-U") regionID = 0; if(!file::exists(firmware[regionID].location)) { errorFirmwareRequired(firmware[regionID]); @@ -215,12 +205,7 @@ SuperGrafx::SuperGrafx() { } auto SuperGrafx::load() -> bool { - if(!ares::PCEngine::load(root, "SuperGrafx")) return false; - - if(auto region = root->find("Region")) { - if(settings.boot.prefer != "NTSC-J") region->setValue("NTSC-U → NTSC-J"); - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U"); - } + if(!ares::PCEngine::load(root, "[NEC] SuperGrafx (NTSC-J)")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/playstation.cpp b/lucia/emulator/playstation.cpp index 6ab8d9466e..edd15677e8 100644 --- a/lucia/emulator/playstation.cpp +++ b/lucia/emulator/playstation.cpp @@ -22,22 +22,13 @@ PlayStation::PlayStation() { } auto PlayStation::load() -> bool { - if(!ares::PlayStation::load(root, "PlayStation")) return false; + auto region = Emulator::region(); + if(!ares::PlayStation::load(root, {"[Sony] PlayStation (", region, ")"})) return false; - if(auto region = root->find("Region")) { - if(settings.boot.prefer == "NTSC-U") region->setValue("NTSC-U → NTSC-J → PAL"), regionID = 0; - if(settings.boot.prefer == "NTSC-J") region->setValue("NTSC-J → NTSC-U → PAL"), regionID = 1; - if(settings.boot.prefer == "PAL" ) region->setValue("PAL → NTSC-U → NTSC-J"), regionID = 2; - } - - if(auto manifest = medium->manifest(game.location)) { - auto document = BML::unserialize(manifest); - auto region = document["game/region"].string(); - //if statements below are ordered by lowest to highest priority - if(region == "PAL" ) regionID = 2; - if(region == "NTSC-J") regionID = 1; - if(region == "NTSC-U") regionID = 0; - } + //if statements below are ordered by lowest to highest priority + if(region == "PAL" ) regionID = 2; + if(region == "NTSC-J") regionID = 1; + if(region == "NTSC-U") regionID = 0; if(!file::exists(firmware[regionID].location)) { errorFirmwareRequired(firmware[regionID]); diff --git a/lucia/emulator/sg-1000.cpp b/lucia/emulator/sg-1000.cpp index 34ed21f1d7..54f4b3cea6 100644 --- a/lucia/emulator/sg-1000.cpp +++ b/lucia/emulator/sg-1000.cpp @@ -16,7 +16,8 @@ SG1000::SG1000() { } auto SG1000::load() -> bool { - if(!ares::SG1000::load(root, "SG-1000")) return false; + auto region = Emulator::region(); + if(!ares::SG1000::load(root, {"[Sega] SG-1000 (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/super-famicom.cpp b/lucia/emulator/super-famicom.cpp index 6672a0e69b..484513c7d6 100644 --- a/lucia/emulator/super-famicom.cpp +++ b/lucia/emulator/super-famicom.cpp @@ -16,7 +16,23 @@ SuperFamicom::SuperFamicom() { } auto SuperFamicom::load() -> bool { - if(!ares::SuperFamicom::load(root, "Super Famicom")) return false; + auto region = Emulator::region(); + if(region.beginsWith("NTSC") + || region.endsWith("BRA") + || region.endsWith("CAN") + || region.endsWith("HKG") + || region.endsWith("JPN") + || region.endsWith("KOR") + || region.endsWith("LTN") + || region.endsWith("ROC") + || region.endsWith("USA") + || region.beginsWith("SHVC-") + ) { + region = "NTSC"; + } else { + region = "PAL"; + } + if(!ares::SuperFamicom::load(root, {"[Nintendo] Super Famicom (", region, ")"})) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/emulator/wonderswan.cpp b/lucia/emulator/wonderswan.cpp index 24241c063d..b21e21a590 100644 --- a/lucia/emulator/wonderswan.cpp +++ b/lucia/emulator/wonderswan.cpp @@ -51,7 +51,7 @@ auto WonderSwan::load(Menu menu) -> void { } auto WonderSwan::load() -> bool { - if(!ares::WonderSwan::load(root, "WonderSwan")) return false; + if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -142,7 +142,7 @@ auto WonderSwanColor::load(Menu menu) -> void { } auto WonderSwanColor::load() -> bool { - if(!ares::WonderSwan::load(root, "WonderSwan Color")) return false; + if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan Color")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -221,7 +221,7 @@ auto PocketChallengeV2::load(Menu menu) -> void { } auto PocketChallengeV2::load() -> bool { - if(!ares::WonderSwan::load(root, "Pocket Challenge V2")) return false; + if(!ares::WonderSwan::load(root, "[Benesse] Pocket Challenge V2")) return false; if(auto port = root->find("Cartridge Slot")) { port->allocate(); diff --git a/lucia/input/input.hpp b/lucia/input/input.hpp index c20bcf10dd..03de3eb5d1 100644 --- a/lucia/input/input.hpp +++ b/lucia/input/input.hpp @@ -76,10 +76,10 @@ struct VirtualPad { InputButton r2{"R2"}; InputButton lt{"LT"}; InputButton rt{"RT"}; - InputAxis lx{"LX"}; - InputAxis ly{"LY"}; - InputAxis rx{"RX"}; - InputAxis ry{"RY"}; + InputAxis lx{"LX"}; + InputAxis ly{"LY"}; + InputAxis rx{"RX"}; + InputAxis ry{"RY"}; vector mappings; }; diff --git a/lucia/presentation/presentation.cpp b/lucia/presentation/presentation.cpp index c9e1cd2bd3..8deb8580d4 100644 --- a/lucia/presentation/presentation.cpp +++ b/lucia/presentation/presentation.cpp @@ -154,13 +154,14 @@ Presentation::Presentation() { }); helpMenu.setText("Help"); - aboutAction.setText("About lucia ...").setIcon(Icon::Prompt::Question).onActivate([&] { + aboutAction.setText("About ...").setIcon(Icon::Prompt::Question).onActivate([&] { image logo{Resource::Ares::Logo}; logo.shrink(); AboutDialog() .setLogo(logo) - .setDescription("lucia — a simplified multi-system emulator") + .setDescription({ares::Name, "/lucia — a simplified multi-system emulator"}) .setVersion(ares::Version) + .setCopyright(ares::Copyright) .setLicense(ares::License, ares::LicenseURI) .setWebsite(ares::Website, ares::WebsiteURI) .setAlignment(presentation) @@ -203,7 +204,7 @@ Presentation::Presentation() { }); resizeWindow(); - setTitle({"lucia v", ares::Version}); + setTitle({ares::Name, " v", ares::Version}); setBackgroundColor({0, 0, 0}); setAlignment(Alignment::Center); setVisible(); @@ -415,7 +416,7 @@ auto Presentation::loadEmulator() -> void { } auto Presentation::unloadEmulator(bool reloading) -> void { - setTitle({"lucia v", ares::Version}); + setTitle({ares::Name, " v", ares::Version}); systemMenu.setVisible(false); systemMenu.reset(); diff --git a/lucia/program/load.cpp b/lucia/program/load.cpp index ba6d4ef16a..e644b3a401 100644 --- a/lucia/program/load.cpp +++ b/lucia/program/load.cpp @@ -5,7 +5,7 @@ auto Program::identify(const string& filename) -> shared_pointer { } } - MessageDialog().setTitle("lucia").setText({ + MessageDialog().setTitle(ares::Name).setText({ "Filename: ", Location::file(filename), "\n\n" "Unable to determine what type of game this file is.\n" "Please use the load menu to choose the appropriate game system instead." @@ -74,7 +74,7 @@ auto Program::load(shared_pointer emulator, string filename) -> bool { string savesPath = settings.paths.saves; if(!savesPath) savesPath = Location::path(filename); if(!directory::writable(savesPath)) { - MessageDialog().setTitle("lucia").setText({ + MessageDialog().setTitle(ares::Name).setText({ "The current save path is read-only; please choose a writable save path now.\n" "Otherwise, any in-game progress will be lost once this game is unloaded!\n\n" "Current save location: ", savesPath @@ -133,7 +133,6 @@ auto Program::unload() -> void { propertiesViewer.unload(); traceLogger.unload(); message.text = ""; - ruby::video.acquireContext(); ruby::video.clear(); ruby::audio.clear(); } diff --git a/lucia/program/platform.cpp b/lucia/program/platform.cpp index 652eab68e8..a0d10b2b9e 100644 --- a/lucia/program/platform.cpp +++ b/lucia/program/platform.cpp @@ -55,7 +55,7 @@ auto Program::video(ares::Node::Video::Screen node, const u32* data, u32 pitch, emulator->latch.width = node->width(); emulator->latch.height = node->height(); emulator->latch.rotation = node->rotation(); - if(settings.video.adaptiveSizing) presentation.resizeWindow(); + emulator->latch.changed = true; //signal Program::main() to potentially resize the presentation window } u32 videoWidth = node->width() * node->scaleX(); @@ -64,7 +64,6 @@ auto Program::video(ares::Node::Video::Screen node, const u32* data, u32 pitch, if(node->rotation() == 90 || node->rotation() == 270) swap(videoWidth, videoHeight); ruby::video.lock(); - ruby::video.acquireContext(); auto [viewportWidth, viewportHeight] = ruby::video.size(); u32 multiplierX = viewportWidth / videoWidth; u32 multiplierY = viewportHeight / videoHeight; @@ -96,7 +95,6 @@ auto Program::video(ares::Node::Video::Screen node, const u32* data, u32 pitch, ruby::video.release(); ruby::video.output(outputWidth, outputHeight); } - ruby::video.releaseContext(); ruby::video.unlock(); static u64 frameCounter = 0, previous, current; diff --git a/lucia/program/program.cpp b/lucia/program/program.cpp index 55fdcf57bd..9bd1ccd9fd 100644 --- a/lucia/program/program.cpp +++ b/lucia/program/program.cpp @@ -69,6 +69,13 @@ auto Program::main() -> void { } } + //if Platform::video() changed the screen resolution, resize the presentation window here. + //window operations must be performed from the main thread. + if(emulator->latch.changed) { + emulator->latch.changed = false; + if(settings.video.adaptiveSizing) presentation.resizeWindow(); + } + memoryEditor.liveRefresh(); graphicsViewer.liveRefresh(); propertiesViewer.liveRefresh(); diff --git a/lucia/resource/lucia.Manifest b/lucia/resource/lucia.Manifest index 4ec355ec55..2f7a61b42b 100644 --- a/lucia/resource/lucia.Manifest +++ b/lucia/resource/lucia.Manifest @@ -1,6 +1,6 @@ - + diff --git a/luna/GNUmakefile b/luna/GNUmakefile deleted file mode 100644 index a05cf09f8b..0000000000 --- a/luna/GNUmakefile +++ /dev/null @@ -1,101 +0,0 @@ -name := luna -build := optimized -openmp := false -local := true -flags += -I. -I.. -I../ares - -ifeq ($(local),true) - flags += -march=native -endif - -nall.path := ../nall -include $(nall.path)/GNUmakefile - -libco.path := ../libco -include $(libco.path)/GNUmakefile - -ruby.path := ../ruby -include $(ruby.path)/GNUmakefile - -hiro.path := ../hiro -hiro.resource := resource/luna.rc -include $(hiro.path)/GNUmakefile - -profile := accuracy -cores := fc sfc n64 sg ms md ps1 pce msx cv gb gba ws ngp - -ares.path := ../ares -include $(ares.path)/GNUmakefile - -luna.path := ../luna - -luna.objects += luna luna-resource luna-emulator -luna.objects += luna-input luna-menus luna-program luna-settings -luna.objects := $(luna.objects:%=$(object.path)/%.o) - -$(object.path)/luna.o: $(luna.path)/luna.cpp -$(object.path)/luna-resource.o: $(luna.path)/resource/resource.cpp -$(object.path)/luna-emulator.o: $(luna.path)/emulator/emulator.cpp -$(object.path)/luna-input.o: $(luna.path)/input/input.cpp -$(object.path)/luna-menus.o: $(luna.path)/menus/menus.cpp -$(object.path)/luna-program.o: $(luna.path)/program/program.cpp -$(object.path)/luna-settings.o: $(luna.path)/settings/settings.cpp - -all.objects := $(libco.objects) $(ruby.objects) $(hiro.objects) $(ares.objects) $(luna.objects) -all.options := $(libco.options) $(ruby.options) $(hiro.options) $(ares.options) $(luna.options) $(options) - -all: $(all.objects) - $(info Linking $(output.path)/$(name) ...) - +@$(compiler) -o $(output.path)/$(name) $(all.objects) $(all.options) -ifeq ($(platform),macos) - rm -rf $(output.path)/$(name).app - mkdir -p $(output.path)/$(name).app/Contents/MacOS/ - mkdir -p $(output.path)/$(name).app/Contents/Resources/ - mv $(output.path)/$(name) $(output.path)/$(name).app/Contents/MacOS/$(name) - cp resource/$(name).plist $(output.path)/$(name).app/Contents/Info.plist - sips -s format icns resource/$(name).png --out $(output.path)/$(name).app/Contents/Resources/$(name).icns -endif - -verbose: nall.verbose ruby.verbose hiro.verbose all; - -clean: -ifeq ($(platform),macos) - rm -rf $(output.path)/$(name).app -endif - $(call delete,$(object.path)/*) - $(call delete,$(output.path)/*) - -install: all -ifeq ($(platform),windows) - mkdir -p $(prefix)/$(name)/ - cp -R $(ares.path)/System/* $(prefix)/$(name)/ -else ifeq ($(shell id -un),root) - $(error "make install should not be run as root") -else ifeq ($(platform),macos) - mkdir -p ~/Library/Application\ Support/$(name)/ - cp -R $(output.path)/$(name).app /Applications/$(name).app - cp -R $(ares.path)/System/* ~/Library/Application\ Support/$(name)/ -else ifneq ($(filter $(platform),linux bsd),) - mkdir -p $(prefix)/bin/ - mkdir -p $(prefix)/share/applications/ - mkdir -p $(prefix)/share/icons/ - mkdir -p $(prefix)/share/$(name)/ - cp $(output.path)/$(name) $(prefix)/bin/$(name) - cp -R $(ares.path)/System/* $(prefix)/share/$(name)/ - cp resource/$(name).desktop $(prefix)/share/applications/$(name).desktop - cp resource/$(name).png $(prefix)/share/icons/$(name).png -endif - -uninstall: -ifeq ($(platform),windows) -else ifeq ($(shell id -un),root) - $(error "make uninstall should not be run as root") -else ifeq ($(platform),macos) - rm -rf /Applications/$(name).app -else ifneq ($(filter $(platform),linux bsd),) - rm -f $(prefix)/bin/$(name) - rm -f $(prefix)/share/applications/$(name).desktop - rm -f $(prefix)/share/icons/$(name).png -endif - --include $(object.path)/*.d diff --git a/luna/emulator/audio.cpp b/luna/emulator/audio.cpp deleted file mode 100644 index 85b3e64f13..0000000000 --- a/luna/emulator/audio.cpp +++ /dev/null @@ -1,56 +0,0 @@ -auto Emulator::audioUpdate() -> void { - if(audioInstance && audioInstance.driver() != settings.audio.driver) { - audioInstance.reset(); - } - - if(!audioInstance) { - audioInstance.create(settings.audio.driver); - audioInstance.setContext(program.handle()); - if(!audioInstance.ready()) { - audioInstance.create(settings.audio.driver = "None"); - } - } - - if(audioInstance.hasDevice(settings.audio.device)) { - audioInstance.setDevice(settings.audio.device); - } else { - settings.audio.device = audioInstance.device(); - } - - if(audioInstance.hasFrequency(settings.audio.frequency)) { - audioInstance.setFrequency(settings.audio.frequency); - } else { - settings.audio.frequency = audioInstance.frequency(); - } - - if(audioInstance.hasLatency(settings.audio.latency)) { - audioInstance.setLatency(settings.audio.latency); - } else { - settings.audio.latency = audioInstance.latency(); - } - - if(audioInstance.hasExclusive()) { - audioInstance.setExclusive(settings.audio.exclusive); - } else { - settings.audio.exclusive = false; - } - - if(audioInstance.hasBlocking()) { - audioInstance.setBlocking(settings.audio.blocking); - } else { - settings.audio.blocking = false; - } - - if(audioInstance.hasDynamic()) { - audioInstance.setDynamic(settings.audio.dynamic); - } else { - settings.audio.dynamic = false; - } -} - -auto Emulator::audioUpdateEffects() -> void { - if(!interface) return; - for(auto stream : root->find()) { - stream->setResamplerFrequency(settings.audio.frequency + settings.audio.skew); - } -} diff --git a/luna/emulator/emulator.cpp b/luna/emulator/emulator.cpp deleted file mode 100644 index 29d2709404..0000000000 --- a/luna/emulator/emulator.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "../luna.hpp" -#include "platform.cpp" -#include "video.cpp" -#include "audio.cpp" -#include "input.cpp" -#include "states.cpp" -#include "status.cpp" -#include "utility.cpp" - -Emulator emulator; - -auto Emulator::create(shared_pointer instance, string location) -> void { - interface = instance; - - system = {}; - system.name = Location::base(location).trimRight("/", 1L); - system.data = location; - system.templates = {Path::templates, interface->name(), "/"}; - - string configuration = file::read({location, "settings.bml"}); - if(!configuration) { - auto system = ares::Node::System::create(); - system->setName(interface->name()); - system->setAttribute("location", location); - configuration = ares::Node::serialize(system); - } - - //peripherals may have been renamed or deleted since last run; remove them from the configuration now - auto document = BML::unserialize(configuration); - for(auto node : document) validateConfiguration(node, document); - configuration = BML::serialize(document); - - screens.reset(); - streams.reset(); - interface->load(root); - root->copy(ares::Node::unserialize(configuration)); - - systemMenu.setText(system.name); - toolsMenu.pauseEmulation.setChecked(false); - program.setEmulatorMode(); - program.setTitle(system.name); - program.setFocused(); - - videoUpdate(); - audioUpdate(); - inputManager.bind(root); - inputManager.poll(); - - power(false); -} - -auto Emulator::unload() -> void { - if(!interface) return; - - power(false); - if(system.log) system.log.close(); - - if(auto location = root->attribute("location")) { - file::write({location, "settings.bml"}, ares::Node::serialize(root)); - } - - inputManager.unbind(); - - root = {}; - interface->unload(); - interface.reset(); - - program.setTitle({"luna v", ares::Version}); - systemMenu.setText("System"); - setCaption(); -} - -auto Emulator::main() -> void { - updateMessage(); - if(Application::modal()) return; //modal loop calls usleep() internally - - inputManager.poll(); - hotkeys.poll(); - - if(!interface) return (void)usleep(20 * 1000); - - if(!system.power - || program.toolsMenu.pauseEmulation.checked() - || (!program.viewport.focused() && settings.input.unfocused == "Pause") - ) { - usleep(20 * 1000); - } else { - interface->run(); - if(events.power) power(false); //system powered itself off - } -} - -auto Emulator::quit() -> void { - //make quitting feel more responsive - program.setVisible(false); - Application::processEvents(); - - //stop processing callbacks and timers - Application::quit(); - - unload(); - - interfaces.reset(); - - videoInstance.reset(); - audioInstance.reset(); - inputInstance.reset(); -} - -auto Emulator::power(bool on) -> void { - if(system.power == on) return; - if(system.power = on) { - program.setTitle(interface->game()); - videoUpdateColors(); - audioUpdateEffects(); - events = {}; - interface->power(); - //powering on the system latches static settings - nodeManager.refreshSettings(); - if(settingEditor.visible()) settingEditor.refresh(); - program.viewport.setFocused(); - } else { - program.setTitle(system.name); - setCaption(); - videoInstance.clear(); - audioInstance.clear(); - inputInstance.release(); - } - systemMenu.power.setChecked(on); - toolsMenu.saveStateMenu.setEnabled(on); - toolsMenu.loadStateMenu.setEnabled(on); -} - -//used to prevent connecting the same (emulated) physical device to multiple ports simultaneously -auto Emulator::connected(string location) -> ares::Node::Port { - for(auto& peripheral : root->find()) { - if(location == peripheral->attribute("location")) { - if(auto parent = peripheral->parent()) return parent.acquire(); - } - } - return {}; -} - -auto Emulator::validateConfiguration(Markup::Node node, Markup::Node parent) -> void { - for(auto attribute : node.find("attribute")) { - if(attribute["name"].text() != "location") continue; - auto location = attribute["value"].text(); - //if the peripheral is missing, remove it from the tree - if(!directory::exists(location)) parent.remove(node); - } - for(auto branch : node) validateConfiguration(branch, node); -} diff --git a/luna/emulator/emulator.hpp b/luna/emulator/emulator.hpp deleted file mode 100644 index 108290ad37..0000000000 --- a/luna/emulator/emulator.hpp +++ /dev/null @@ -1,76 +0,0 @@ -struct Emulator : ares::Platform { - ares::Node::Object root; - - //emulator.cpp - auto create(shared_pointer, string location) -> void; - auto unload() -> void; - auto main() -> void; - auto quit() -> void; - auto power(bool on) -> void; - auto validateConfiguration(Markup::Node, Markup::Node) -> void; - - auto connected(string location) -> ares::Node::Port; - - //platform.cpp - auto attach(ares::Node::Object) -> void override; - auto detach(ares::Node::Object) -> void override; - auto open(ares::Node::Object, string name, vfs::file::mode mode, bool required) -> shared_pointer override; - auto event(ares::Event) -> void override; - auto log(string_view message) -> void override; - auto video(ares::Node::Screen, const uint32_t* data, uint pitch, uint width, uint height) -> void override; - auto audio(ares::Node::Stream) -> void override; - auto input(ares::Node::Input) -> void override; - - //video.cpp - auto videoUpdate() -> void; - auto videoUpdateColors() -> void; - auto videoUpdateShader() -> void; - auto videoToggleFullscreen() -> void; - - //audio.cpp - auto audioUpdate() -> void; - auto audioUpdateEffects() -> void; - - //input.cpp - auto inputUpdate() -> void; - - //states.cpp - auto saveState(uint slot) -> bool; - auto loadState(uint slot) -> bool; - - //status.cpp - auto updateMessage() -> void; - auto showMessage(const string& message = {}) -> void; - auto setCaption(const string& caption = {}) -> void; - - //utility.cpp - auto captureScreenshot(const uint32_t* data, uint pitch, uint width, uint height) -> void; - - struct System { - string name; - string data; - string templates; - bool power = false; - file_buffer log; - } system; - - struct Events { - bool power = false; - } events; - - struct Requests { - bool captureScreenshot = false; - } requests; - - struct State { - struct Message { - uint64_t timestamp = 0; - string text; - } message; - } state; - - vector screens; - vector streams; -}; - -extern Emulator emulator; diff --git a/luna/emulator/input.cpp b/luna/emulator/input.cpp deleted file mode 100644 index ff23f9f6be..0000000000 --- a/luna/emulator/input.cpp +++ /dev/null @@ -1,14 +0,0 @@ -auto Emulator::inputUpdate() -> void { - if(inputInstance && inputInstance.driver() != settings.input.driver) { - inputInstance.reset(); - } - - if(!inputInstance) { - inputInstance.create(settings.input.driver); - inputInstance.setContext(program.handle()); - inputInstance.onChange({&InputManager::eventInput, &inputManager}); - if(!inputInstance.ready()) { - inputInstance.create(settings.input.driver = "None"); - } - } -} diff --git a/luna/emulator/platform.cpp b/luna/emulator/platform.cpp deleted file mode 100644 index f4b2583462..0000000000 --- a/luna/emulator/platform.cpp +++ /dev/null @@ -1,210 +0,0 @@ -auto Emulator::attach(ares::Node::Object node) -> void { - if(interface && node->is()) { - screens = root->find(); - } - - if(interface && node->is()) { - streams = root->find(); - } -} - -auto Emulator::detach(ares::Node::Object node) -> void { - if(interface && node->is()) { - screens = root->find(); - } - - if(interface && node->is()) { - streams = root->find(); - } - - if(auto location = node->attribute("location")) { - file::write({location, "settings.bml"}, node->save()); - } -} - -auto Emulator::open(ares::Node::Object node, string name, vfs::file::mode mode, bool required) -> shared_pointer { - auto location = node->attribute("location"); - - if(name == "manifest.bml") { - if(!file::exists({location, name}) && directory::exists(location)) { - if(auto manifest = execute("mia", "--system", node->name(), "--manifest", location).output) { - return vfs::memory::open(manifest.data(), manifest.size()); - } - } - } - - if(auto result = vfs::disk::open({location, name}, mode)) return result; - - if(required) { - //attempt to pull required system firmware (boot ROMs, etc) from system template - if(location == emulator.system.data) { - if(file::exists({emulator.system.templates, name})) { - file::copy({emulator.system.templates, name}, {emulator.system.data, name}); - if(auto result = vfs::disk::open({location, name}, mode)) return result; - } - } - - if(MessageDialog() - .setTitle("Warning") - .setText({"Missing required file:\n", - location, name, "\n\n", - "Would you like to browse for this file now?"}) - .setAlignment(Alignment::Center) - .question() == "No") return {}; - - if(auto source = BrowserDialog() - .setTitle({"Load ", name}) - .setPath(location) - .setAlignment(Alignment::Center) - .openFile() - ) { - if(auto input = vfs::memory::open(source, true)) { - if(auto output = file::open({location, name}, file::mode::write)) { - output.write({input->data(), (uint)input->size()}); - } - } - if(auto result = vfs::disk::open({location, name}, mode)) return result; - } - } - - return {}; -} - -auto Emulator::event(ares::Event event) -> void { - if(event == ares::Event::Power) { - events.power = true; - } -} - -auto Emulator::log(string_view message) -> void { - if(!system.log) { - directory::create({"/tmpfs/Logs/", system.name, "/"}); - string datetime = chrono::local::datetime().transform("-: ", " _").replace(" ", ""); - system.log.open({"/tmpfs/Logs/", system.name, "/event-", datetime, ".log"}, file::mode::write); - } - system.log.print(message); -} - -auto Emulator::video(ares::Node::Screen node, const uint32_t* data, uint pitch, uint width, uint height) -> void { - if(requests.captureScreenshot) { - requests.captureScreenshot = false; - captureScreenshot(data, pitch, width, height); - } - - uint videoWidth = node->width() * node->scaleX(); - uint videoHeight = node->height() * node->scaleY(); - - if(settings.video.aspectCorrection) { - videoWidth = videoWidth * node->aspectX() / node->aspectY(); - } - - if(node->rotation() == 90 || node->rotation() == 270) { - swap(videoWidth, videoHeight); - } - - auto [viewportWidth, viewportHeight] = videoInstance.size(); - - uint multiplierX = viewportWidth / videoWidth; - uint multiplierY = viewportHeight / videoHeight; - uint multiplier = min(multiplierX, multiplierY); - - uint outputWidth = videoWidth * multiplier; - uint outputHeight = videoHeight * multiplier; - - if(multiplier == 0 || settings.video.output == "Scale") { - float multiplierX = (float)viewportWidth / (float)videoWidth; - float multiplierY = (float)viewportHeight / (float)videoHeight; - float multiplier = min(multiplierX, multiplierY); - - outputWidth = videoWidth * multiplier; - outputHeight = videoHeight * multiplier; - } - - if(settings.video.output == "Stretch") { - outputWidth = viewportWidth; - outputHeight = viewportHeight; - } - - pitch >>= 2; - if(auto [output, length] = videoInstance.acquire(width, height); output) { - length >>= 2; - for(auto y : range(height)) { - memory::copy(output + y * length, data + y * pitch, width); - } - videoInstance.release(); - videoInstance.output(outputWidth, outputHeight); - } - - static uint frameCounter = 0; - static uint64_t previous, current; - frameCounter++; - - current = chrono::timestamp(); - if(current != previous) { - previous = current; - setCaption({frameCounter, " fps"}); - frameCounter = 0; - } -} - -auto Emulator::audio(ares::Node::Stream) -> void { - if(!streams) return; //should never occur - - //process all pending frames (there may be more than one waiting) - while(true) { - //only process a frame if all streams have at least one pending frame - for(auto& stream : streams) { - if(!stream->pending()) return; - } - - //mix all frames together - double samples[2] = {0.0, 0.0}; - for(auto& stream : streams) { - double buffer[2]; - uint channels = stream->read(buffer); - if(channels == 1) { - //monaural -> stereo mixing - samples[0] += buffer[0]; - samples[1] += buffer[0]; - } else { - //stereo mixing - samples[0] += buffer[0]; - samples[1] += buffer[1]; - } - } - - //apply volume, balance, and clamping to the output frame - double volume = !settings.audio.mute ? settings.audio.volume : 0.0; - double balance = settings.audio.balance; - for(uint c : range(2)) { - samples[c] = max(-1.0, min(+1.0, samples[c] * volume)); - if(balance < 0.0) samples[1] *= 1.0 + balance; - if(balance > 0.0) samples[0] *= 1.0 - balance; - } - - //send frame to the audio output device - audioInstance.output(samples); - } -} - -auto Emulator::input(ares::Node::Input input) -> void { - inputManager.poll(); - - bool allow = program.viewport.focused(); - if(settings.input.unfocused == "Allow") allow = true; - if(videoInstance.exclusive()) allow = true; - - if(auto button = input->cast()) { - button->setValue(0); - if(auto instance = button->attribute>("instance")) { - if(allow) button->setValue(instance->value()); - } - } - - if(auto axis = input->cast()) { - axis->setValue(0); - if(auto instance = axis->attribute>("instance")) { - if(allow) axis->setValue(instance->value()); - } - } -} diff --git a/luna/emulator/states.cpp b/luna/emulator/states.cpp deleted file mode 100644 index 7d4ac50e8d..0000000000 --- a/luna/emulator/states.cpp +++ /dev/null @@ -1,33 +0,0 @@ -auto Emulator::saveState(uint slot) -> bool { - if(!system.power) return false; - if(auto cartridge = root->find(0)) { - if(auto location = cartridge->attribute("location")) { - if(auto state = interface->serialize()) { - directory::create({location, "State/"}); - if(file::write({location, "State/Slot ", slot, ".bst"}, {state.data(), state.size()})) { - showMessage({"Saved state ", slot}); - return true; - } - } - } - } - showMessage({"Failed to save state ", slot}); - return false; -} - -auto Emulator::loadState(uint slot) -> bool { - if(!system.power) return false; - if(auto cartridge = root->find(0)) { - if(auto location = cartridge->attribute("location")) { - if(auto memory = file::read({location, "State/Slot ", slot, ".bst"})) { - serializer state{memory.data(), (uint)memory.size()}; - if(interface->unserialize(state)) { - showMessage({"Loaded state ", slot}); - return true; - } - } - } - } - showMessage({"Failed to load state ", slot}); - return false; -} diff --git a/luna/emulator/status.cpp b/luna/emulator/status.cpp deleted file mode 100644 index 9f9285dfb3..0000000000 --- a/luna/emulator/status.cpp +++ /dev/null @@ -1,14 +0,0 @@ -auto Emulator::updateMessage() -> void { - if(chrono::millisecond() - state.message.timestamp >= 2000) { - program.statusMessage.setText(state.message.text); - } -} - -auto Emulator::showMessage(const string& message) -> void { - state.message.timestamp = chrono::millisecond(); - program.statusMessage.setText(message); -} - -auto Emulator::setCaption(const string& caption) -> void { - program.statusCaption.setText(caption); -} diff --git a/luna/emulator/utility.cpp b/luna/emulator/utility.cpp deleted file mode 100644 index 42b35e13a6..0000000000 --- a/luna/emulator/utility.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -auto Emulator::captureScreenshot(const uint32_t* data, uint pitch, uint width, uint height) -> void { - string filename{Path::desktop(), "luna ", chrono::local::datetime().transform(":", "-"), ".png"}; - Encode::PNG::RGB8(filename, data, pitch, width, height); - showMessage("Captured screenshot"); -} diff --git a/luna/emulator/video.cpp b/luna/emulator/video.cpp deleted file mode 100644 index 3b00543202..0000000000 --- a/luna/emulator/video.cpp +++ /dev/null @@ -1,82 +0,0 @@ -auto Emulator::videoUpdate() -> void { - if(videoInstance && videoInstance.driver() != settings.video.driver) { - videoInstance.reset(); - } - - if(!videoInstance) { - videoInstance.create(settings.video.driver); - videoInstance.setContext(program.viewport.handle()); - if(!videoInstance.ready()) { - videoInstance.reset(); - videoInstance.create(settings.video.driver = "None"); - } - settingsMenu.updateShaders(); - } - - if(videoInstance.hasMonitor(settings.video.monitor)) { - videoInstance.setMonitor(settings.video.monitor); - } else { - settings.video.monitor = videoInstance.monitor(); - } - - if(videoInstance.hasExclusive()) { - videoInstance.setExclusive(settings.video.exclusive); - } else { - settings.video.exclusive = videoInstance.exclusive(); - } - - if(videoInstance.hasBlocking()) { - videoInstance.setBlocking(settings.video.blocking); - } else { - settings.video.blocking = videoInstance.blocking(); - } - - if(videoInstance.hasFlush()) { - videoInstance.setFlush(settings.video.flush); - } else { - settings.video.flush = videoInstance.flush(); - } - - if(!videoInstance.hasFormat(settings.video.format)) { - settings.video.format = videoInstance.hasFormats().first(); - } - videoInstance.setFormat(settings.video.format); - - if(videoInstance.hasShader()) { - videoInstance.setShader(settings.video.shader); - } - - videoUpdateColors(); -} - -auto Emulator::videoUpdateColors() -> void { - if(!interface) return; - for(auto screen : root->find()) { - screen->setLuminance(settings.video.luminance); - screen->setSaturation(settings.video.saturation); - screen->setGamma(settings.video.gamma); - } -} - -auto Emulator::videoUpdateShader() -> void { - videoInstance.setShader(settings.video.shader); -} - -auto Emulator::videoToggleFullscreen() -> void { - if(!videoInstance.hasFullScreen()) return; - - //todo: when not in exclusive mode, it would be prudent to hide or minimize the programWindow. - //however, doing so causes the keypress to exit fullscreen to fall through to another window. - //if that window binds the same hotkey, it could trigger fullscreen there (eg xfce4-terminal.) - //so far, nothing I've tried can prevent this from happening, so I leave programWindow visible. - - videoInstance.clear(); //clear the video in the current mode before changing modes - if(!videoInstance.fullScreen()) { - videoInstance.setFullScreen(true); - if(videoInstance.exclusive()) inputInstance.acquire(); - } else { - videoInstance.setFullScreen(false); - inputInstance.release(); - program.viewport.setFocused(); - } -} diff --git a/luna/input/hotkeys.cpp b/luna/input/hotkeys.cpp deleted file mode 100644 index c785ee55bb..0000000000 --- a/luna/input/hotkeys.cpp +++ /dev/null @@ -1,144 +0,0 @@ -InputHotkey::InputHotkey(string_view name) : name(name) { -} - -auto InputHotkey::poll() -> void { - //don't allow hotkeys to trigger while emulator is unfocused - if(!videoInstance.fullScreen()) { - if(!program.focused()) return; - } else { - if(!videoInstance.focused()) return; - } - - //don't allow hotkeys to trigger while mapping them - if(hotkeySettings.visible()) return; - - if(device && !hotkeySettings.visible()) { - newValue = device->group(groupID).input(inputID).value(); - if(oldValue == 0 && newValue == 1 && onPress) onPress(); - if(oldValue == 1 && newValue == 0 && onRelease) onRelease(); - oldValue = newValue; - } -} - -Hotkeys::Hotkeys() { - toggleStatus.onPress = [&] { - if(program.statusLayout.visible()) { - program.hideStatus(); - } else { - program.showStatus(); - } - }; - hotkeys.append(&toggleStatus); - - togglePanels.onPress = [&] { - if(program.panelLayout.visible()) { - program.hidePanels(); - } else { - program.showPanels(); - } - }; - hotkeys.append(&togglePanels); - - toggleFullscreen.onPress = [&] { - if(!emulator.system.power) return; - emulator.videoToggleFullscreen(); - }; - hotkeys.append(&toggleFullscreen); - - toggleMouseCapture.onPress = [&] { - if(!emulator.system.power) return; - if(!inputInstance.acquired()) { - inputInstance.acquire(); - } else { - inputInstance.release(); - } - }; - hotkeys.append(&toggleMouseCapture); - - fastForward.onPress = [&] { - if(!interface) return; - fastForwardVideoBlocking = videoInstance.blocking(); - fastForwardAudioBlocking = audioInstance.blocking(); - fastForwardAudioDynamic = audioInstance.dynamic(); - videoInstance.setBlocking(false); - audioInstance.setBlocking(false); - audioInstance.setDynamic(false); - }; - fastForward.onRelease = [&] { - if(!interface) return; - videoInstance.setBlocking(fastForwardVideoBlocking); - audioInstance.setBlocking(fastForwardAudioBlocking); - audioInstance.setDynamic(fastForwardAudioDynamic); - }; - hotkeys.append(&fastForward); - - saveState.onPress = [&] { - emulator.saveState(stateSlot); - }; - hotkeys.append(&saveState); - - loadState.onPress = [&] { - emulator.loadState(stateSlot); - }; - hotkeys.append(&loadState); - - incrementStateSlot.onPress = [&] { - if(stateSlot < 5) stateSlot++; - else stateSlot = 1; - }; - hotkeys.append(&incrementStateSlot); - - decrementStateSlot.onPress = [&] { - if(stateSlot > 1) stateSlot--; - else stateSlot = 5; - }; - hotkeys.append(&decrementStateSlot); - - pauseEmulation.onPress = [&] { - if(!interface) return; - toolsMenu.pauseEmulation.setChecked(!toolsMenu.pauseEmulation.checked()); - }; - hotkeys.append(&pauseEmulation); - - exportMemory.onPress = [&] { - if(!interface) return; - interface->exportMemory(); - }; - hotkeys.append(&exportMemory); - - quitEmulator.onPress = [&] { - emulator.quit(); - }; - hotkeys.append(&quitEmulator); -} - -auto Hotkeys::poll() -> void { - for(auto& hotkey : hotkeys) hotkey->poll(); -} - -auto Hotkeys::bind() -> void { - for(auto& hotkey : hotkeys) { - hotkey->device.reset(); - auto part = hotkey->identifier.split("/"); - if(part.size() != 5) continue; - - hotkey->pathID = part[0].hex(); - hotkey->vendorID = part[1].hex(); - hotkey->productID = part[2].hex(); - string groupName = part[3]; - string inputName = part[4]; - - for(auto& device : inputManager.devices) { - if(hotkey->pathID != device->pathID()) continue; - if(hotkey->vendorID != device->vendorID()) continue; - if(hotkey->productID != device->productID()) continue; - if(auto groupID = device->find(groupName)) { - if(auto inputID = device->group(groupID()).find(inputName)) { - hotkey->device = device; - hotkey->groupID = groupID(); - hotkey->inputID = inputID(); - } - } - } - } -} diff --git a/luna/input/hotkeys.hpp b/luna/input/hotkeys.hpp deleted file mode 100644 index 8024ef7fa3..0000000000 --- a/luna/input/hotkeys.hpp +++ /dev/null @@ -1,47 +0,0 @@ -struct InputHotkey { - InputHotkey(string_view name); - auto poll() -> void; - - const string name; - string identifier; - - shared_pointer device; - uint pathID = 0; - uint vendorID = 0; - uint productID = 0; - uint groupID = 0; - uint inputID = 0; - - bool oldValue = 0; - bool newValue = 0; - - function onPress; - function onRelease; -}; - -struct Hotkeys { - Hotkeys(); - auto poll() -> void; - auto bind() -> void; - - InputHotkey toggleStatus{"Toggle Status Bar"}; - InputHotkey togglePanels{"Toggle System Panels"}; - InputHotkey toggleFullscreen{"Toggle Fullscreen"}; - InputHotkey toggleMouseCapture{"Toggle Mouse Capture"}; - InputHotkey fastForward{"Fast Forward"}; - InputHotkey saveState{"Save State"}; - InputHotkey loadState{"Load State"}; - InputHotkey incrementStateSlot{"Increment State Slot"}; - InputHotkey decrementStateSlot{"Decrement State Slot"}; - InputHotkey pauseEmulation{"Pause Emulation"}; - InputHotkey exportMemory{"Export Memory"}; - InputHotkey quitEmulator{"Quit Emulator"}; - - vector hotkeys; - -private: - uint stateSlot = 1; - bool fastForwardVideoBlocking = false; - bool fastForwardAudioBlocking = false; - bool fastForwardAudioDynamic = false; -}; diff --git a/luna/input/input.cpp b/luna/input/input.cpp deleted file mode 100644 index 11833e10ca..0000000000 --- a/luna/input/input.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "../luna.hpp" -#include "hotkeys.cpp" - -InputManager inputManager; -Hotkeys& hotkeys = inputManager.hotkeys; - -auto InputButton::value() -> int16_t { - auto value = device->group(groupID).input(inputID).value(); - - if(device->isKeyboard() && groupID == HID::Keyboard::Button) { - return value == 1; - } - - if(device->isJoypad() && (groupID == HID::Joypad::Axis || groupID == HID::Joypad::Hat)) { - if(qualifier == Qualifier::Lo && value < -16384) return 1; - if(qualifier == Qualifier::Hi && value > +16384) return 1; - return 0; - } - - if(device->isJoypad() && groupID == HID::Joypad::Button) { - return value == 1; - } - - return 0; -} - -// - -auto InputAxis::value() -> int16_t { - if(!inputInstance.acquired()) return 0; - auto value = device->group(groupID).input(inputID).value(); - - if(device->isMouse() && groupID == HID::Mouse::Axis) { - return value; - } - - return 0; -} - -// - -auto InputManager::bind(maybe newRoot) -> void { - if(newRoot) root = newRoot(); - if(!root) return; - - for(auto& input : root->find()) { - //not strictly necessary; but release any shared_pointer instances to free up the allocated memory - input->setAttribute>("instance"); - - auto _pathID = input->attribute("pathID"); if(!_pathID) continue; - auto _vendorID = input->attribute("vendorID"); if(!_vendorID) continue; - auto _productID = input->attribute("productID"); if(!_productID) continue; - - auto pathID = _pathID.natural(); - auto vendorID = _vendorID.natural(); - auto productID = _productID.natural(); - - for(auto& device : devices) { - if(pathID != device->pathID()) continue; - if(vendorID != device->vendorID()) continue; - if(productID != device->productID()) continue; - - if(input->cast()) { - auto instance = shared_pointer_make(); - instance->device = device; - instance->groupID = input->attribute("groupID").natural(); - instance->inputID = input->attribute("inputID").natural(); - if(input->attribute("qualifier") == "Lo") instance->qualifier = InputButton::Qualifier::Lo; - if(input->attribute("qualifier") == "Hi") instance->qualifier = InputButton::Qualifier::Hi; - input->setAttribute>("instance", instance); - break; - } - - if(input->cast()) { - auto instance = shared_pointer_make(); - instance->device = device; - instance->groupID = input->attribute("groupID").natural(); - instance->inputID = input->attribute("inputID").natural(); - input->setAttribute>("instance", instance); - break; - } - } - } -} - -auto InputManager::unbind() -> void { - this->root = {}; -} - -auto InputManager::poll() -> void { - //polling actual hardware is very time-consuming: skip call if poll was called too recently - auto thisPoll = chrono::millisecond(); - if(thisPoll - lastPoll < pollFrequency) return; - lastPoll = thisPoll; - - //poll hardware, detect when the available devices have changed: - //existing in-use devices may have been disconnected; or mapped but disconnected devices may now be available. - //as such, when the returned devices tree changes, rebind all inputs - auto devices = inputInstance.poll(); - bool changed = devices.size() != this->devices.size(); - if(!changed) { - for(uint n : range(devices.size())) { - if(changed = devices[n] != this->devices[n]) break; - } - } - if(changed) { - this->devices = devices; - bind(); - } -} - -auto InputManager::eventInput(shared_pointer device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void { - inputMapper.eventInput(device, group, input, oldValue, newValue); - hotkeySettings.eventInput(device, group, input, oldValue, newValue); -} diff --git a/luna/input/input.hpp b/luna/input/input.hpp deleted file mode 100644 index f39a43d3b2..0000000000 --- a/luna/input/input.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "hotkeys.hpp" - -struct InputAxis { - auto value() -> int16_t; - - const string name; - shared_pointer device; - uint groupID; - uint inputID; -}; - -struct InputButton { - auto value() -> int16_t; - - const string name; - shared_pointer device; - uint groupID; - uint inputID; - enum class Qualifier : uint { None, Lo, Hi } qualifier = Qualifier::None; -}; - -struct InputManager { - auto bind(maybe root = {}) -> void; - auto unbind() -> void; - - auto poll() -> void; - auto eventInput(shared_pointer, uint group, uint input, int16_t oldValue, int16_t newValue) -> void; - - ares::Node::Object root; - vector> devices; - Hotkeys hotkeys; - - uint64_t pollFrequency = 5; - uint64_t lastPoll = 0; -}; - -extern InputManager inputManager; -extern Hotkeys& hotkeys; diff --git a/luna/luna.cpp b/luna/luna.cpp deleted file mode 100644 index 6db48f5dad..0000000000 --- a/luna/luna.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "luna.hpp" - -shared_pointer interface; -vector> interfaces; - -namespace nall::Path { - string settings; - string templates; - string data; -} - -Video videoInstance; -Audio audioInstance; -Input inputInstance; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -auto nall::main(Arguments arguments) -> void { - Application::setName("luna"); - Application::setScreenSaver(false); - settings.load(); - - if(file::exists({Path::program(), "paths.bml"})) { - Path::settings = Path::program(); - } else { - Path::settings = {Path::userSettings(), "luna/"}; - directory::create(Path::settings); - } - if(auto document = BML::unserialize(file::read({Path::settings, "paths.bml"}))) { - Path::templates = document["templates"].text(); - Path::data = document["data"].text(); - } - if(!directory::exists(Path::templates)) { - Path::templates = {Path::userData(), "luna/"}; - directory::create(Path::templates); - } - if(!directory::exists(Path::data)) { - Path::data = {Path::user(), "luna/"}; - directory::create(Path::data); - } - file::write({Path::settings, "paths.bml"}, string{ - "data: ", Path::data, "\n", - "templates: ", Path::templates, "\n" - }); - - //create interfaces list in alphabetical order of interface->name() values - - #ifdef CORE_CV - interfaces.append(new ares::ColecoVision::ColecoVisionInterface); - #endif - - #ifdef CORE_FC - interfaces.append(new ares::Famicom::FamicomInterface); - #endif - - #ifdef CORE_GB - interfaces.append(new ares::GameBoy::GameBoyInterface); - #endif - - #ifdef CORE_GB - interfaces.append(new ares::GameBoy::GameBoyColorInterface); - #endif - - #ifdef CORE_GBA - interfaces.append(new ares::GameBoyAdvance::GameBoyAdvanceInterface); - #endif - - #ifdef CORE_GBA - interfaces.append(new ares::GameBoyAdvance::GameBoyPlayerInterface); - #endif - - #ifdef CORE_MD - interfaces.append(new ares::MegaDrive::MegaDriveInterface); - #endif - - #ifdef CORE_MS - interfaces.append(new ares::MasterSystem::GameGearInterface); - #endif - - #ifdef CORE_MS - interfaces.append(new ares::MasterSystem::MasterSystemInterface); - #endif - - #ifdef CORE_MSX - interfaces.append(new ares::MSX::MSXInterface); - #endif - - #ifdef CORE_MSX - interfaces.append(new ares::MSX::MSX2Interface); - #endif - - #ifdef CORE_N64 - interfaces.append(new ares::Nintendo64::Nintendo64Interface); - #endif - - #ifdef CORE_NGP - interfaces.append(new ares::NeoGeoPocket::NeoGeoPocketInterface); - #endif - - #ifdef CORE_NGP - interfaces.append(new ares::NeoGeoPocket::NeoGeoPocketColorInterface); - #endif - - #ifdef CORE_PCE - interfaces.append(new ares::PCEngine::PCEngineInterface); - #endif - - #ifdef CORE_PCE - interfaces.append(new ares::PCEngine::PCEngineDuoInterface); - #endif - - #ifdef CORE_PS1 - interfaces.append(new ares::PlayStation::PlayStationInterface); - #endif - - #ifdef CORE_WS - interfaces.append(new ares::WonderSwan::PocketChallengeV2Interface); - #endif - - #ifdef CORE_SG - interfaces.append(new ares::SG1000::SC3000Interface); - #endif - - #ifdef CORE_SG - interfaces.append(new ares::SG1000::SG1000Interface); - #endif - - #ifdef CORE_SFC - interfaces.append(new ares::SuperFamicom::SuperFamicomInterface); - #endif - - #ifdef CORE_PCE - interfaces.append(new ares::PCEngine::SuperGrafxInterface); - #endif - - #ifdef CORE_WS - interfaces.append(new ares::WonderSwan::SwanCrystalInterface); - #endif - - #ifdef CORE_WS - interfaces.append(new ares::WonderSwan::WonderSwanInterface); - #endif - - #ifdef CORE_WS - interfaces.append(new ares::WonderSwan::WonderSwanColorInterface); - #endif - - ares::platform = &emulator; - - Instances::program.construct(); - emulator.inputUpdate(); - inputManager.poll(); - hotkeys.bind(); - - Application::onMain({&Emulator::main, &emulator}); - Application::run(); - - settings.save(); - Instances::program.destruct(); -} diff --git a/luna/luna.hpp b/luna/luna.hpp deleted file mode 100644 index b5910deed6..0000000000 --- a/luna/luna.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace ruby; - -#include -using namespace hiro; - -#include -extern shared_pointer interface; -extern vector> interfaces; - -#include - -namespace nall::Path { - extern string settings; // ~/.local/share/luna/ - extern string templates; // ~/.local/share/luna/Systems/ - extern string data; // ~/luna/ -} - -extern Video videoInstance; -extern Audio audioInstance; -extern Input inputInstance; - -#include "resource/resource.hpp" -#include "menus/menus.hpp" -#include "program/program.hpp" -#include "settings/settings.hpp" -#include "input/input.hpp" -#include "emulator/emulator.hpp" diff --git a/luna/menus/action.cpp b/luna/menus/action.cpp deleted file mode 100644 index 7863f9181a..0000000000 --- a/luna/menus/action.cpp +++ /dev/null @@ -1,17 +0,0 @@ -ActionMenu::ActionMenu(MenuBar* parent) : Menu(parent) { - setText("System"); - create.setIcon(Icon::Action::Add).setText("Create").onActivate([&] { - program.setPanelList(systemManager); - systemManager.doCreate(); - }); - launch.setIcon(Icon::Media::Play).setText("Launch").setEnabled(false).onActivate([&] { - systemManager.onActivate(); - }); - rename.setIcon(Icon::Application::TextEditor).setText("Rename").setEnabled(false).onActivate([&] { - systemManager.doRename(); - }); - remove.setIcon(Icon::Action::Remove).setText("Delete").setEnabled(false).onActivate([&] { - systemManager.doRemove(); - }); - quit.setIcon(Icon::Action::Quit).setText("Quit").onActivate([&] { emulator.quit(); }); -} diff --git a/luna/menus/help.cpp b/luna/menus/help.cpp deleted file mode 100644 index 67479db503..0000000000 --- a/luna/menus/help.cpp +++ /dev/null @@ -1,16 +0,0 @@ -HelpMenu::HelpMenu(MenuBar* parent) : Menu(parent) { - setText("Help"); - about.setIcon(Icon::Prompt::Question).setText("About luna ...").onActivate([&] { - image logo{Resource::Ares::Logo}; - logo.shrink(); - AboutDialog() - .setLogo(logo) - .setDescription("luna — an advanced multi-system emulator") - .setVersion(ares::Version) - .setCopyright(ares::Copyright) - .setLicense(ares::License, ares::LicenseURI) - .setWebsite(ares::Website, ares::WebsiteURI) - .setAlignment(program, {0.5f, program.panelLayout.visible() ? 0.32f : 0.5f}) - .show(); - }); -} diff --git a/luna/menus/menus.cpp b/luna/menus/menus.cpp deleted file mode 100644 index 7405eff816..0000000000 --- a/luna/menus/menus.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "../luna.hpp" -#include "action.cpp" -#include "system.cpp" -#include "settings.cpp" -#include "tools.cpp" -#include "help.cpp" diff --git a/luna/menus/menus.hpp b/luna/menus/menus.hpp deleted file mode 100644 index 027014e6a6..0000000000 --- a/luna/menus/menus.hpp +++ /dev/null @@ -1,62 +0,0 @@ -struct ActionMenu : Menu { - ActionMenu(MenuBar*); - MenuItem create{this}; - MenuItem launch{this}; - MenuItem rename{this}; - MenuItem remove{this}; - MenuSeparator quitSeparator{this}; - MenuItem quit{this}; -}; - -struct SystemMenu : Menu { - SystemMenu(MenuBar*); - MenuCheckItem power{this}; - MenuSeparator unloadSeparator{this}; - MenuItem unload{this}; -}; - -struct SettingsMenu : Menu { - auto updateShaders() -> void; - - SettingsMenu(MenuBar*); - Menu outputMenu{this}; - MenuRadioItem outputCenter{&outputMenu}; - MenuRadioItem outputScale{&outputMenu}; - MenuRadioItem outputStretch{&outputMenu}; - Group videoOutputGroup{&outputCenter, &outputScale, &outputStretch}; - MenuSeparator outputSeparator{&outputMenu}; - MenuCheckItem aspectCorrection{&outputMenu}; - Menu scaleMenu{this}; - MenuItem scale2x{&scaleMenu}; - MenuItem scale3x{&scaleMenu}; - MenuItem scale4x{&scaleMenu}; - Menu shaderMenu{this}; - MenuSeparator separator{this}; - MenuCheckItem muteAudio{this}; - MenuCheckItem showStatusBar{this}; - MenuCheckItem showSystemPanels{this}; -}; - -struct ToolsMenu : Menu { - ToolsMenu(MenuBar*); - Menu saveStateMenu{this}; - MenuItem saveState1{&saveStateMenu}; - MenuItem saveState2{&saveStateMenu}; - MenuItem saveState3{&saveStateMenu}; - MenuItem saveState4{&saveStateMenu}; - MenuItem saveState5{&saveStateMenu}; - Menu loadStateMenu{this}; - MenuItem loadState1{&loadStateMenu}; - MenuItem loadState2{&loadStateMenu}; - MenuItem loadState3{&loadStateMenu}; - MenuItem loadState4{&loadStateMenu}; - MenuItem loadState5{&loadStateMenu}; - MenuSeparator stateSeparator{this}; - MenuItem captureScreenshot{this}; - MenuCheckItem pauseEmulation{this}; -}; - -struct HelpMenu : Menu { - HelpMenu(MenuBar*); - MenuItem about{this}; -}; diff --git a/luna/menus/settings.cpp b/luna/menus/settings.cpp deleted file mode 100644 index e63b9d0eb8..0000000000 --- a/luna/menus/settings.cpp +++ /dev/null @@ -1,100 +0,0 @@ -SettingsMenu::SettingsMenu(MenuBar* parent) : Menu(parent) { - setText("Settings"); - outputMenu.setText("Output").setIcon(Icon::Emblem::Image); - outputCenter.setText("Center").onActivate([&] { - settings.video.output = "Center"; - }); - outputScale.setText("Scale").onActivate([&] { - settings.video.output = "Scale"; - }); - outputStretch.setText("Stretch").onActivate([&] { - settings.video.output = "Stretch"; - }); - if(settings.video.output == "Center") outputCenter.setChecked(); - if(settings.video.output == "Scale") outputScale.setChecked(); - if(settings.video.output == "Stretch") outputStretch.setChecked(); - aspectCorrection.setText("Aspect Correction").setChecked(settings.video.aspectCorrection).onToggle([&] { - settings.video.aspectCorrection = aspectCorrection.checked(); - }); - scaleMenu.setText("Scale").setIcon(Icon::Emblem::Image); - scale2x.setText("640x480").onActivate([&] { - settings.video.scale = 2; - program.resize(); - }); - scale3x.setText("960x720").onActivate([&] { - settings.video.scale = 3; - program.resize(); - }); - scale4x.setText("1280x960").onActivate([&] { - settings.video.scale = 4; - program.resize(); - }); - shaderMenu.setText("Shader").setIcon(Icon::Emblem::Image).setEnabled(false); - muteAudio.setText("Mute Audio").setChecked(settings.audio.mute).onToggle([&] { - settings.audio.mute = muteAudio.checked(); - emulator.audioUpdateEffects(); - }); - showStatusBar.setText("Show Status Bar").setChecked(settings.interface.showStatusBar).onToggle([&] { - settings.interface.showStatusBar = showStatusBar.checked(); - if(showStatusBar.checked()) { - program.showStatus(); - } else { - program.hideStatus(); - } - }); - showSystemPanels.setText("Show System Panels").setChecked(settings.interface.showSystemPanels).onToggle([&] { - settings.interface.showSystemPanels = showSystemPanels.checked(); - if(showSystemPanels.checked()) { - program.showPanels(); - } else { - program.hidePanels(); - } - }); -} - -auto SettingsMenu::updateShaders() -> void { - shaderMenu.reset(); - if(!videoInstance.ready() || !videoInstance.hasShader()) { - shaderMenu.setEnabled(false); - return; - } - shaderMenu.setEnabled(); - - Group shaders; - - MenuRadioItem none{&shaderMenu}; - none.setText("None").onActivate([&] { - settings.video.shader = "None"; - emulator.videoUpdateShader(); - }); - shaders.append(none); - - MenuRadioItem blur{&shaderMenu}; - blur.setText("Blur").onActivate([&] { - settings.video.shader = "Blur"; - emulator.videoUpdateShader(); - }); - shaders.append(blur); - - string location{Path::settings, "Shaders/"}; - - if(settings.video.driver == "OpenGL 3.2") { - for(auto shaderName : directory::folders(location, "*.shader")) { - if(shaders.objectCount() == 2) shaderMenu.append(MenuSeparator()); - MenuRadioItem item{&shaderMenu}; - item.setText(Location::prefix(shaderName)).onActivate([=] { - settings.video.shader = {location, shaderName}; - emulator.videoUpdateShader(); - }); - shaders.append(item); - } - } - - if(settings.video.shader == "None") none.setChecked(); - if(settings.video.shader == "Blur") blur.setChecked(); - for(auto item : shaders.objects()) { - if(settings.video.shader == string{location, item.text(), ".shader/"}) { - item.setChecked(); - } - } -} diff --git a/luna/menus/system.cpp b/luna/menus/system.cpp deleted file mode 100644 index 527bcdbdcb..0000000000 --- a/luna/menus/system.cpp +++ /dev/null @@ -1,10 +0,0 @@ -SystemMenu::SystemMenu(MenuBar* parent) : Menu(parent) { - setText("System"); - power.setText("Power").onToggle([&] { emulator.power(power.checked()); }); - unload.setIcon(Icon::Go::Home).setText("Unload").onActivate([&] { - emulator.unload(); - program.showPanels(); - program.setOverviewMode(); - program.setTitle({"luna v", ares::Version}); - }); -} diff --git a/luna/menus/tools.cpp b/luna/menus/tools.cpp deleted file mode 100644 index 2ad1716128..0000000000 --- a/luna/menus/tools.cpp +++ /dev/null @@ -1,22 +0,0 @@ -ToolsMenu::ToolsMenu(MenuBar* parent) : Menu(parent) { - setText("Tools"); - saveStateMenu.setText("Save State"); - saveState1.setText("Slot 1").onActivate([&] { emulator.saveState(1); }); - saveState2.setText("Slot 2").onActivate([&] { emulator.saveState(2); }); - saveState3.setText("Slot 3").onActivate([&] { emulator.saveState(3); }); - saveState4.setText("Slot 4").onActivate([&] { emulator.saveState(4); }); - saveState5.setText("Slot 5").onActivate([&] { emulator.saveState(5); }); - - loadStateMenu.setText("Load State"); - loadState1.setText("Slot 1").onActivate([&] { emulator.loadState(1); }); - loadState2.setText("Slot 2").onActivate([&] { emulator.loadState(2); }); - loadState3.setText("Slot 3").onActivate([&] { emulator.loadState(3); }); - loadState4.setText("Slot 4").onActivate([&] { emulator.loadState(4); }); - loadState5.setText("Slot 5").onActivate([&] { emulator.loadState(5); }); - - captureScreenshot.setIcon(Icon::Emblem::Image).setText("Capture Screenshot").onActivate([&] { - emulator.requests.captureScreenshot = true; - }); - - pauseEmulation.setText("Pause Emulation"); -} diff --git a/luna/obj/.gitignore b/luna/obj/.gitignore deleted file mode 100644 index d6b7ef32c8..0000000000 --- a/luna/obj/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/luna/out/.gitignore b/luna/out/.gitignore deleted file mode 100644 index d6b7ef32c8..0000000000 --- a/luna/out/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/luna/panel-items/audio.cpp b/luna/panel-items/audio.cpp deleted file mode 100644 index 1f26848f9b..0000000000 --- a/luna/panel-items/audio.cpp +++ /dev/null @@ -1,120 +0,0 @@ -AudioSettings::AudioSettings(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - - driverHeader.setText("Audio Driver").setFont(Font().setBold()); - driverLabel.setText("Driver:"); - for(auto& driver : Audio::hasDrivers()) { - ComboButtonItem item{&driverOption}; - item.setText(driver); - if(driver == settings.audio.driver) item.setSelected(); - } - driverOption.onChange([&] { - settings.audio.driver = driverOption.selected().text(); - }); - changeButton.setText("Change").onActivate([&] { eventChange(); }); - - settingsHeader.setText("Driver Settings").setFont(Font().setBold()); - settingsLayout.setEnabled(false); - deviceLabel.setText("Device:"); - deviceOption.append(ComboButtonItem().setText(settings.audio.device)).onChange([&] { - settings.audio.device = deviceOption.selected().text(); - refresh(); - }); - frequencyLabel.setText("Frequency:"); - frequencyOption.append(ComboButtonItem().setText(settings.audio.frequency)).onChange([&] { - settings.audio.frequency = frequencyOption.selected().text().natural(); - refresh(); - emulator.audioUpdateEffects(); - }); - latencyLabel.setText("Latency:"); - latencyOption.append(ComboButtonItem().setText(settings.audio.latency)).onChange([&] { - settings.audio.latency = latencyOption.selected().text().natural(); - refresh(); - }); - exclusiveOption.setText("Exclusive").setChecked(settings.audio.exclusive).onToggle([&] { - settings.audio.exclusive = exclusiveOption.checked(); - refresh(); - }); - blockingOption.setText("Blocking").setChecked(settings.audio.blocking).onToggle([&] { - settings.audio.blocking = blockingOption.checked(); - refresh(); - }); - dynamicOption.setText("Dynamic").setChecked(settings.audio.dynamic).onToggle([&] { - settings.audio.dynamic = dynamicOption.checked(); - refresh(); - }); - - effectsHeader.setText("Effects").setFont(Font().setBold()); - effectsLayout.setSize({3, 3}); - effectsLayout.column(0).setAlignment(1.0); - skewLabel.setText("Skew:"); - skewValue.setAlignment(0.5); - skewSlider.setLength(10001).setPosition(settings.audio.skew + 5000).onChange([&] { - settings.audio.skew = (int)skewSlider.position() - 5000; - skewValue.setText({settings.audio.skew > 0 ? "+" : "", settings.audio.skew}); - emulator.audioUpdateEffects(); - }).doChange(); - volumeLabel.setText("Volume:"); - volumeValue.setAlignment(0.5); - volumeSlider.setLength(201).setPosition(settings.audio.volume * 100.0).onChange([&] { - settings.audio.volume = volumeSlider.position() / 100.0; - volumeValue.setText({volumeSlider.position(), "%"}); - emulator.audioUpdateEffects(); - }).doChange(); - balanceLabel.setText("Balance:"); - balanceValue.setAlignment(0.5); - balanceSlider.setLength(101).setPosition((settings.audio.balance * 50.0) + 50).onChange([&] { - settings.audio.balance = ((int)balanceSlider.position() - 50) / 50.0; - balanceValue.setText({balanceSlider.position(), "%"}); - emulator.audioUpdateEffects(); - }).doChange(); -} - -auto AudioSettings::show() -> void { - setVisible(true); -} - -auto AudioSettings::hide() -> void { - setVisible(false); -} - -auto AudioSettings::refresh() -> void { - emulator.audioUpdate(); - - deviceOption.reset(); - for(auto& device : audioInstance.hasDevices()) { - ComboButtonItem item{&deviceOption}; - item.setText(device); - if(device == settings.audio.device) item.setSelected(); - } - deviceOption.setEnabled(deviceOption.itemCount() > 1); - - frequencyOption.reset(); - for(auto& frequency : audioInstance.hasFrequencies()) { - ComboButtonItem item{&frequencyOption}; - item.setText(frequency); - if(frequency == settings.audio.frequency) item.setSelected(); - } - frequencyOption.setEnabled(frequencyOption.itemCount() > 1); - - latencyOption.reset(); - for(auto& latency : audioInstance.hasLatencies()) { - ComboButtonItem item{&latencyOption}; - item.setText(latency); - if(latency == settings.audio.latency) item.setSelected(); - } - latencyOption.setEnabled(latencyOption.itemCount() > 1); - - settingsLayout.resize(); - - exclusiveOption.setEnabled(audioInstance.hasExclusive()); - blockingOption.setEnabled(audioInstance.hasBlocking()); - dynamicOption.setEnabled(audioInstance.hasDynamic()); -} - -auto AudioSettings::eventChange() -> void { - settings.audio.driver = driverOption.selected().text(); - refresh(); - driverHeader.setText({"Audio Driver (", settings.audio.driver, ")"}); - settingsLayout.setEnabled(true); -} diff --git a/luna/panel-items/audio.hpp b/luna/panel-items/audio.hpp deleted file mode 100644 index 0b1e5a0e66..0000000000 --- a/luna/panel-items/audio.hpp +++ /dev/null @@ -1,42 +0,0 @@ -struct AudioSettings : PanelItem { - AudioSettings(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto eventChange() -> void; - - Frame frame{this, Size{~0, ~0}}; - VerticalLayout layout{&frame}; - - Label driverHeader{&layout, Size{~0, 0}}; - HorizontalLayout driverLayout{&layout, Size{~0, 0}}; - Label driverLabel{&driverLayout, Size{0, 0}}; - ComboButton driverOption{&driverLayout, Size{0, 0}}; - Button changeButton{&driverLayout, Size{0, 0}}; - - Label settingsHeader{&layout, Size{~0, 0}}; - VerticalLayout settingsLayout{&layout, Size{~0, 0}}; - HorizontalLayout deviceLayout{&settingsLayout, Size{~0, 0}}; - Label deviceLabel{&deviceLayout, Size{0, 0}}; - ComboButton deviceOption{&deviceLayout, Size{~0, 0}}; - Label frequencyLabel{&deviceLayout, Size{0, 0}}; - ComboButton frequencyOption{&deviceLayout, Size{0, 0}}; - Label latencyLabel{&deviceLayout, Size{0, 0}}; - ComboButton latencyOption{&deviceLayout, Size{0, 0}}; - HorizontalLayout togglesLayout{&settingsLayout, Size{~0, 0}}; - CheckLabel exclusiveOption{&togglesLayout, Size{0, 0}}; - CheckLabel blockingOption{&togglesLayout, Size{0, 0}}; - CheckLabel dynamicOption{&togglesLayout, Size{0, 0}}; - - Label effectsHeader{&layout, Size{~0, 0}}; - TableLayout effectsLayout{&layout, Size{~0, 0}}; - Label skewLabel{&effectsLayout, Size{0, 0}}; - Label skewValue{&effectsLayout, Size{50_sx, 0}}; - HorizontalSlider skewSlider{&effectsLayout, Size{~0, 0}}; - Label volumeLabel{&effectsLayout, Size{0, 0}}; - Label volumeValue{&effectsLayout, Size{50_sx, 0}}; - HorizontalSlider volumeSlider{&effectsLayout, Size{~0, 0}}; - Label balanceLabel{&effectsLayout, Size{0, 0}}; - Label balanceValue{&effectsLayout, Size{50_sx, 0}}; - HorizontalSlider balanceSlider{&effectsLayout, Size{~0, 0}}; -}; diff --git a/luna/panel-items/home.cpp b/luna/panel-items/home.cpp deleted file mode 100644 index 2a672e053f..0000000000 --- a/luna/panel-items/home.cpp +++ /dev/null @@ -1,23 +0,0 @@ -Home::Home(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - image icon{Resource::Ares::Icon}; - icon.shrink(); - for(uint y : range(icon.height())) { - auto data = icon.data() + y * icon.pitch(); - for(uint x : range(icon.width())) { - uint8_t alpha = icon.read(data) >> 24; - icon.write(data, uint8_t(alpha * 0.15) << 24); - data += icon.stride(); - } - } - icon.scale(sx(icon.width() * 0.75), sy(icon.height() * 0.75)); - iconCanvas.setIcon(icon); -} - -auto Home::show() -> void { - setVisible(true); -} - -auto Home::hide() -> void { - setVisible(false); -} diff --git a/luna/panel-items/home.hpp b/luna/panel-items/home.hpp deleted file mode 100644 index 8ea97739e9..0000000000 --- a/luna/panel-items/home.hpp +++ /dev/null @@ -1,8 +0,0 @@ -struct Home : PanelItem { - Home(View*); - auto show() -> void override; - auto hide() -> void override; - - Frame frame{this, Size{~0, ~0}}; - Canvas iconCanvas{&frame}; -}; diff --git a/luna/panel-items/hotkeys.cpp b/luna/panel-items/hotkeys.cpp deleted file mode 100644 index 06534b954e..0000000000 --- a/luna/panel-items/hotkeys.cpp +++ /dev/null @@ -1,126 +0,0 @@ -HotkeySettings::HotkeySettings(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - - headerLabel.setText("Hotkeys").setFont(Font().setBold()); - hotkeyList.setBatchable(); - hotkeyList.onActivate([&](auto cell) { eventAssign(); }); - hotkeyList.onChange([&] { eventChange(); }); - assignButton.setText("Assign").onActivate([&] { eventAssign(); }); - clearButton.setText("Clear").onActivate([&] { eventClear(); }); -} - -auto HotkeySettings::show() -> void { - refresh(); - setVisible(true); -} - -auto HotkeySettings::hide() -> void { - setVisible(false); - assigning.reset(); -} - -auto HotkeySettings::refresh() -> void { - hotkeyList.reset().setEnabled(); - hotkeyList.append(TableViewColumn().setText("Name")); - hotkeyList.append(TableViewColumn().setText("Mapping").setExpandable()); - for(auto& hotkey : hotkeys.hotkeys) { - TableViewItem item{&hotkeyList}; - item.setAttribute("hotkey", hotkey); - TableViewCell name{&item}; - name.setText(hotkey->name).setFont(Font().setBold()); - TableViewCell value{&item}; - } - update(); - hotkeyList.doChange(); -} - -auto HotkeySettings::update() -> void { - for(auto& item : hotkeyList.items()) { - auto value = item.cell(1); - auto hotkey = item.attribute("hotkey"); - if(hotkey->device) { - auto device = hotkey->device->name(); - if(device == "Keyboard") value.setIcon(Icon::Device::Keyboard); - else if(device == "Mouse") value.setIcon(Icon::Device::Mouse); - else if(device == "Joypad") value.setIcon(Icon::Device::Joypad); - else value.setIcon(Icon::Action::Close); - string label; - if(hotkey->device->isJoypad()) label.append(hotkey->device->group(hotkey->groupID).name(), "."); - label.append(hotkey->device->group(hotkey->groupID).input(hotkey->inputID).name()); - value.setText(label); - } else { - value.setIcon(Icon::Action::Close); - value.setText("(unmapped)"); - } - } - - hotkeyList.resizeColumns(); -} - -auto HotkeySettings::eventAssign() -> void { - inputManager.poll(); - assigningQueue = hotkeyList.batched(); - eventAssignNext(); -} - -auto HotkeySettings::eventAssignNext() -> void { - if(!assigningQueue) { - hotkeyList.selectNone().setFocused(); - return eventChange(); - } - - //use the viewport to sink inputs away from the table view during assignment - program.viewport.setFocused(); - auto item = assigningQueue.takeFirst(); - hotkeyList.selectNone(); - item.setSelected().setFocused(); - auto hotkey = item.attribute("hotkey"); - item.cell(1).setIcon(Icon::Go::Right).setText("(assign)"); - assigning = *hotkey; - eventChange(); -} - -auto HotkeySettings::eventClear() -> void { - if(auto batched = hotkeyList.batched()) { - for(auto& item : batched) { - auto hotkey = item.attribute("hotkey"); - hotkey->identifier = {}; - } - hotkeys.bind(); - update(); - } -} - -auto HotkeySettings::eventChange() -> void { - auto batched = hotkeyList.batched(); - assignButton.setEnabled((bool)batched); - clearButton.setEnabled((bool)batched); -} - -auto HotkeySettings::eventInput(shared_pointer device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void { - if(!assigning) return; - - bool allow = false; - - if(device->isKeyboard()) { - if(oldValue == 0 && newValue == 1) allow = true; - } - if(device->isJoypad() && group == HID::Joypad::Button) { - if(oldValue == 0 && newValue == 1) allow = true; - } - - if(!allow) return; - - assigning->identifier = {}; - if(device->group(group).input(input).name() != "Escape") { - assigning->identifier.append(hex(device->pathID()), "/"); - assigning->identifier.append(hex(device->vendorID()), "/"); - assigning->identifier.append(hex(device->productID()), "/"); - assigning->identifier.append(device->group(group).name(), "/"); - assigning->identifier.append(device->group(group).input(input).name()); - } - assigning.reset(); - hotkeys.bind(); - update(); - eventAssignNext(); -} diff --git a/luna/panel-items/hotkeys.hpp b/luna/panel-items/hotkeys.hpp deleted file mode 100644 index b3483ecaab..0000000000 --- a/luna/panel-items/hotkeys.hpp +++ /dev/null @@ -1,24 +0,0 @@ -struct InputHotkey; - -struct HotkeySettings : PanelItem { - HotkeySettings(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto update() -> void; - auto eventAssign() -> void; - auto eventAssignNext() -> void; - auto eventClear() -> void; - auto eventChange() -> void; - auto eventInput(shared_pointer, uint group, uint input, int16_t oldValue, int16_t newValue) -> void; - - Label headerLabel{this, Size{~0, 0}}; - TableView hotkeyList{this, Size{~0, ~0}}; - HorizontalLayout controlLayout{this, Size{~0, 0}}; - Widget spacer{&controlLayout, Size{~0, 0}, 0}; - Button assignButton{&controlLayout, Size{80_sx, 0}}; - Button clearButton{&controlLayout, Size{80_sx, 0}}; - - maybe assigning; - vector assigningQueue; -}; diff --git a/luna/panel-items/input-mapper.cpp b/luna/panel-items/input-mapper.cpp deleted file mode 100644 index fa8506ae0f..0000000000 --- a/luna/panel-items/input-mapper.cpp +++ /dev/null @@ -1,210 +0,0 @@ -InputMapper::InputMapper(View* view) : PanelItem(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - nameLabel.setFont(Font().setBold()); - inputList.setBatchable(); - inputList.onActivate([&](auto cell) { eventAssign(); }); - inputList.onChange([&] { eventChange(); }); - mouseXaxis.setText("Mouse X-axis").setCollapsible().onActivate([&] { eventAssignMouse(0, 0); }); - mouseYaxis.setText("Mouse Y-axis").setCollapsible().onActivate([&] { eventAssignMouse(0, 1); }); - mouseLeft.setText("Mouse Left").setCollapsible().onActivate([&] { eventAssignMouse(1, 0); }); - mouseMiddle.setText("Mouse Middle").setCollapsible().onActivate([&] { eventAssignMouse(1, 1); }); - mouseRight.setText("Mouse Right").setCollapsible().onActivate([&] { eventAssignMouse(1, 2); }); - assignButton.setText("Assign").onActivate([&] { eventAssign(); }); - clearButton.setText("Clear").onActivate([&] { eventClear(); }); -} - -auto InputMapper::show() -> void { - setVisible(true); -} - -auto InputMapper::hide() -> void { - setVisible(false); - node = {}; - inputList.reset(); -} - -auto InputMapper::refresh(ares::Node::Object node) -> void { - this->node = node; - - nameLabel.setText(node->name()); - inputList.reset().setEnabled(); - inputList.append(TableViewColumn().setText("Name")); - inputList.append(TableViewColumn().setText("Mapping").setExpandable()); - for(auto& node : node->find()) { - if(node->parent() != this->node) continue; - TableViewItem item{&inputList}; - item.setAttribute("node", node); - TableViewCell name{&item}; - name.setText(node->name()).setFont(Font().setBold()); - TableViewCell value{&item}; - } - update(); - inputList.doChange(); -} - -auto InputMapper::update() -> void { - for(auto& item : inputList.items()) { - auto value = item.cell(1); - auto node = item.attribute("node"); - if(auto name = node->attribute("inputName")) { - auto device = node->attribute("deviceName"); - if(device == "Keyboard") value.setIcon(Icon::Device::Keyboard); - else if(device == "Mouse") value.setIcon(Icon::Device::Mouse); - else if(device == "Joypad") value.setIcon(Icon::Device::Joypad); - else value.setIcon(Icon::Action::Close); - string label; - if(label == "Joypad") label.append(node->attribute("groupName"), "."); - label.append(node->attribute("inputName")); - if(auto qualifier = node->attribute("qualifier")) label.append(".", qualifier); - value.setText(label); - } else { - value.setIcon(Icon::Action::Close); - value.setText("(unmapped)"); - } - } - - inputList.resizeColumns(); -} - -auto InputMapper::eventAssignMouse(uint groupID, uint inputID) -> void { - auto batched = inputList.batched(); - if(batched.size() != 1) return; - for(auto& device : inputManager.devices) { - if(!device->isMouse()) continue; - assigning = batched.first().attribute("node"); - eventInput(device, groupID, inputID, 0, 1, true); - return; - } -} - -auto InputMapper::eventAssign() -> void { - //prevent an activation via the return key from mapping return instantly - inputManager.poll(); - - assigningQueue = inputList.batched(); //assign selected - if(!assigningQueue) assigningQueue = inputList.items(); //assign all - if(!assigningQueue) return; //no inputs to assign - - eventAssignNext(); -} - -auto InputMapper::eventAssignNext() -> void { - if(!assigningQueue) { - inputList.selectNone().setFocused(); - return eventChange(); - } - - //use the viewport to sink inputs away from the table view during assignment - program.viewport.setFocused(); - auto item = assigningQueue.takeFirst(); - inputList.selectNone(); - item.setSelected().setFocused(); //scroll the current assigning mapping into view - auto input = item.attribute("node"); - item.cell(1).setIcon(Icon::Go::Right).setText("(assign)"); - assigning = input; - eventChange(); -} - -auto InputMapper::eventClear() -> void { - auto batched = inputList.batched(); //clear selected - if(!batched) batched = inputList.items(); //clear all - if(!batched) return; //no inputs to clear - - for(auto& item : batched) { - auto input = item.attribute("node"); - input->setAttribute("pathID"); - input->setAttribute("vendorID"); - input->setAttribute("productID"); - input->setAttribute("groupID"); - input->setAttribute("inputID"); - input->setAttribute("deviceName"); - input->setAttribute("groupName"); - input->setAttribute("inputName"); - input->setAttribute("qualifier"); - } - inputManager.bind(); - update(); -} - -auto InputMapper::eventChange() -> void { - auto batched = inputList.batched(); - bool showMouseAxes = false; - bool showMouseButtons = false; - if(batched.size() == 1 && assigning) { - if(auto node = batched.first().attribute("node")) { - if(node->cast()) showMouseAxes = true; - if(node->cast()) showMouseButtons = true; - } - } - mouseXaxis.setVisible(showMouseAxes); - mouseYaxis.setVisible(showMouseAxes); - mouseLeft.setVisible(showMouseButtons); - mouseMiddle.setVisible(showMouseButtons); - mouseRight.setVisible(showMouseButtons); - controlLayout.resize(); - assignButton.setText((bool)batched ? "Assign" : "Assign All"); - clearButton.setText((bool)batched ? "Clear" : "Clear All"); -} - -auto InputMapper::eventInput(shared_pointer device, uint group, uint input, int16_t oldValue, int16_t newValue, bool allowMouseInput) -> void { - if(!assigning) return; - - auto isButton = (bool)assigning->cast(); - auto isAxis = (bool)assigning->cast(); - auto isTrigger = (bool)assigning->cast(); - auto isRumble = (bool)assigning->cast(); - - bool allow = false; - string qualifier; - - if(isButton) { - if(device->isKeyboard()) { - if(oldValue == 0 && newValue == 1) allow = true; - } - if(device->isJoypad() && (group == HID::Joypad::Axis || group == HID::Joypad::Hat)) { - if(newValue < -24576) allow = true, qualifier = "Lo"; - if(newValue > +24576) allow = true, qualifier = "Hi"; - } - if(device->isJoypad() && group == HID::Joypad::Button) { - if(oldValue == 0 && newValue == 1) allow = true; - } - } - - if(isAxis) { - } - - if(isTrigger) { - } - - if(isRumble) { - } - - if(allowMouseInput && device->isMouse()) allow = true; - if(!allow) return; - - if(device->group(group).input(input).name() == "Escape") { - assigning->setAttribute("pathID"); - assigning->setAttribute("vendorID"); - assigning->setAttribute("productID"); - assigning->setAttribute("groupID"); - assigning->setAttribute("inputID"); - assigning->setAttribute("deviceName"); - assigning->setAttribute("groupName"); - assigning->setAttribute("inputName"); - assigning->setAttribute("qualifier"); - } else { - assigning->setAttribute("pathID", device->pathID()); - assigning->setAttribute("vendorID", device->vendorID()); - assigning->setAttribute("productID", device->productID()); - assigning->setAttribute("groupID", group); - assigning->setAttribute("inputID", input); - assigning->setAttribute("deviceName", device->name()); - assigning->setAttribute("groupName", device->group(group).name()); - assigning->setAttribute("inputName", device->group(group).input(input).name()); - assigning->setAttribute("qualifier", qualifier); - } - assigning.reset(); - inputManager.bind(); - update(); - eventAssignNext(); -} diff --git a/luna/panel-items/input-mapper.hpp b/luna/panel-items/input-mapper.hpp deleted file mode 100644 index 4dbd4d81fb..0000000000 --- a/luna/panel-items/input-mapper.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct InputMapper : PanelItem { - InputMapper(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh(ares::Node::Object) -> void; - auto update() -> void; - - auto eventAssignMouse(uint groupID, uint inputID) -> void; - auto eventAssign() -> void; - auto eventAssignNext() -> void; - auto eventClear() -> void; - auto eventChange() -> void; - - auto eventInput(shared_pointer, uint group, uint input, int16_t oldValue, int16_t newValue, bool allowMouseInput = false) -> void; - - Label nameLabel{this, Size{~0, 0}}; - TableView inputList{this, Size{~0, ~0}}; - HorizontalLayout controlLayout{this, Size{~0, 0}}; - Button mouseXaxis{&controlLayout, Size{100_sx, 0}}; - Button mouseYaxis{&controlLayout, Size{100_sx, 0}}; - Button mouseLeft{&controlLayout, Size{100_sx, 0}}; - Button mouseMiddle{&controlLayout, Size{100_sx, 0}}; - Button mouseRight{&controlLayout, Size{100_sx, 0}}; - Widget spacer{&controlLayout, Size{~0, 0}, 0}; - Button assignButton{&controlLayout, Size{80_sx, 0}}; - Button clearButton{&controlLayout, Size{80_sx, 0}}; - - ares::Node::Object node; - ares::Node::Input assigning; - vector assigningQueue; -}; diff --git a/luna/panel-items/input.cpp b/luna/panel-items/input.cpp deleted file mode 100644 index c666948998..0000000000 --- a/luna/panel-items/input.cpp +++ /dev/null @@ -1,47 +0,0 @@ -InputSettings::InputSettings(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - - driverHeader.setText("Input Settings").setFont(Font().setBold()); - driverLabel.setText("Driver:"); - for(auto& driver : Input::hasDrivers()) { - ComboButtonItem item{&driverOption}; - item.setText(driver); - if(driver == settings.input.driver) item.setSelected(); - } - driverOption.onChange([&] { - settings.input.driver = driverOption.selected().text(); - }); - changeButton.setText("Change").onActivate([&] { eventChange(); }); - - focusLossHeader.setText("Focus Loss").setFont(Font().setBold()); - focusPause.setText("Pause emulation").onActivate([&] { - settings.input.unfocused = "Pause"; - }); - focusBlock.setText("Block input").onActivate([&] { - settings.input.unfocused = "Block"; - }); - focusAllow.setText("Allow input").onActivate([&] { - settings.input.unfocused = "Allow"; - }); - if(settings.input.unfocused == "Pause") focusPause.setChecked(); - if(settings.input.unfocused == "Block") focusBlock.setChecked(); - if(settings.input.unfocused == "Allow") focusAllow.setChecked(); -} - -auto InputSettings::show() -> void { - setVisible(true); -} - -auto InputSettings::hide() -> void { - setVisible(false); -} - -auto InputSettings::refresh() -> void { - emulator.inputUpdate(); -} - -auto InputSettings::eventChange() -> void { - settings.input.driver = driverOption.selected().text(); - refresh(); - driverHeader.setText({"Input Driver (", settings.input.driver, ")"}); -} diff --git a/luna/panel-items/input.hpp b/luna/panel-items/input.hpp deleted file mode 100644 index 1ef2d60e65..0000000000 --- a/luna/panel-items/input.hpp +++ /dev/null @@ -1,23 +0,0 @@ -struct InputSettings : PanelItem { - InputSettings(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto eventChange() -> void; - - Frame frame{this, Size{~0, ~0}}; - VerticalLayout layout{&frame}; - - Label driverHeader{&layout, Size{~0, 0}}; - HorizontalLayout driverLayout{&layout, Size{~0, 0}}; - Label driverLabel{&driverLayout, Size{0, 0}}; - ComboButton driverOption{&driverLayout, Size{0, 0}}; - Button changeButton{&driverLayout, Size{0, 0}}; - - Label focusLossHeader{&layout, Size{~0, 0}}; - HorizontalLayout focusLossLayout{&layout, Size{~0, 0}}; - RadioLabel focusPause{&focusLossLayout, Size{0, 0}}; - RadioLabel focusBlock{&focusLossLayout, Size{0, 0}}; - RadioLabel focusAllow{&focusLossLayout, Size{0, 0}}; - Group focusGroup{&focusPause, &focusBlock, &focusAllow}; -}; diff --git a/luna/panel-items/peripheral-overview.cpp b/luna/panel-items/peripheral-overview.cpp deleted file mode 100644 index 671cd2d01d..0000000000 --- a/luna/panel-items/peripheral-overview.cpp +++ /dev/null @@ -1,19 +0,0 @@ -PeripheralOverview::PeripheralOverview(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - header.setText("Manifest").setFont(Font().setBold()); - manifest.setFont(Font::Mono).setEditable(false).setWordWrap(false); -} - -auto PeripheralOverview::show() -> void { - setVisible(true); -} - -auto PeripheralOverview::hide() -> void { - setVisible(false); - peripheral = {}; -} - -auto PeripheralOverview::refresh(ares::Node::Peripheral peripheral) -> void { - this->peripheral = peripheral; - manifest.setText(peripheral->manifest()); -} diff --git a/luna/panel-items/peripheral-overview.hpp b/luna/panel-items/peripheral-overview.hpp deleted file mode 100644 index 42f088bf26..0000000000 --- a/luna/panel-items/peripheral-overview.hpp +++ /dev/null @@ -1,11 +0,0 @@ -struct PeripheralOverview : PanelItem { - PeripheralOverview(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh(ares::Node::Peripheral peripheral) -> void; - - Label header{this, Size{~0, 0}}; - TextEdit manifest{this, Size{~0, ~0}}; - - ares::Node::Peripheral peripheral; -}; diff --git a/luna/panel-items/port-connector.cpp b/luna/panel-items/port-connector.cpp deleted file mode 100644 index 1393953005..0000000000 --- a/luna/panel-items/port-connector.cpp +++ /dev/null @@ -1,298 +0,0 @@ -PortConnector::PortConnector(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - - renameAction.setIcon(Icon::Application::TextEditor).setText("Rename ...").onActivate([&] { eventRename(); }); - removeAction.setIcon(Icon::Action::Remove).setText("Delete ...").onActivate([&] { eventRemove(); }); - - locationLabel.setMouseCursor(MouseCursor::Hand); - locationLabel.setFont(Font().setBold()); - locationLabel.setForegroundColor({0, 0, 240}); - locationLabel.onMousePress([&](auto button) { - if(button == Mouse::Button::Left) eventBrowse(); - }); - peripheralList.onActivate([&] { eventActivate(); }); - peripheralList.onChange([&] { eventChange(); }); - peripheralList.onContext([&] { eventContext(); }); - importButton.setText("Import ...").onActivate([&] { eventImport(); }); - acceptButton.setText("Create").onActivate([&] { eventActivate(); }); -} - -auto PortConnector::show() -> void { - setVisible(true); -} - -auto PortConnector::hide() -> void { - setVisible(false); - port = {}; -} - -auto PortConnector::isMiaType() const -> bool { - if(!port) return false; //should never occur - if(port->type() == "Cartridge") return true; - if(port->type() == "Floppy Disk") return true; - if(port->type() == "Compact Disc") return true; - return false; -} - -auto PortConnector::refresh(ares::Node::Port port) -> void { - this->port = port; - importButton.setVisible(isMiaType()); - - auto path = port->attribute("path"); - //is this the first time refreshing this port? - if(!path) { - //see if there's a shared mia path for it - if(isMiaType()) { - path = {Path::user(), "Emulation/", port->family(), "/"}; - } - //if not, use a local path for it - if(!directory::exists(path)) { - path = {emulator.system.data, port->family(), " ", port->type(), "/"}; - } - port->setAttribute("path", path); - } - - //if this is a user path, replace the home directory with ~ for brevity - if(path.beginsWith(Path::user())) { - locationLabel.setText(string{path}.trimLeft(Path::user(), 1L).prepend("~/")); - } else { - locationLabel.setText(path); - } - - peripheralList.reset(); - ListViewItem item{&peripheralList}; - item.setAttribute("type", "nothing"); - item.setIcon(Icon::Action::Remove).setText("Nothing"); - if(!port->connected()) item.setSelected().setFocused(); - - if(string location = {emulator.system.templates, port->type(), "/"}) { - for(auto& name : directory::folders(location)) { - //if(!port->supported().find(name.trimRight("/", 1L))) continue; - ListViewItem item{&peripheralList}; - item.setAttribute("type", "template"); - item.setAttribute("location", {location, name, "/"}); - item.setAttribute("path", location); - item.setAttribute("name", name.trimRight("/", 1L)); - item.setIcon(Icon::Action::Add).setText(name); - } - } - - for(auto& name : directory::folders(path)) { - ListViewItem item{&peripheralList}; - item.setAttribute("type", "peripheral"); - item.setAttribute("location", {path, name}); - item.setAttribute("path", path); - item.setAttribute("name", name.trimRight("/", 1L)); - item.setIcon(Icon::Emblem::Folder).setText(name); - //set a currently connected peripheral as the active item - if(auto peripheral = port->connected()) { - if(name == peripheral->attribute("name")) { - item.setSelected().setFocused(); - } - } - } - - peripheralList.doChange(); -} - -auto PortConnector::eventImport() -> void { - if(auto location = execute("mia", "--system", interface->name(), "--import").output) { - refresh(port); - } -} - -auto PortConnector::eventActivate() -> void { - if(auto item = peripheralList.selected()) { - if(!port->hotSwappable() && emulator.system.power) { - auto response = MessageDialog() - .setText("The peripheral currently connected to this port isn't hot-swappable.\n" - "Removing it anyway may crash the emulated system.\n" - "What would you like to do?") - .setTitle("Warning").setAlignment(program).question({"Force", "Power Off", "Cancel"}); - if(response == "Cancel") return; - if(response == "Power Off") emulator.power(false); - } - - auto name = item.attribute("name"); - - if(item.attribute("type") == "nothing") { - port->disconnect(); - program.refreshPanelList(); - } - - else if(item.attribute("type") == "template") { - auto label = NameDialog() - .setTitle({"Create New ", name}) - .setAlignment(program) - .create(item.text()); - if(!label) return; - - auto source = item.attribute("location"); - auto target = string{emulator.system.data, port->family(), " ", port->type(), "/", label, "/"}; - if(directory::exists(target)) return (void)MessageDialog() - .setText("A directory by this name already exists.") - .setTitle("Error").setAlignment(program).error(); - - //if(directory::create(target)) { - if(directory::copy(source, target)) { - if(auto peripheral = port->allocate(name)) { - peripheral->setAttribute("location", target); - peripheral->setAttribute("name", label); - port->connect(); - inputManager.bind(); //bind any inputs this peripheral may contain - program.refreshPanelList(); - refresh(port); - } - } - } - - else if(item.attribute("type") == "peripheral") { - auto location = item.attribute("location"); - auto connected = emulator.connected(location); - - //treat selecting the already-connected device as a no-op that aborts the port connection dialog - if(connected && connected == port) return; - - if(connected) return (void)MessageDialog() - .setText({"This peripheral is already connected to another port:\n\n", connected->name()}) - .setTitle("Error").setAlignment(program).error(); - - if(auto markup = file::read({location, "settings.bml"})) { - auto node = ares::Node::unserialize(markup); - //update the location and name here, in case the folder moved since it was last connected - node->setAttribute("location", location); - node->setAttribute("name", item.attribute("name")); - if(auto peripheral = port->allocate(node->name())) { - peripheral->copy(node); - port->connect(); - peripheral->copy(node); - } - } else { - if(auto peripheral = port->allocate()) { - peripheral->setAttribute("location", location); - peripheral->setAttribute("name", item.attribute("name")); - port->connect(); - } - } - inputManager.bind(); //bind any inputs this peripheral may contain - program.refreshPanelList(); - } - } -} - -auto PortConnector::eventChange() -> void { - acceptButton.setVisible(false); - acceptButton.setEnabled(true); - - if(auto item = peripheralList.selected()) { - if(item.attribute("type") == "nothing") { - if(!port->connected()) { - acceptButton.setText("Disconnect").setEnabled(false).setVisible(); - } else { - acceptButton.setText("Disconnect").setVisible(); - } - } - - if(item.attribute("type") == "template") { - acceptButton.setText("Create").setVisible(); - } - - if(item.attribute("type") == "peripheral") { - auto peripheral = port->connected(); - if(peripheral && peripheral->attribute("name") == item.text()) { - acceptButton.setText("Connect").setEnabled(false).setVisible(); - } else { - acceptButton.setText("Connect").setVisible(); - } - } - } - - controlLayout.resize(); -} - -auto PortConnector::eventContext() -> void { - if(auto item = peripheralList.selected()) { - if(item.attribute("type") == "peripheral") { - contextMenu.setVisible(); - } - } -} - -auto PortConnector::eventBrowse() -> void { - auto path = port->attribute("path"); - if(auto location = BrowserDialog() - .setTitle({port->name(), " Location"}) - .setPath(path ? path : Path::user()) - .setAlignment(program).selectFolder() - ) { - port->setAttribute("path", location); - refresh(port); - } -} - -auto PortConnector::eventRename() -> void { - if(auto item = peripheralList.selected()) { - if(item.attribute("type") == "peripheral") { - auto location = item.attribute("location"); - auto path = item.attribute("path"); - auto name = item.attribute("name"); - if(auto rename = NameDialog() - .setAlignment(program) - .rename(name) - ) { - if(name == rename) return; - - if(directory::exists({path, rename})) return (void)MessageDialog() - .setText("A directory by this name already exists.") - .setTitle("Error").setAlignment(program).error(); - - if(!directory::rename({path, name}, {path, rename})) return (void)MessageDialog() - .setText("Failed to rename directory.") - .setTitle("Error").setAlignment(program).error(); - - //the location must be updated if this peripheral is already connected ... - if(auto connector = emulator.connected(location)) { - if(auto connected = connector->connected()) { - connected->setAttribute("location", {path, rename, "/"}); - connected->setAttribute("name", rename); - //the name will be updated in the system tree, so it must be refreshed: - program.refreshPanelList(); - } - } - - return refresh(port); - } - } - } -} - -auto PortConnector::eventRemove() -> void { - if(auto item = peripheralList.selected()) { - if(item.attribute("type") == "peripheral") { - auto location = item.attribute("location"); - auto connected = emulator.connected(location); - - if(!port->hotSwappable() && emulator.system.power && emulator.connected(location)) return (void)MessageDialog() - .setText({"This peripheral is not hot-swappable and is already connected to a port:\n\n", connected->name()}) - .setTitle("Error").setAlignment(program).error(); - - if(MessageDialog() - .setText("Are you really sure you want to delete this peripheral?\n" - "All data will be permanently lost!") - .setTitle("Warning").setAlignment(program).question() == "No" - ) return; - - //must disconnect device before removing it, as disconnect will attempt to save data to disk - if(connected) { - port->disconnect(); - program.refreshPanelList(); - } - - if(!directory::remove(location)) return (void)MessageDialog() - .setText("Failed to remove directory.") - .setTitle("Error").setAlignment(program).error(); - - refresh(port); - } - } -} diff --git a/luna/panel-items/port-connector.hpp b/luna/panel-items/port-connector.hpp deleted file mode 100644 index 661173bd03..0000000000 --- a/luna/panel-items/port-connector.hpp +++ /dev/null @@ -1,28 +0,0 @@ -struct PortConnector : PanelItem { - PortConnector(View*); - auto show() -> void override; - auto hide() -> void override; - auto isMiaType() const -> bool; - auto refresh(ares::Node::Port port) -> void; - - auto eventImport() -> void; - auto eventActivate() -> void; - auto eventChange() -> void; - auto eventContext() -> void; - auto eventBrowse() -> void; - auto eventRename() -> void; - auto eventRemove() -> void; - - PopupMenu contextMenu; - MenuItem renameAction{&contextMenu}; - MenuItem removeAction{&contextMenu}; - - Label locationLabel{this, Size{~0, 0}}; - ListView peripheralList{this, Size{~0, ~0}}; - HorizontalLayout controlLayout{this, Size{~0, 0}}; - Button importButton{&controlLayout, Size{80_sx, 0}}; - Widget controlSpacer{&controlLayout, Size{~0, 0}}; - Button acceptButton{&controlLayout, Size{80_sx, 0}}; - - ares::Node::Port port; -}; diff --git a/luna/panel-items/setting-editor.cpp b/luna/panel-items/setting-editor.cpp deleted file mode 100644 index 269a793ca9..0000000000 --- a/luna/panel-items/setting-editor.cpp +++ /dev/null @@ -1,51 +0,0 @@ -SettingEditor::SettingEditor(View* view) : PanelItem(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - nameLabel.setFont(Font().setBold()); - latchedLayout.setCollapsible(); - latchedLabel.setText("Latched:"); - valueList.onChange([&] { eventChange(); }); -} - -auto SettingEditor::show() -> void { - setVisible(true); -} - -auto SettingEditor::hide() -> void { - setVisible(false); - setting = {}; -} - -auto SettingEditor::refresh(ares::Node::Setting setting) -> void { - if(setting) { - this->setting = setting; //assigning a new setting to the editor - } else { - setting = this->setting; //refreshing an existing setting in the editor - } - nameLabel.setText(setting->name()); - latchedLayout.setVisible(!setting->dynamic()); - latchedValue.setText(setting->readLatch()); - valueList.reset(); - for(auto& value : setting->readAllowedValues()) { - ListViewItem item{&valueList}; - item.setText(value); - if(value == setting->readValue()) item.setSelected(); - } - resize(); -} - -auto SettingEditor::eventChange() -> void { - if(auto item = valueList.selected()) { - setting->writeValue(item.text()); - latchedValue.setText(setting->readLatch()); - nodeManager.refreshSettings(); - } else { - //the current value should always be selected - //if the user deselects all item, reselect the current value - for(auto& item : valueList.items()) { - if(item.text() == setting->readValue()) { - item.setSelected(); - break; - } - } - } -} diff --git a/luna/panel-items/setting-editor.hpp b/luna/panel-items/setting-editor.hpp deleted file mode 100644 index 67a03e8c91..0000000000 --- a/luna/panel-items/setting-editor.hpp +++ /dev/null @@ -1,17 +0,0 @@ -struct SettingEditor : PanelItem { - SettingEditor(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh(ares::Node::Setting setting = {}) -> void; - - auto eventChange() -> void; - - VerticalLayout layout{this, Size{~0, ~0}}; - Label nameLabel{&layout, Size{~0, 0}}; - HorizontalLayout latchedLayout{&layout, Size{~0, 0}}; - Label latchedLabel{&latchedLayout, Size{0, 0}}; - Label latchedValue{&latchedLayout, Size{~0, 0}}; - ListView valueList{&layout, Size{~0, ~0}}; - - ares::Node::Setting setting; -}; diff --git a/luna/panel-items/system-creation.cpp b/luna/panel-items/system-creation.cpp deleted file mode 100644 index cac419ac89..0000000000 --- a/luna/panel-items/system-creation.cpp +++ /dev/null @@ -1,78 +0,0 @@ -SystemCreation::SystemCreation(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - header.setText("Create New System").setFont(Font().setBold()); - systemList.onActivate([&] { eventAccept(); }); - systemList.onChange([&] { eventChange(); }); - nameLabel.setText("Name:"); - nameValue.onActivate([&] { eventAccept(); }); - createButton.setText("Create").onActivate([&] { eventAccept(); }); -} - -auto SystemCreation::show() -> void { - refresh(); - setVisible(true); -} - -auto SystemCreation::hide() -> void { - setVisible(false); -} - -auto SystemCreation::refresh() -> void { - systemList.reset(); - for(auto& interface : interfaces) { - ListViewItem item{&systemList}; - item.setAttribute>("interface", interface); - item.setText(interface->name()); - } - systemList.doChange(); -} - -auto SystemCreation::eventChange() -> void { - if(auto item = systemList.selected()) { - if(auto interface = item.attribute>("interface")) { - nameValue.setText(interface->name()); - nameLabel.setEnabled(true); - nameValue.setEnabled(true); - createButton.setEnabled(true); - return; - } - } - - //nothing selected - nameLabel.setEnabled(false); - nameValue.setEnabled(false).setText(""); - createButton.setEnabled(false); -} - -auto SystemCreation::eventAccept() -> void { - auto name = nameValue.text().strip(); - if(!name) return; - name.append("/"); - - auto location = Path::data; - if(directory::exists({location, name})) { - if(MessageDialog() - .setTitle("Warning") - .setText("A directory by this name already exists.\n" - "Do you wish to delete the existing directory and create a new one?") - .setAlignment(program).question() == "No" - ) return; - if(!directory::remove({location, name})) return (void)MessageDialog() - .setTitle("Error") - .setText("Failed to remove previous directory. The location may be read-only.") - .setAlignment(program).error(); - } - if(!directory::create({location, name})) return (void)MessageDialog() - .setTitle("Error") - .setText("Failed to create directory. Either the location is read-only, or the name contains invalid characters.") - .setAlignment(program).error(); - - if(auto interface = systemList.selected().attribute>("interface")) { - file::write({location, name, "manifest.bml"}, string{ - "system: ", interface->name(), "\n" - }); - } - - systemManager.refresh(); - program.setPanelItem(home); -} diff --git a/luna/panel-items/system-creation.hpp b/luna/panel-items/system-creation.hpp deleted file mode 100644 index b1ca882a07..0000000000 --- a/luna/panel-items/system-creation.hpp +++ /dev/null @@ -1,16 +0,0 @@ -struct SystemCreation : PanelItem { - SystemCreation(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - - auto eventChange() -> void; - auto eventAccept() -> void; - - Label header{this, Size{~0, 0}}; - ListView systemList{this, Size{~0, ~0}}; - HorizontalLayout controlLayout{this, Size{~0, 0}}; - Label nameLabel{&controlLayout, Size{0, 0}}; - LineEdit nameValue{&controlLayout, Size{~0, 0}}; - Button createButton{&controlLayout, Size{80_sx, 0}}; -}; diff --git a/luna/panel-items/system-overview.cpp b/luna/panel-items/system-overview.cpp deleted file mode 100644 index a27e81c541..0000000000 --- a/luna/panel-items/system-overview.cpp +++ /dev/null @@ -1,43 +0,0 @@ -SystemOverview::SystemOverview(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - header.setFont(Font().setBold()); - removeButton.setText("Remove").onActivate([&] { systemManager.doRemove(); }); - renameButton.setText("Rename").onActivate([&] { systemManager.doRename(); }); - launchButton.setText("Launch").onActivate([&] { systemManager.onActivate(); }); -} - -auto SystemOverview::show() -> void { - refresh(); - setVisible(true); -} - -auto SystemOverview::hide() -> void { - setVisible(false); -} - -auto SystemOverview::refresh() -> void { - auto location = systemManager.listView.selected().attribute("location"); - nodeList.reset(); - auto manifest = BML::unserialize(file::read({location, "manifest.bml"})); - header.setText(manifest["system"].text()); - if(auto root = ares::Node::unserialize(file::read({location, "settings.bml"}))) { - for(auto& node : *root) scan(node); - } -} - -auto SystemOverview::scan(ares::Node::Object node, uint depth) -> void { - if(node->is()) return; - if(node->is()) return; - if(node->is() && !settings.interface.advancedMode) return; - - ListViewItem item{&nodeList}; - string name; - for(uint n : range(depth)) name.append(" "); - name.append(node->attribute("name") ? node->attribute("name") : node->name()); - if(auto setting = node->cast()) { - name.append(": ", setting->readValue()); - } - - item.setText(name); - for(auto& node : *node) scan(node, depth + 1); -} diff --git a/luna/panel-items/system-overview.hpp b/luna/panel-items/system-overview.hpp deleted file mode 100644 index 5b3833a811..0000000000 --- a/luna/panel-items/system-overview.hpp +++ /dev/null @@ -1,15 +0,0 @@ -struct SystemOverview : PanelItem { - SystemOverview(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void override; - auto scan(ares::Node::Object node, uint depth = 0) -> void; - - Label header{this, Size{~0, 0}}; - ListView nodeList{this, Size{~0, ~0}}; - HorizontalLayout controlLayout{this, Size{~0, 0}}; - Label nameLabel{&controlLayout, Size{~0, 0}}; - Button removeButton{&controlLayout, Size{80, 0}}; - Button renameButton{&controlLayout, Size{80, 0}}; - Button launchButton{&controlLayout, Size{80, 0}}; -}; diff --git a/luna/panel-items/video.cpp b/luna/panel-items/video.cpp deleted file mode 100644 index 20452494a7..0000000000 --- a/luna/panel-items/video.cpp +++ /dev/null @@ -1,105 +0,0 @@ -VideoSettings::VideoSettings(View* parent) : PanelItem(parent, Size{~0, ~0}) { - setCollapsible().setVisible(false); - - driverHeader.setText("Video Driver").setFont(Font().setBold()); - driverLabel.setText("Driver:"); - for(auto& driver : Video::hasDrivers()) { - ComboButtonItem item{&driverOption}; - item.setText(driver); - if(driver == settings.video.driver) item.setSelected(); - } - changeButton.setText("Change").onActivate([&] { eventChange(); }); - - settingsHeader.setText("Driver Settings").setFont(Font().setBold()); - monitorLabel.setText("Monitor:"); - monitorOption.append(ComboButtonItem().setText(settings.video.monitor)).onChange([&] { - settings.video.monitor = monitorOption.selected().text(); - refresh(); - }); - formatLabel.setText("Format:"); - formatOption.append(ComboButtonItem().setText(settings.video.format)).onChange([&] { - settings.video.format = formatOption.selected().text(); - refresh(); - }); - exclusiveOption.setText("Exclusive").setChecked(settings.video.exclusive).onToggle([&] { - settings.video.exclusive = exclusiveOption.checked(); - refresh(); - }); - blockingOption.setText("Blocking").setChecked(settings.video.blocking).onToggle([&] { - settings.video.blocking = blockingOption.checked(); - refresh(); - }); - flushOption.setText("Flush").setChecked(settings.video.flush).onToggle([&] { - settings.video.flush = flushOption.checked(); - refresh(); - }); - - colorHeader.setText("Color Adjustment").setFont(Font().setBold()); - colorLayout.setSize({3, 3}); - colorLayout.column(0).setAlignment(1.0); - luminanceLabel.setText("Luminance:"); - luminanceValue.setAlignment(0.5); - luminanceSlider.setLength(101).setPosition(settings.video.luminance * 100.0).onChange([&] { - settings.video.luminance = luminanceSlider.position() / 100.0; - luminanceValue.setText({luminanceSlider.position(), "%"}); - emulator.videoUpdateColors(); - }).doChange(); - saturationLabel.setText("Saturation:"); - saturationValue.setAlignment(0.5); - saturationSlider.setLength(201).setPosition(settings.video.saturation * 100.0).onChange([&] { - settings.video.saturation = saturationSlider.position() / 100.0; - saturationValue.setText({saturationSlider.position(), "%"}); - emulator.videoUpdateColors(); - }).doChange(); - gammaLabel.setText("Gamma:"); - gammaValue.setAlignment(0.5); - gammaSlider.setLength(101).setPosition((settings.video.gamma - 1.0) * 100.0).onChange([&] { - settings.video.gamma = 1.0 + gammaSlider.position() / 100.0; - gammaValue.setText({100 + gammaSlider.position(), "%"}); - emulator.videoUpdateColors(); - }).doChange(); - viewport.setVisible(false); -} - -auto VideoSettings::show() -> void { - setVisible(true); -} - -auto VideoSettings::hide() -> void { - setVisible(false); -} - -auto VideoSettings::refresh() -> void { - emulator.videoUpdate(); - - monitorOption.reset(); - for(auto& monitor : Video::hasMonitors()) { - ComboButtonItem item{&monitorOption}; - item.setText(monitor.name); - if(monitor.name == settings.video.monitor) item.setSelected(); - } - monitorOption.setEnabled(monitorOption.itemCount() > 1); - - formatOption.reset(); - for(auto& format : videoInstance.hasFormats()) { - ComboButtonItem item{&formatOption}; - item.setText(format); - if(format == settings.video.format) item.setSelected(); - } -//formatOption.setEnabled(formatOption.itemCount() > 1); -//temporarily disabled; Emulator::Node::Sprite needs to be able to handle non-ARGB8888 formats first. - formatOption.setEnabled(false); - - optionsLayout.resize(); - - exclusiveOption.setEnabled(videoInstance.hasExclusive()).setChecked(videoInstance.exclusive()); - blockingOption.setEnabled(videoInstance.hasBlocking()).setChecked(videoInstance.blocking()); - flushOption.setEnabled(videoInstance.hasFlush()).setChecked(videoInstance.flush()); -} - -auto VideoSettings::eventChange() -> void { - settings.video.driver = driverOption.selected().text(); - refresh(); - driverHeader.setText({"Video Driver (", settings.video.driver, ")"}); - settingsLayout.setEnabled(true); -} diff --git a/luna/panel-items/video.hpp b/luna/panel-items/video.hpp deleted file mode 100644 index 3ac0e2b507..0000000000 --- a/luna/panel-items/video.hpp +++ /dev/null @@ -1,42 +0,0 @@ -struct VideoSettings : PanelItem { - VideoSettings(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto eventChange() -> void; - - Frame frame{this, Size{~0, ~0}}; - VerticalLayout layout{&frame}; - - Label driverHeader{&layout, Size{~0, 0}}; - HorizontalLayout driverLayout{&layout, Size{~0, 0}}; - Label driverLabel{&driverLayout, Size{0, 0}}; - ComboButton driverOption{&driverLayout, Size{0, 0}}; - Button changeButton{&driverLayout, Size{0, 0}}; - - Label settingsHeader{&layout, Size{~0, 0}}; - VerticalLayout settingsLayout{&layout, Size{~0, 0}}; - HorizontalLayout optionsLayout{&settingsLayout, Size{~0, 0}}; - Label monitorLabel{&optionsLayout, Size{0, 0}}; - ComboButton monitorOption{&optionsLayout, Size{0, 0}}; - Label formatLabel{&optionsLayout, Size{0, 0}}; - ComboButton formatOption{&optionsLayout, Size{0, 0}}; - HorizontalLayout togglesLayout{&settingsLayout, Size{~0, 0}}; - CheckLabel exclusiveOption{&togglesLayout, Size{0, 0}}; - CheckLabel blockingOption{&togglesLayout, Size{0, 0}}; - CheckLabel flushOption{&togglesLayout, Size{0, 0}}; - - Label colorHeader{&layout, Size{~0, 0}}; - TableLayout colorLayout{&layout, Size{~0, 0}}; - Label luminanceLabel{&colorLayout, Size{0, 0}}; - Label luminanceValue{&colorLayout, Size{50_sx, 0}}; - HorizontalSlider luminanceSlider{&colorLayout, Size{~0, 0}}; - Label saturationLabel{&colorLayout, Size{0, 0}}; - Label saturationValue{&colorLayout, Size{50_sx, 0}}; - HorizontalSlider saturationSlider{&colorLayout, Size{~0, 0}}; - Label gammaLabel{&colorLayout, Size{0, 0}}; - Label gammaValue{&colorLayout, Size{50_sx, 0}}; - HorizontalSlider gammaSlider{&colorLayout, Size{~0, 0}}; - Widget spacer{&layout, Size{~0, ~0}}; - Viewport viewport{&layout, Size{1, 1}}; -}; diff --git a/luna/panel-lists/event-manager.cpp b/luna/panel-lists/event-manager.cpp deleted file mode 100644 index 15cd4e044e..0000000000 --- a/luna/panel-lists/event-manager.cpp +++ /dev/null @@ -1,43 +0,0 @@ -EventManager::EventManager(View* view) : PanelList(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - listView.onChange([&] { onChange(); }); - listView.onToggle([&](auto item) { onToggle(item); }); -} - -auto EventManager::show() -> void { - listView.selectNone().doChange(); - refresh(); - setVisible(true); -} - -auto EventManager::hide() -> void { - setVisible(false); -} - -auto EventManager::refresh() -> void { - listView.reset(); - if(auto root = emulator.root) { - for(auto& node : *root) refresh(node); - } -} - -auto EventManager::refresh(ares::Node::Object node) -> void { - if(auto tracer = node->cast()) { - ListViewItem item{&listView}; - item.setAttribute("tracer", tracer); - item.setCheckable(); - item.setChecked(tracer->enabled()); - item.setText({tracer->component(), " ", tracer->name()}); - } - - for(auto& node : *node) refresh(node); -} - -auto EventManager::onChange() -> void { -} - -auto EventManager::onToggle(ListViewItem item) -> void { - if(auto tracer = item.attribute("tracer")) { - tracer->setEnabled(item.checked()); - } -} diff --git a/luna/panel-lists/event-manager.hpp b/luna/panel-lists/event-manager.hpp deleted file mode 100644 index 4ff2f273cb..0000000000 --- a/luna/panel-lists/event-manager.hpp +++ /dev/null @@ -1,12 +0,0 @@ -struct EventManager : PanelList { - EventManager(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void override; - auto refresh(ares::Node::Object node) -> void; - - auto onChange() -> void; - auto onToggle(ListViewItem) -> void; - - ListView listView{this, Size{~0, ~0}}; -}; diff --git a/luna/panel-lists/node-manager.cpp b/luna/panel-lists/node-manager.cpp deleted file mode 100644 index 97abe37a33..0000000000 --- a/luna/panel-lists/node-manager.cpp +++ /dev/null @@ -1,104 +0,0 @@ -NodeManager::NodeManager(View* view) : PanelList(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - listView.onChange([&] { onChange(); }); -} - -auto NodeManager::show() -> void { - root = emulator.root; - listView.selectNone().doChange(); - refresh(); - setVisible(true); -} - -auto NodeManager::hide() -> void { - setVisible(false); - root = {}; -} - -//recreate the tree after nodes have been added or removed -auto NodeManager::refresh() -> void { - //save the currently selected node to try and reselect it after rebuilding the tree - ares::Node::Object selected; - if(auto item = listView.selected()) { - selected = item.attribute("node"); - } - - listView.reset(); - if(root) for(auto& node : *root) refresh(node, 0); - - //try and restore the previously selected node - for(auto& item : listView.items()) { - if(item.attribute("node") == selected) { - item.setSelected().setFocused(); - } - } -} - -auto NodeManager::refresh(ares::Node::Object node, uint depth) -> void { - if(node->is()) return; - if(node->is()) return; - if(node->is()) return; - if(node->is()) return; - if(node->is()) return; - - ListViewItem item{&listView}; - item.setAttribute("node", node); - item.setAttribute("depth", depth); - item.setText(name(node, depth)); - - for(auto& node : *node) refresh(node, depth + 1); -} - -//refresh the tree after settings have changed -auto NodeManager::refreshSettings() -> void { - for(auto& item : listView.items()) { - auto node = item.attribute("node"); - if(auto setting = node->cast()) { - uint depth = item.attribute("depth"); - item.setText(name(node, depth)); - } - } -} - -//generate a name for the panel list for a given node -//insert spacing based on depth to simulate a TreeView in a ListView widget -auto NodeManager::name(ares::Node::Object node, uint depth) -> string { - string name; - for(uint n : range(depth)) name.append(" "); - name.append(node->attribute("name") ? node->attribute("name") : node->name()); - if(auto setting = node->cast()) { - name.append(": ", setting->readValue()); - if(!setting->dynamic() && setting->readLatch() != setting->readValue()) { - name.append(" (", setting->readLatch(), ")"); - } - } - return name; -} - -auto NodeManager::onChange() -> void { - if(auto node = listView.selected().attribute("node")) { - if(auto port = node->cast()) { - portConnector.refresh(port); - return program.setPanelItem(portConnector); - } - - if(auto setting = node->cast()) { - settingEditor.refresh(setting); - return program.setPanelItem(settingEditor); - } - - if(auto inputs = node->find()) { - if(inputs.first()->parent() == node) { - inputMapper.refresh(node); - return program.setPanelItem(inputMapper); - } - } - - if(auto peripheral = node->cast()) { - peripheralOverview.refresh(peripheral); - return program.setPanelItem(peripheralOverview); - } - } - - program.setPanelItem(home); -} diff --git a/luna/panel-lists/node-manager.hpp b/luna/panel-lists/node-manager.hpp deleted file mode 100644 index 2561ee0f01..0000000000 --- a/luna/panel-lists/node-manager.hpp +++ /dev/null @@ -1,13 +0,0 @@ -struct NodeManager : PanelList { - NodeManager(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto refresh(ares::Node::Object node, uint depth) -> void; - auto refreshSettings() -> void; - auto name(ares::Node::Object node, uint depth) -> string; - auto onChange() -> void; - - ares::Node::Object root; - ListView listView{this, Size{~0, ~0}}; -}; diff --git a/luna/panel-lists/port-manager.cpp b/luna/panel-lists/port-manager.cpp deleted file mode 100644 index b775aaa656..0000000000 --- a/luna/panel-lists/port-manager.cpp +++ /dev/null @@ -1,77 +0,0 @@ -PortManager::PortManager(View* view) : PanelList(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - listView.onChange([&] { onChange(); }); -} - -auto PortManager::show() -> void { - root = emulator.root; - listView.selectNone().doChange(); - refresh(); - setVisible(true); -} - -auto PortManager::hide() -> void { - setVisible(false); - root = {}; -} - -auto PortManager::refresh() -> void { - //save the currently selected node to try and reselect it after rebuilding the tree - ares::Node::Object selected; - if(auto item = listView.selected()) { - selected = item.attribute("node"); - } - - listView.reset(); - if(root) for(auto& node : *root) refresh(node); - - //try and restore the previously selected node - for(auto& item : listView.items()) { - if(item.attribute("node") == selected) { - item.setSelected().setFocused(); - } - } -} - -auto PortManager::refresh(ares::Node::Object node) -> void { - if(auto port = node->cast()) { - ListViewItem item{&listView}; - item.setAttribute("node", port); - item.setText(port->attribute("name") ? port->attribute("name") : port->name()); - if(auto peripheral = port->connected()) { - ListViewItem item{&listView}; - item.setAttribute("node", peripheral); - item.setText({" ", peripheral->attribute("name") ? peripheral->attribute("name") : peripheral->name()}); - } - } - - for(auto& node : *node) refresh(node); -} - -auto PortManager::onChange() -> void { - if(auto node = listView.selected().attribute("node")) { - if(auto port = node->cast()) { - portConnector.refresh(port); - return program.setPanelItem(portConnector); - } - - if(auto setting = node->cast()) { - settingEditor.refresh(setting); - return program.setPanelItem(settingEditor); - } - - if(auto inputs = node->find()) { - if(inputs.first()->parent() == node) { - inputMapper.refresh(node); - return program.setPanelItem(inputMapper); - } - } - - if(auto peripheral = node->cast()) { - peripheralOverview.refresh(peripheral); - return program.setPanelItem(peripheralOverview); - } - } - - program.setPanelItem(home); -} diff --git a/luna/panel-lists/port-manager.hpp b/luna/panel-lists/port-manager.hpp deleted file mode 100644 index 0cbe0f8e46..0000000000 --- a/luna/panel-lists/port-manager.hpp +++ /dev/null @@ -1,12 +0,0 @@ -struct PortManager : PanelList { - PortManager(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - auto refresh(ares::Node::Object node) -> void; - - auto onChange() -> void; - - ares::Node::Object root; - ListView listView{this, Size{~0, ~0}}; -}; diff --git a/luna/panel-lists/settings-manager.cpp b/luna/panel-lists/settings-manager.cpp deleted file mode 100644 index 5b3ed8da81..0000000000 --- a/luna/panel-lists/settings-manager.cpp +++ /dev/null @@ -1,32 +0,0 @@ -SettingsManager::SettingsManager(View* view) : PanelList(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - listView.onChange([&] { onChange(); }); -} - -auto SettingsManager::show() -> void { - listView.selectNone().doChange(); - refresh(); - setVisible(true); -} - -auto SettingsManager::hide() -> void { - setVisible(false); -} - -auto SettingsManager::refresh() -> void { - listView.reset(); - listView.append(ListViewItem().setText("Video").setIcon(Icon::Device::Display)); - listView.append(ListViewItem().setText("Audio").setIcon(Icon::Device::Speaker)); - listView.append(ListViewItem().setText("Input").setIcon(Icon::Device::Joypad)); - listView.append(ListViewItem().setText("Hotkeys").setIcon(Icon::Device::Keyboard)); -} - -auto SettingsManager::onChange() -> void { - if(auto item = listView.selected()) { - if(item.text() == "Video") return program.setPanelItem(videoSettings); - if(item.text() == "Audio") return program.setPanelItem(audioSettings); - if(item.text() == "Input") return program.setPanelItem(inputSettings); - if(item.text() == "Hotkeys") return program.setPanelItem(hotkeySettings); - } - return program.setPanelItem(home); -} diff --git a/luna/panel-lists/settings-manager.hpp b/luna/panel-lists/settings-manager.hpp deleted file mode 100644 index 1eae1d3b00..0000000000 --- a/luna/panel-lists/settings-manager.hpp +++ /dev/null @@ -1,10 +0,0 @@ -struct SettingsManager : PanelList { - SettingsManager(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - - auto onChange() -> void; - - ListView listView{this, Size{~0, ~0}}; -}; diff --git a/luna/panel-lists/system-manager.cpp b/luna/panel-lists/system-manager.cpp deleted file mode 100644 index 312083c998..0000000000 --- a/luna/panel-lists/system-manager.cpp +++ /dev/null @@ -1,157 +0,0 @@ -SystemManager::SystemManager(View* view) : PanelList(view, Size{~0, ~0}) { - setCollapsible().setVisible(false); - listView.onActivate([&] { onActivate(); }); - listView.onChange([&] { onChange(); }); - listView.onContext([&] { onContext(); }); - listCreate.setText("Create").setIcon(Icon::Action::Add).onActivate([&] { doCreate(); }); - listLaunch.setText("Launch").setIcon(Icon::Media::Play).onActivate([&] { onActivate(); }); - listRename.setText("Rename").setIcon(Icon::Application::TextEditor).onActivate([&] { doRename(); }); - listRemove.setText("Remove").setIcon(Icon::Action::Remove).onActivate([&] { doRemove(); }); -} - -auto SystemManager::show() -> void { - listView.selectNone().doChange(); - refresh(); - setVisible(true); -} - -auto SystemManager::hide() -> void { - setVisible(false); - actionMenu.rename.setEnabled(false); - actionMenu.remove.setEnabled(false); -} - -auto SystemManager::refresh() -> void { - listView.reset(); - listView.doChange(); - - ListViewItem item{&listView}; - item.setIcon(Icon::Action::Add); - item.setText("Create New System"); - - auto location = Path::data; - for(auto& name : directory::folders(location)) { - auto document = BML::unserialize(file::read({location, name, "/", "manifest.bml"})); - if(!document) continue; - - auto system = document["system"].text(); - ListViewItem item{&listView}; - item.setAttribute("location", {location, name}); - item.setAttribute("path", location); - item.setAttribute("name", name.trimRight("/", 1L)); - item.setAttribute("system", system); - item.setIcon(Icon::Place::Server); - item.setText(name); - - //hignlight any systems found that have not been compiled into this binary - if(!interfaces.find([&](auto interface) { return interface->name() == system; })) { - item.setForegroundColor({240, 80, 80}); - //only show the missing systems in advanced mode - if(!settings.interface.advancedMode) item.remove(); - } - } -} - -auto SystemManager::onActivate() -> void { - if(auto item = listView.selected()) { - if(!item.attribute("path")) return; - if(auto system = item.attribute("system")) { - if(auto index = interfaces.find([&](auto interface) { return interface->name() == system; })) { - emulator.create(interfaces[*index], {item.attribute("path"), item.attribute("name"), "/"}); - } - } - } -} - -auto SystemManager::onChange() -> void { - auto item = listView.selected(); - if(item && !item.attribute("location")) { - program.setPanelItem(systemCreation); - actionMenu.create.setEnabled(true); - actionMenu.launch.setEnabled(false); - actionMenu.rename.setEnabled(false); - actionMenu.remove.setEnabled(false); - } else if(item && item.attribute("location")) { - systemOverview.refresh(); - program.setPanelItem(systemOverview); - actionMenu.create.setEnabled(false); - actionMenu.launch.setEnabled(true); - actionMenu.rename.setEnabled(true); - actionMenu.remove.setEnabled(true); - } else { - program.setPanelItem(home); - actionMenu.create.setEnabled(true); - actionMenu.launch.setEnabled(false); - actionMenu.rename.setEnabled(false); - actionMenu.remove.setEnabled(false); - } -} - -auto SystemManager::onContext() -> void { - if(auto item = listView.selected()) { - if(!item.attribute("path")) return; //no context menu for "Create New System" option - listCreate.setVisible(false); - listLaunch.setVisible(true); - listRename.setVisible(true); - listRemove.setVisible(true); - listMenu.setVisible(); - } else { - listCreate.setVisible(true); - listLaunch.setVisible(false); - listRename.setVisible(false); - listRemove.setVisible(false); - listMenu.setVisible(); - } -} - -auto SystemManager::doCreate() -> void { - //clear the current selection to indicate that creation isn't related to the currently selected system item - listView.selectNone(); - program.setPanelItem(systemCreation); -} - -auto SystemManager::doRename() -> void { - if(auto item = listView.selected()) { - if(!item.attribute("path")) return; - auto path = item.attribute("path"); - auto from = item.attribute("name"); - if(auto name = NameDialog() - .setAlignment(program) - .rename(from) - ) { - if(name == from) return; - if(directory::exists({path, name})) return (void)MessageDialog() - .setTitle("Error") - .setText("A directory with this name already exists.\n" - "Please choose a unique name.") - .setAlignment(program) - .error(); - if(!directory::rename({path, from}, {path, name})) return (void)MessageDialog() - .setTitle("Error") - .setText("Failed to rename directory.") - .setAlignment(program) - .error(); - refresh(); - } - } -} - -auto SystemManager::doRemove() -> void { - if(auto item = listView.selected()) { - if(!item.attribute("path")) return; - if(MessageDialog() - .setTitle({"Delete ", item.attribute("name")}) - .setText("Are you sure you want to permanently delete the selected system?\n" - "All of its contents will be permanently lost!") - .setAlignment(program) - .question() != "Yes") return; - auto location = string{item.attribute("path"), item.attribute("name"), "/"}; - if(!directory::remove(location)) return (void)MessageDialog() - .setTitle("Error") - .setText("Failed to delete directory.") - .setAlignment(program) - .error(); - program.setPanelItem(home); //hide the system overview for the now-deleted system - refresh(); - } -} diff --git a/luna/panel-lists/system-manager.hpp b/luna/panel-lists/system-manager.hpp deleted file mode 100644 index 386924912f..0000000000 --- a/luna/panel-lists/system-manager.hpp +++ /dev/null @@ -1,21 +0,0 @@ -struct SystemManager : PanelList { - SystemManager(View*); - auto show() -> void override; - auto hide() -> void override; - auto refresh() -> void; - - auto onActivate() -> void; - auto onChange() -> void; - auto onContext() -> void; - - auto doCreate() -> void; - auto doRename() -> void; - auto doRemove() -> void; - - ListView listView{this, Size{~0, ~0}}; - PopupMenu listMenu; - MenuItem listCreate{&listMenu}; - MenuItem listLaunch{&listMenu}; - MenuItem listRename{&listMenu}; - MenuItem listRemove{&listMenu}; -}; diff --git a/luna/program/program.cpp b/luna/program/program.cpp deleted file mode 100644 index b95ec2e0b3..0000000000 --- a/luna/program/program.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "../luna.hpp" -#include "../panel-items/home.cpp" -#include "../panel-items/system-creation.cpp" -#include "../panel-items/system-overview.cpp" -#include "../panel-items/port-connector.cpp" -#include "../panel-items/peripheral-overview.cpp" -#include "../panel-items/input-mapper.cpp" -#include "../panel-items/setting-editor.cpp" -#include "../panel-items/video.cpp" -#include "../panel-items/audio.cpp" -#include "../panel-items/input.cpp" -#include "../panel-items/hotkeys.cpp" -#include "../panel-lists/settings-manager.cpp" -#include "../panel-lists/system-manager.cpp" -#include "../panel-lists/node-manager.cpp" -#include "../panel-lists/port-manager.cpp" -#include "../panel-lists/event-manager.cpp" - -namespace Instances { Instance program; } -Program& program = Instances::program(); -ActionMenu& actionMenu = program.actionMenu; -SystemMenu& systemMenu = program.systemMenu; -SettingsMenu& settingsMenu = program.settingsMenu; -ToolsMenu& toolsMenu = program.toolsMenu; -HelpMenu& helpMenu = program.helpMenu; -SettingsManager& settingsManager = program.settingsManager; -SystemManager& systemManager = program.systemManager; -NodeManager& nodeManager = program.nodeManager; -PortManager& portManager = program.portManager; -EventManager& eventManager = program.eventManager; -Home& home = program.home; -SystemCreation& systemCreation = program.systemCreation; -SystemOverview& systemOverview = program.systemOverview; -PortConnector& portConnector = program.portConnector; -PeripheralOverview& peripheralOverview = program.peripheralOverview; -InputMapper& inputMapper = program.inputMapper; -SettingEditor& settingEditor = program.settingEditor; -VideoSettings& videoSettings = program.videoSettings; -AudioSettings& audioSettings = program.audioSettings; -InputSettings& inputSettings = program.inputSettings; -HotkeySettings& hotkeySettings = program.hotkeySettings; - -Program::Program() { - viewport.setCollapsible().setFocusable(); - - statusHeight = Font().size(" ").height() + 8_sy; - layout.cell(statusLayout).setSize({~0, statusHeight}); - - statusLayout.setCollapsible().setVisible(settings.interface.showStatusBar); - statusMessage.setFont(Font().setBold()); - statusCaption.setFont(Font().setBold()).setAlignment(1.0); - - Color foreground{255, 255, 255}; - Color background{ 48, 48, 48}; - statusBefore.setForegroundColor(foreground).setBackgroundColor(background); - statusMessage.setForegroundColor(foreground).setBackgroundColor(background); - statusCaption.setForegroundColor(foreground).setBackgroundColor(background); - statusAfter.setForegroundColor(foreground).setBackgroundColor(background); - - panelGroup.onChange([&] { - if(auto item = panelGroup.selected()) { - if(auto list = item.attribute("panelList")) { - setPanelList(*list); - } - } - }); - - panelHeight = 7 + 250_sy; - verticalResizeGrip.setCollapsible().setVisible(settings.interface.showSystemPanels); - panelLayout.setCollapsible().setVisible(settings.interface.showSystemPanels); - panelLayout.setPadding({5_sx, 0_sy, 5_sx, 5_sy}); - - for(auto& cell : panelLayout.cells()) cell.setSpacing(0); - - verticalResizeGrip.onActivate([&] { - verticalResizeHeight = layout.cell(panelLayout).size().height(); - }).onResize([&](auto offset) { - float min = 128_sy, max = geometry().height() - 128_sy; - float height = verticalResizeHeight - offset; - height = height < min ? min : height > max ? max : height; - if(layout.cell(panelLayout).size().height() != height) { - layout.cell(panelLayout).setSize({~0, height}); - layout.resize(); - } - }); - - horizontalResizeGrip.onActivate([&] { - horizontalResizeWidth = panelLayout.cell(panelBlock).size().width(); - }).onResize([&](auto offset) { - float min = 128_sx, max = panelLayout.geometry().width() - 128_sx; - float width = horizontalResizeWidth + offset; - width = width < min ? min : width > max ? max : width; - if(panelLayout.cell(panelBlock).size().width() != width) { - panelLayout.cell(panelBlock).setSize({width, ~0}); - panelLayout.resize(); - } - }); - - onClose([&] { emulator.quit(); }); - - setOverviewMode(); - resize(); - - setTitle({"luna v", ares::Version}); - setVisible(); - - emulator.inputUpdate(); - videoSettings.eventChange(); - audioSettings.eventChange(); - inputSettings.eventChange(); -} - -auto Program::resize() -> void { - uint scale = max(2, min(4, settings.video.scale)); - uint width = 320_sx * scale; - uint height = 240_sx * scale; - if(settings.interface.showStatusBar) height += statusHeight; - if(settings.interface.showSystemPanels) height += panelHeight; - setGeometry(Alignment::Center, {width, height}); -} - -auto Program::setOverviewMode() -> void { - if(panelGroup.attribute("mode") == "overview") return; - panelGroup.setAttribute("mode", "overview"); - panelGroup.reset(); - panelGroup.append(ComboButtonItem().setText("Systems").setAttribute("panelList", &systemManager)); - panelGroup.append(ComboButtonItem().setText("Settings").setAttribute("panelList", &settingsManager)); - setPanelList(systemManager); - setPanelItem(home); - - systemMenu.setVisible(false); - toolsMenu.setVisible(false); - //todo: if test shouldn't be necessary ... works around a hiro/GTK bug ... - if(!actionMenu.visible()) actionMenu.setVisible(true); -} - -auto Program::setEmulatorMode() -> void { - if(panelGroup.attribute("mode") == "emulator") return; - panelGroup.setAttribute("mode", "emulator"); - panelGroup.reset(); - panelGroup.append(ComboButtonItem().setText(emulator.system.name).setAttribute("panelList", &nodeManager)); - panelGroup.append(ComboButtonItem().setText("Ports").setAttribute("panelList", &portManager)); - panelGroup.append(ComboButtonItem().setText("Events").setAttribute("panelList", &eventManager)); - panelGroup.append(ComboButtonItem().setText("Settings").setAttribute("panelList", &settingsManager)); - setPanelList(nodeManager); - setPanelItem(home); - - actionMenu.setVisible(false); - systemMenu.setVisible(true); - toolsMenu.setVisible(true); -} - -auto Program::setPanelList(PanelList& panelList) -> void { - if(activePanelList && activePanelList() == panelList) return; - if(activePanelList) activePanelList().hide(); - setPanelItem(home); - activePanelList = panelList; - activePanelList().show(); - panelBlock.resize(); - - //update the panel group selection as well - for(auto item : panelGroup.items()) { - if(item.attribute("panelList") == &panelList) { - item.setSelected(); - } - } -} - -auto Program::setPanelItem(PanelItem& panelItem) -> void { - if(activePanelItem && activePanelItem() == panelItem) return; - if(activePanelItem) activePanelItem().hide(); - activePanelItem = panelItem; - activePanelItem().show(); - panelLayout.resize(); - //todo: this works around a Windows rendering issue on the audio settings panel, but should not be needed: - Application::processEvents(); - panelLayout.resize(); -} - -auto Program::refreshPanelList() -> void { - if(activePanelList) activePanelList().refresh(); -} - -auto Program::showStatus() -> void { - if(statusLayout.visible()) return; - statusLayout.setVisible(true); - if(!maximized()) setSize({geometry().width(), geometry().height() + statusHeight}); - layout.resize(); - settingsMenu.showStatusBar.setChecked(true); -} - -auto Program::hideStatus() -> void { - if(!statusLayout.visible()) return; - statusLayout.setVisible(false); - if(!maximized()) setSize({geometry().width(), geometry().height() - statusHeight}); - layout.resize(); - settingsMenu.showStatusBar.setChecked(false); -} - -auto Program::showPanels() -> void { - if(panelLayout.visible()) return; - verticalResizeGrip.setVisible(true); - panelLayout.setVisible(true); - if(!maximized()) setSize({geometry().width(), geometry().height() + panelHeight}); - layout.resize(); - settingsMenu.showSystemPanels.setChecked(true); -} - -auto Program::hidePanels() -> void { - if(!panelLayout.visible()) return; - panelHeight = 7 + panelLayout.geometry().height(); - verticalResizeGrip.setVisible(false); - panelLayout.setVisible(false); - if(!maximized()) setSize({geometry().width(), geometry().height() - panelHeight}); - layout.resize(); - settingsMenu.showSystemPanels.setChecked(false); -} diff --git a/luna/program/program.hpp b/luna/program/program.hpp deleted file mode 100644 index ccbf2f36fc..0000000000 --- a/luna/program/program.hpp +++ /dev/null @@ -1,115 +0,0 @@ -struct PanelList : VerticalLayout { - using VerticalLayout::VerticalLayout; - virtual auto show() -> void = 0; - virtual auto hide() -> void = 0; - virtual auto refresh() -> void {} -}; - -struct PanelItem : VerticalLayout { - using VerticalLayout::VerticalLayout; - virtual auto show() -> void = 0; - virtual auto hide() -> void = 0; - virtual auto refresh() -> void {} -}; - -using View = HorizontalLayout; - -#include "../panel-items/home.hpp" -#include "../panel-items/system-creation.hpp" -#include "../panel-items/system-overview.hpp" -#include "../panel-items/port-connector.hpp" -#include "../panel-items/peripheral-overview.hpp" -#include "../panel-items/input-mapper.hpp" -#include "../panel-items/setting-editor.hpp" -#include "../panel-items/video.hpp" -#include "../panel-items/audio.hpp" -#include "../panel-items/input.hpp" -#include "../panel-items/hotkeys.hpp" -#include "../panel-lists/settings-manager.hpp" -#include "../panel-lists/system-manager.hpp" -#include "../panel-lists/node-manager.hpp" -#include "../panel-lists/port-manager.hpp" -#include "../panel-lists/event-manager.hpp" - -struct Program : Window { - Program(); - auto resize() -> void; - auto setOverviewMode() -> void; - auto setEmulatorMode() -> void; - auto setPanelList(PanelList&) -> void; - auto setPanelItem(PanelItem&) -> void; - auto refreshPanelList() -> void; - auto showStatus() -> void; - auto hideStatus() -> void; - auto showPanels() -> void; - auto hidePanels() -> void; - - MenuBar menuBar{this}; - ActionMenu actionMenu{&menuBar}; - SystemMenu systemMenu{&menuBar}; - SettingsMenu settingsMenu{&menuBar}; - ToolsMenu toolsMenu{&menuBar}; - HelpMenu helpMenu{&menuBar}; - - VerticalLayout layout{this}; - Viewport viewport{&layout, Size{~0, ~0}, 0}; - HorizontalLayout statusLayout{&layout, Size{~0, 0}, 0}; - Label statusBefore{&statusLayout, Size{8_sx, ~0}, 0}; - Label statusMessage{&statusLayout, Size{~0, ~0}, 0}; - Label statusCaption{&statusLayout, Size{100_sx, ~0}, 0}; - Label statusAfter{&statusLayout, Size{8_sx, ~0}, 0}; - VerticalResizeGrip verticalResizeGrip{&layout, Size{~0, 7}, 0}; - HorizontalLayout panelLayout{&layout, Size{~0, 250_sy}, 0}; - VerticalLayout panelBlock{&panelLayout, Size{200_sx, ~0}}; - ComboButton panelGroup{&panelBlock, Size{~0, 0}}; - HorizontalLayout panelLists{&panelBlock, Size{~0, ~0}}; - SettingsManager settingsManager{&panelLists}; - SystemManager systemManager{&panelLists}; - NodeManager nodeManager{&panelLists}; - PortManager portManager{&panelLists}; - EventManager eventManager{&panelLists}; - HorizontalResizeGrip horizontalResizeGrip{&panelLayout, Size{7, ~0}}; - Home home{&panelLayout}; - SystemCreation systemCreation{&panelLayout}; - SystemOverview systemOverview{&panelLayout}; - PortConnector portConnector{&panelLayout}; - PeripheralOverview peripheralOverview{&panelLayout}; - InputMapper inputMapper{&panelLayout}; - SettingEditor settingEditor{&panelLayout}; - VideoSettings videoSettings{&panelLayout}; - AudioSettings audioSettings{&panelLayout}; - InputSettings inputSettings{&panelLayout}; - HotkeySettings hotkeySettings{&panelLayout}; - -private: - maybe activePanelList; - maybe activePanelItem; - float verticalResizeHeight = 0; - float horizontalResizeWidth = 0; - float panelHeight = 0; - float statusHeight = 0; -}; - -namespace Instances { extern Instance program; } -extern Program& program; -extern ActionMenu& actionMenu; -extern SystemMenu& systemMenu; -extern SettingsMenu& settingsMenu; -extern ToolsMenu& toolsMenu; -extern HelpMenu& helpMenu; -extern SettingsManager& settingsManager; -extern SystemManager& systemManager; -extern NodeManager& nodeManager; -extern PortManager& portManager; -extern EventManager& eventManager; -extern Home& home; -extern SystemCreation& systemCreation; -extern SystemOverview& systemOverview; -extern PortConnector& portConnector; -extern PeripheralOverview& peripheralOverview; -extern InputMapper& inputMapper; -extern SettingEditor& settingEditor; -extern VideoSettings& videoSettings; -extern AudioSettings& audioSettings; -extern InputSettings& inputSettings; -extern HotkeySettings& hotkeySettings; diff --git a/luna/resource/GNUmakefile b/luna/resource/GNUmakefile deleted file mode 100644 index 8218cabbba..0000000000 --- a/luna/resource/GNUmakefile +++ /dev/null @@ -1,6 +0,0 @@ -all: - sourcery resource.bml resource.cpp resource.hpp - -clean: - rm resource.cpp - rm resource.hpp diff --git a/luna/resource/luna.Manifest b/luna/resource/luna.Manifest deleted file mode 100644 index 84a4e143cc..0000000000 --- a/luna/resource/luna.Manifest +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - true/pm - PerMonitorV2, PerMonitor - - - diff --git a/luna/resource/luna.desktop b/luna/resource/luna.desktop deleted file mode 100644 index 429abb56eb..0000000000 --- a/luna/resource/luna.desktop +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Name=luna -Comment=Emulator -Exec=luna -Icon=luna -Terminal=false -Type=Application -Categories=Game;Emulator; diff --git a/luna/resource/luna.ico b/luna/resource/luna.ico deleted file mode 100644 index 8fe551aa0d231a099462a4b81eb94658155f01a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26041 zcmeHv1z45I`uKOwp+mYv!bC(`K|(+T5s*+Mq!C3x5S8wOgaL?vii!v#rASD3h=70y z(jB67O6U2{Anx_<>aOnI-Fu(^^P6Xf`Od`qzVpt^TQe(ypb$KSk`e(WJ7S85AV&}c zVQ2sRI}X$*f;v9Fjo&*FM1u}=015Wb-Gd-&q6o4Z{03b?&F6YhAOI{u~n5{}`2=yLrBIyUwwxIv8LDv}0uy+b)w2|RAtb=W^4>cDz5gY^41}wC6 zXpF5+L*IhY`%gH7?g@~`afUsU>u}af@D1T<*S}wYeZf#P9DC^A6GX`Es;EXq%kZgp zJyR;#W%=^)Ss@C~vqIqashX|{Ljdn<7=VtU{jT1kQgRr{FG7?vU%e7?zjl~n z`z{h#2^0JVunz+`MFyRtzrcWVf&2hnP=L3ag*|Qr@m+M-e(>h~^>JVS5%&*4cI%yC zhcJGj1Iz>Pw1)MFA_Ex<8v`{L4=3eLxZ>YV^6{C7u!pY7=ZVe`Y#^~YzWdr zh#*B61i_*{X9Cd3hD8v`A_T#~+_RC3K?$=b$Y2Z(jD@?79b_qxq5N4-K=AyLocY}G zfBG*zhKPusV*5@`hW!TwV20nY4p5E%H&KoO=a^%+{uxUV?|=l^i1dB!#dcuPUjEO0%22Z+sOfO zeVu>}1An4`uD!Xw*ZQV$y3PH#V<`ngB0d3$oQ5WsSq>jnpx<{u6lVC%X?X53IB$ut z5A6GI{Q4F@0F4kfz~K*ZZQxudgJv%;vT56n-Qe8xLO93sDnAL@W5Z~8_#vT$D9mq< z@7&pl_}K)< zY(9ACD5T-{_yA=Tl#>uAv_J64Hz7ncbPQl!Uhh!XG5m~sou;27VZ)XI_NN|Pzwhk_ z$OGAk=M4ZjJw6#Zf=5D%0J*RS=yM-pS~_A3A<@s_{i-+6LGTx$paV7x?#XYRQAiim z7f@$WY}@f=G&SJG7RZmknwTXHBeZ;i2jIE*77t(@kOdP^Z-TS*1>Ijqya5S?0nQAN zwIV*ZlAwI}^DaU*rGv`THmFe=UEGy~zJNP_M(>e&XBw zhrIZf{QXZ80&FmZ^Vj?DU;5`J!1r(Z=Rb-6tMixm>+`p+e}Rtw>fHY)QLn>dmXJnh zc?E@m{2BbR_h9+i{?O2|{S&(7M~U2!-BA8M{33rL?tintKHIiG3i2oVefFh)(Lcb3 zfwB+G`-}Za{73fZPaykE*Dv~4{%Lv-oHK~00Q>vdSN8WW;g8>p{VNruOw4dN5jb-O zz< zq|7V~VBFv3fBrB@Kid)P8ys$u0*Aw*;K{_TfbhZs2s2EAFd57}z@8}ryex7xCfRVf9!Y=*AOziUpb8|oP<$X8 zf{a4g!C#PoS@i!woZ|Cb{_pR%H~^wl2qW;pxCk~;h=LfVB+T#|*1DiZ2XW?RiJ*tWK*mnX#iY!^48K7gj6pZUKENOHfMdWUsQ*h7L80;Rw*i0K zj@Q!WwM=;Y%*j`EINg?kb=_nHbkw&p)LXF6$&z?9ll5+rT{jW4^-o zc!Ec~uB+(i1%+()JA1Z*82g%j`^aZnfo}V?Pw~CqP!GcS!LcB2v9{02vyEOr2;MQ! zZQ%GG34f&?MNH2i1>!wLN@+za&>x3%e2>N-t%oomEC>_A2K!115c!{5i_f}@fQF05 z48*qwKsp;O<7gE&A8#0<=V;4k~VpJ^v%JRt54&fx5qyNn;D>8JYv zTOQ(&34b;Vae_Gz|HU~FKsZ2#EI=RWr|J1dtmj8yKwJ>##vI`F!kt)|0L~S z<_B>?+#7r8r_KW{uK+?sOLqwD#eR4<`32@bUBbNtX#nx3LmT(Cf4B~4{PpFc=K`_- zp4H#PngCyn-hYF zur{GyQc5dcg>-!3`MS*R1^x?&)q=J~$>2u=`y4#p?mcIf2W3! z;J1W>nvJ+UHSYzx*ZLj6CIDlAkG;4{%ODlRlEDj$zvTB}KulP4mzI7Cg!yOY0BsH4 z3%2Ee4(hM(7`{w~Yzr$wOiM2VV$d_EKg{63z1}pFn4~Xgr~Q$0^99cLN?@bGCRzv+ z!v5K_4bK6%%bWpn@h}-P%Wu$}EUibFB@cV3mo?yyK24vd6WH$xI)RI`pAx;lf%}aL zVh9_~;b+zX_JuYsh(lpd6jpx&EJDb2#v&cW;8!<`AA)>ezx4Z7$NxYbF*r}YDw#jG zm!Rzp;)iJf|G)b{pY0q*Zu3h`96Cnnpq&oLm;V5n-v+S(n{L-BgVb-u(tl4z3Ay?- z0jP{$+ePp^fcsBwpsTA%nKp}mYkz&4l0RPy&l|Ay#h_gJ(X#;cCiLR~R<3{JFXTT8 zwGYh05w!jN@uh!F8@*XV`UcbwKXMk<&oJ;sp+EhNm?Lzqz-zOAF2Q>?kocgEGXi@0 z_x25JgY-jx8pH%7NEkQ&n$Z8ap!qd|@BAhJIz0;78h^Bp{(%1Pfd6}|nWbbA%AFiW z&|ZT3`}fvhegA}icmMpognkG5#@#BvHnAg zCi73|*B>MMmtLgMkNds-^Vxp3dksc>(|-O1(tqcJ0s5j}_R6nIxOcwzFVM&OUrIkB zKY!GJ{BO*QSyJYA^%v9$>;C&bVcX|_;J^Pj=m$8zZ$E6rPhczu^!uUs$v-&`#2=+VNGaK=9Nc&%npZ{I++3??A{Spg;wlj=%eszCA__dGwcM{n#Rw9SY-uxZ)p$awjIF#Z~3o( zG&Sg?JAnTerJCF9QZv_?^XVYw0PnA5K>dH~{`!w-{?ZP4N&;guFunxdX8$j~ANWG+ z|CN7&1M824-~*-g1j`=qwg{FR89rKq-|*2AEQ>&Z4whJO;9v=Hf!tg8xdP`6euIZv z>*eG+UjPHw`2@&W=NkY6{sVc9@N>Bi5sm{1L9VMR%aN08hC-KI{;14}&teRP5J9U$ z_i~&Gg6z2>FLUUmL)%!Vqr=I@#iFT+H#>qW3a;+-^5Vuj(>FMc`I_F1D#H(MzJk4TfXHVfZ;$Wvl8_7$f&un)VxWBl1$;1bRk~hf~44$7B zcMNi-d3%uQa<|C9BkL}VG|^Ts%HRDnX(^h(#h&-la2ct!Uc+?`&z!Pawm?OCoG5y3 zTk3sI9-$05v1t@tXIWmF5l~+w&(3h5ei0_BHbac+W&%vl8C)kWvym4G^-L5cNa-ZFb57~i zp(#TIw=7`zn%tz5n(0B1=pVYXwopN${6Re^OzrKOXY>|P-6O7^9~I8B zVwzA@9&~XRylZdaAyclqkQy{*lp}Jx|1y1^NEhE3)f2)4Y!-YvuSHJ0E%1yU?KF_? zzga)}c27)V!PJS5LXp};RTgaRBHgo;`rA-ay5uYu1t&El^2Z)V8%%ilhZjmdHjt6I zxbSh!NY8b9?i_up?Xp?M=hOz&yzx9O>Z3SX)f9>MI?1G zdF=zUJDa0P*@sQ5i7{A$RB!HfG@~OQ3~#qAx1F!9Zut~)&d1L#y7r2i`reh9-MIVixALw`yb)|8T4B<F>ISmFKdZ1+!Z#)$`IT!l6iyPj8Z; z0h?xgACawK4Eo-&Lsy%5?w=lQ6WP_s;>{*`sv_QMY@ieW>eIvm!}~8U^#l~@yk7F& z1@=-0H*2G2A*)pEla)@*a+WaB7p?~OdOfxBbPKOG$^PY%x-SPs^N6jJy+K?~ z+nd5}k)m$>>d2Lc##>KgCV6}2;~vZO%Am26K0HMyA_U{)508W>GoR)g6t6=c)HzXQ z?cQ0MOPXS4VdJ;?;h}0n7Xv_J$Wer{t8TLv@eFcQ(Z3_bw(*VI)?%k8u{;jDV;^$h zZdE)>Uwj)If{{Grza`Cq8u1b?jnr5pCpfBfy(6bD^!}>nm6=12@&?Z-22A>x&@Nskvbw_GNh$=P+Gq-|%tPwsh}9tELu^i!z@mfMz(X0JAg^jzxc)-K$w zealGdvA3up|3%ELlQuCitB)V1qzmqfjdomm$yq_w;iw}@cZYnm!s0N1wYnSB?~n0!WjSb>QVJ`L9koacOlMXxdZFd1 zs(0ng$@g_w)}6PmVqa=@5V#Nx9*c=6k+bjWYHEyrrIap`dM&p<;qjoKaTXsk36ICQJeT2rR<2vWZ1x$tqob&WN9(!uPFj}-ZvdPj?azD|X>=sKdCRcwOlo#(Q z3>m&CT}V^(?c0qB`4^7m?z7Th7vFm=G}b;UE9$P^snQ7Q$8XVgXt^{uj}9fUnRaS4 z94^-JXkp2%$zYNcT{LYM>YeI(?o}LN{4$;Ml?>CV`~oEY4rPPj4M9Au%FB)f>@M#N z8!qbJ;(T?>+M;IkOmGF|Gg(;)1G|UItf%BG6Z%f|s1*rn7fOw9<3@UYN8|0w9xx|d z3KdYXdStD5E^`Ns*|S8w(~M#Q_dmufw+)c`;lK1y*DgFd&W@5=c;+AHCq1UpubDB? zwBN-3NC;!n8;UHg_9mlap|{IY)Hy~S34ESt2=kQIq*5y~NG+u7GvuW-BWnsjP+)H- zZEC7|PvefreS?Y_5v~JHqYqab+KUb@OzEPS2xtpN87Fs0xq3#gK4f!GRjR6t+98+h z@@_}YxmRr}o!*r)qnY!8fQ?D*H!Jxb207gK!5 zP(8~M28XARnd3zIDverp*%2tthdlT?~T$rAwKElW|@0Vg0PGj6a41BcXxT+DQYNL%l$f{idWp`9G8j}f78iO0pEK<%Uo|vNaH%M zE}=gr-Wk>h*2LO#)IIYT)ORSYDo49HUW7H#UA`N%<&ca6r9l!GlFoaYWb%5`?B!i0 z*q7negbIlM$~leXraRfUmnRB*t~ZOCaMv7)rk`d4@>DV&)kU~lT&+`hz9m~cfy;(J zY}4A}%Zu7OMFk$@U#Yb2p#eJ8ecop*b!|v;;`O^6fsi1|bMHSElF7wB%94Ge%_DJX zqCybqolwTmc-V<#5BRBwH*maU&LtC8kKJ_q_U)z@hb@n`vF^VS_|!JvWg7``Z=^l4 znK{8yGoiXW*7hvVz4C=+ame$^g`&RBqHp?tbzRL|pR z&;Epw9VjWhE2%}o2w+amej#mFyYba)TNCbED>5wi?r1o(s~RX3kJDSRrKgpaoRrqw z61c2))<}rdI-cyAh$HlT0QT-S)rSZx#%5s8FvUV0`myi*V+29%KGUsreGx)T#78V; z$87Kula9wV)H#F;<@O|6xurWtKvya2xmV>`5P-Dd`uVsJ8Ib>Vy;PFtqVNrX( z%Hev!;sG6Waj_FPCGpJ+*vhT<$j>FNYeDVQ(W<)jHWX&1`)j_q<)s zG;MFVbKe8lP>JRX<*qpU(N^M)*R+DPAAy_AIiJ;JNxr7~=GzE6I&c;B;KD%H`(SO& z7|!vq&_i1Ho-9vHX<)(Ju5C#jO4)S#VSSE(5*0Je%h6ELb_y#b$N7`fI%xdo$Z`R9 zLNjQdEegnK7iMZiQ8;|khKs9sbNI+wrJsI zlC%*(L{Y)@xsvvSm&oBbkvYQMJhL?*sBW!5xEvCObsOg~Kx2tcrqA)3o4+9k{Kz&@ z9x@E4K`w^oR)s)#VXMAvZAVg@?wBPu$v-9=4nHHA$I_8I@fa{GZVM_R@vS=sDSA_3 zHpkoE*M9->5LU-DjW(kUE4@gAm{l&HYX!%C@=}H6%Zj4`FW8iAV1-Ns$qRQXbCORA zPTVRv7yP!T_foRI)%&Obc6lWg0*p;JHl!>-Im6uyDa(!5U7r9NTk!#hG8~N1@VZLa zPSM#!4taZL`#U$F=aRYb7tzMakElF#S}EkRKMyHwFFblpSoXXglRcwAEfpe)y3mR` z1t&d+)KbzJ`8DJSjPre1@nXjsjqg^24O56ye&Wek>xog3gqe|GscY{7drY&$D&gKy z--6}Wn#d&e;GsXguXbc}IZ+Rh{cTRTj&?{ORT)VF*L!78!UH)dSHyT)@dRARMikIK z4$)0?mtr4vvT$P!*-N}5LGXDSpEp__848PJPEYg`n;o<(-ch7q&0Vexh>&4P<_;a} z;%@qAlEN!LvBjUiz0OX5`>Ny{C3+m(W?B zKXw!x%kie|+nd&+(-5yLuSZC6@lxLF*FD&KcpvuWTl=k6Wn^WY2W}qKH79hMG6{EW z&bCLj1!2ai+gbJ~s-^#n~%t<$bwk9{xpb&9Y!>>Me`P)ViEM_Lp;um$|9Se~Rf z4I+C*yd{j^mZlihkxGXLY7Fdn4CAtJE4?Y2n|G-R)9cK*ys{Vy%Y)(oiCV#)P#jWb2vo7rJO=SRq{(L|(<6*S`5hV4K{OH!@V2Tdx)Y*~h249= zvfCMPVKZ+k^G?)>t((8r&Lf zsq47>feAZ#&e}r@Th2P%7-4%h?`gr>73YFht1_?+))WZE$$-$P$vv;Jgd}i%P%5ZJ zgJY7mkEQ+X0sHQEvqx2L6||=It{nHINJApAm)lF5O;@j6qaWZ$!fvK?A8bmJ&0qGk zN<$Pp^fHpql8+y0UK4O&Y7(rj4y=sdG~* zkg(N>f2A5ieR?7OeUNB*NaF22bL4<;n@>dn;j;CG-D=mW-dV487Os4hq?mYO>z#Ju z#4r(ZPLH#k1;sA3wJWW}P8``U#O1}&K|X_@Wu|>q?*)GuV**#yogjg3V&v74t7Jlq zHglHu9?AJr67?zvwsftM6X+FJ)ljfS0eCiZ&yDN1E9D{_h%)_2pSAI+wd@S*1gwGi z((pB@8QR*-J*^ystQ6$rB(L?{6MY&<9P!oXN{kb4e*}aQsOq%89uv0ROiyFkab65( z9g*vk6iBr9pvP6@bfo_&$wj02t=gJL6=h@NpC(v~FG%()oJu4>mUAUIKJBq(%jcJ1 z+`q#JZ*9!ylQ$n?g%o2K`!dU!bt;3pt3>QlK3zGiS$SEJ6zP%C-+7o|r!BKsN;N_I z)83-h&3O{rl2>TcdpT&zGTQl)txjlyS*Q1La6P234%OL|^#b28seuqzU}p$|C{bfG z;TJDW2)v85Et>18F>PRTA835xnVxuy_dwu)DN4(uZ+%8_Xl2xyf!i3$&6{cG%DUwq zy-??&z84Th$)Lo5mq#drGzsJQV_uyR@G{rqG%ze|#=1n5c}I5C$#s(^;|!nnz4EJI zSt4h>mDXi^t@H{E#U5SjU z=?dkmr9FM%w3rKtPM6Tu#Fuu;CRT}OXO3#W?0n8D*xA<0RrxNcDWY8nJwfj&J zDoI{%VW7rb%!0xND^5Wf!hp9IuMX*7jazO)xzg09C*J05wePv&{DwmtA@m@?KDSaV zn654q7d&G#@7Lm=Q8IGtY{~miYeasS!8Q?-dh0@#eIR_d_`sEL%e>aXTVv*q<3xyU z(FN=qmRR0JOuWSXj`A}CA6hoKU$>b1d8?K8I(Wh&+s=bkOf#-w8X&|<&>>sywC1eNoOL&?TbRoacS)-eYS{7Ep-0hz zD^JF^fnLj_t+ROvNGZWs6@}obwW^lOz4_^_EN64L5L!bWhGa+QcXaNPQ&*S#?n!Xk zCX6KuCR5Xq$y5bla~8$W9sANt+T>UVMRZ3L76oF3o3}*Ng0a@=UD{akP*O8K0};ik z_9Q=+gK-A$Mca)i4Cyjh^ksZ0$@gLsQH$Lj+bG)F2u>?h9A|zyJ*it=UTE(AHk(HyynhOTg6&o zg)Te~nIyOLm~CnDvN`JC7L@H|(tS50TGLttA6p&gT+Q9V;uwM&mDGCq^yP5;5+Mjk z_1$a~-emKDy9G0Qb=zStk0)HixHPdi6Wm;*AfXT5h`+Yx8#dtlzBjbHzj`rStjf+F z(IVMn)*Hg5qB|=oz-Z&+Ull{a%paBRY7;@Tr_SHbdev*5T()zC1w}BYq?@@`WmZB) z5cZrnTS2iPr$=9V_-#rj3u0%;yh%6jgI4g`W96&kz7!lcAMlGa)vKp!vKsicYmho z_VOhw>1yjuhZ5Lbh|^CTTOhW|6U%5Q44XxWkvT{P4 z>N*2jYp;fcPE(%ESxNWgfyu=r|MrPAyPmBl>*bCRxfpCSzfz+Xm%SRzwsx+=LvEmA zM|i(h-Ur5}>C6>r`;dw2NHWWQwd*Q{7H%)=p3=0>ccxrEa=(JsrUkesI;}x0W%lHU zZ87B@+KnOE!(}(*``YK5a!#)e2k*S;yqj5A7*}lVxXggE=)ClxqmQndC+hsby#`}v zljxa2)^jTRACXu{SxVB6KF;xt5kv}+CWJGhX_~Fm(OK+NOTEk0fV-*ZlZ;0S1Aqap zf{)Ea#W#{nGiu8fuRG?m~)l|-aYKi#?_BpcZ$$hoicy=l)rs| z=p?2FaW54jJ?`MonngIMfGTf?4GWqr@Pb`l$pEu(%Hk|#+puIjzYB}Tc%$i$_HxvSA zI4mZPyxbn?!JwKnOQ|Y0mp8wZ?yTW1bT(?=VrTi&5nY14a}BoQOo%y_0#%?NGErAj zqa(3rnQDD~TRw z@Fw>vkMNTb==CPC4cUKq=XmgH`V4o@!RV;8o2(_0F*$8ylOlYb!Ohc01hXmcofp!% zc4MD_g(_EoUR?A3OBIs&^A94PlyeEOit5r|ec;o!=^nl=DJ|yerD>Z=B$6-&Wff`i zDH=6sbGutSzvONbgUZl8bFGn^m#3ZIDke?zg-%!FmM>nK@1E#Oz`bUXDtzTYb1L*g zG41=sEVUEbnxYd^iu#Xi~550oM$IlbPouVv~jv2+yh)`8V!2X-nJm#DKR(WeD0& z`HtGm zE!^f-WKdSfn$F<9$J>|bUD6_50gd5Smn(vsW_rxB*x~P9I}{rY6!DK zHbiJ`YDvOvK6Y%bL3IyrW*~B_0rW6zPn*xx7jC)r=q~lU45ntv z3n$bYrNWQn`i@=VE^<5B{N}y(Q_b>r6>F<^KC8#j;Ih&srP4kX&H7BM zc7pef#7gTY8er9?$0ub*>6J=y$>3i>HykcK9ZTVSareNAd)lMv z&`2Qd^7|~=u1g7+A6s*tKTgI!Y@KU&vm#uG(_ieu*u$V0-$hB-@`bR-@{-(>Ut-ex|M^N(1$OpdXSe=xB zDSjqCs#fh_ZmD`VUxDkO*A!=1F!iyu>C+h(o##XNOokce%nHNNg86!c31}&TXRTX+ zbUT07ZvJ6mOTF_KzNtSE>dv zj0VQ%ya9fE8fl7~l14lDb6&{JYZ*_lP90x$-W7G^2tie)oaEW`m*kn;#;I)+Nvw_0 z*4)m@f~Jd~!SWCyZ1J3JN2P;%+ZoTaqZ#t?NX%ha*2eSk!Lkl}t^kJSKmNCAcisREuS6USD9h z#V+fs#xI8gRJR*HsC7DODv@zEXPV(ms>xvw-%{e<_9iQyGsPToqgNHDq!Mv4lit_a z&ElqNt|^-xx6qYf36>99yjG;9W^6L(Rdc{D5`8kbknrM(D$&K4VH!T0nZvcTHRR5! zWBSTX1)lBll3V>WfB)_IRrgKL>vEKV_l(e8YeJXUifS!%k7QjqmJ)xKq*w56l4!+q z=faGEMFZcqgB9lm*Lcb`(MTL;Vy;IVkgCjgRpztJUP|vPzyDs_M`hv7qroR+`#YPT z+;>a7+eCp1`-rBv;#Ay!Fr(N}lXmM$P$LP2L_x9Jw5NhhAC0i&LYW|P&iS};;*VuyV+RgIUOq>_HmltYQJm*U6JtR%_IL;L`;3xYYvc*5)={e)FR*dK4#1|L` zZerc6w+c?^dbC=g4qVYrNvQA&ubL`FkY@pD#6(I8L}$l>o~D^`hrT7k1-d`G!LL@3 zTr(Fh`_ZiBv28w2zhVvYaE!o>%shXlW4Z8g!J%ow7-`)*;QF0y)h1!JpD>G!EpM@S z{t@axyRSB3cVR^GgZDw&yL7qKyuBx!7c@h)a_aaC2Mpr;&0KS8yALN*o;v>vCa2d zxT#VoURL9tTPooaMxh(9d4B#>!4l=<>1Ko(%cyqEqek-K>j*ai@!c-vcP(Y#WEtb9 z+xka5nhB7xHFkZFB!QRL;?^S+@i-$fP-Nb%I#4%!vl11z)?DD_{*?vha%b<9o2npw?Ax^)z?n`@3^wikMDi@lY+T`nqWK|9(PiU?egU`Q=5Um*1;el` ztIqM(q8nD9?ztV_OtsmHZ<}_Ens?)|0!tB&Pg|^HRM5DF9DSu;D-_b8u!n{(GVS@z zq=L7`WgqsvEZIRsG$8^mt7lpb0<8Ai@$}rh`xSzhFObB-sZ$5YcNB#goCxQS!p-V#w%YgvE`JJleaVKbt_lVxLlG@ z^;%@ubPmUmMaXt^^quY+EAqT(AkH$~=l0#ksl}AOV_8DpSuKCBH>+sK~9_)17tM!3m?i$zmCUMeJGOtb`0uWC~k*w9x~ zw0*%Wwfj^A9)jH;XDXf%lM#q>4O9%d`R>f?G^5@tDtA9zE_aO=iM5+ZkMvo3)Rdz? zPJI-G7_wYMXBAsyY?jb*BEwQ0F0fbA+gi|}nmTw&WWPlZ9FBhk}N@*_^!Y7zKg zpgCf>yU7Qi?yud6^vwSDKm#m!HbDNIk)`#3`OVQhxH9ZcM+Vx>Z>=J(7U?b4yqFc_veRIZ%IbWQC6#~8TT`& zSbY?(v3!zKW+A!C!-rvOOD|{E)+Q}#<&NVyv{y=d`RLkQhbkZ}9vo0Y%MR_=HE!7z zj!Y9GCxdYZ6GmdZ?`}b)Z1MY_2w6(SdWvM)^nySdH4QiE4Ya(x8B3v?P;kJS{j0?p z(H`Z74=?DSM%$uzGzjuAw)J+T2?AhKU4vZ zLtXpn?%6PTWFfJ&s2jTj0XjP@)3#SQV0JrySCnn%EA`#r$gt_RR1o@JPS)B&I!EFW zjv`G@4Cgf)(!(lNpw}>r9w-eipM%Rc90y7)o@)&?9^CZgxW16V$y1F*(8eAoY))~V zXId6t6YY`h(J+i{vYi39ZdoZjMb>dt803B5v6Y#w^9xgYokVxGcu72tDSIQvW-^_r znfkDK6!RR-ir!?ZCugt|)iZodYNyAbrQ|zN&f9VWv!}<$hVDs6$wqjCOPQ{Gtp%?I1fRp}Qq?_CwSs@uacm4jORp~G zKB99n!i_>wrST&-HS$0?Kzr-l-dh(WnNIHmS3{cv-j2vR#hNCJFy6Wu7T1%GbE^_# zV~OcsA(O!B_Bi$^xj1m>8|*+uEM8HaE@L~Kz>hS<6{kOG6PTZ~*>zK8t5ys{Zd9>_ zQEO#z-tuuFaPfCQvXQWbV1;gh?Q)+mcv>>gh+0A4Iq-7o!LFTNm-`y_xm|P??L2eh zc<`2rgXJsUR~LKwwkU_^N4Q(z7Z9wWTprsVTnz)`hHpMNBS3iVMR>zdLsTSltexRf z)XBCC;^v%35}de`bm4A}ex-^xUl<1%Gu9;1HfFlhIX;^ZqDI8G)9$x%pfJDj!c#xV zSQWS9!o#4l+av9n3x>BeRZD}ClqZKmvVo_+^gguf#)Bjr!L$1Y?S6{axNadmj!bd* z9GU1a-ZhhXKP_-8WwJ7O#)r(poBu#^I1_lmkOJPSsGpxcmA)(7^J*2(tZ{1`lk)`n zYI>qIdoa?Yw~B37P4L{r;4UaGelPH_wxEL)_2DIscbWEAx@-935-iUQbfsE!X}oG0 zi)~F#zcp+=9qqP{K?|ERWpAc8aaS6RwOazW-SS10JpA14jL&1OlJE%T6r-B=Pw56z zDLM_9hO?ZCvr4`drd9@?_5JI0UdBLU;XS511+MqU4#y0cgQs;?*YFb$<9i*Kimh5T zym;%;%-eSmM2Pacs2G{L0zEu4PAdHhE7Nr8cSGhk!=8Wm>cQaQ=q+zK3p=VWgm@0u z^U77%apgZaPf`B>(7Rqhg z{Xj6{-mzzosaVe1oRQ7Ye!QZ4Fyg@|P}L_-Hd$vx-34L@sJz`g2~V=J?$S8k0e2pa zx12G^9ejDrL-cuuVnPDnve^~{cBiWXmOrTgBSpPj!Lt=j8I zjjZVG-ji^OFt&y>PM3gKDsSvbwsUkdsW6fm; zE!YTRr!Tr~w%l$$+Ihoi{_arv?>_YW{0#KLl6xihK*c3qfA~)$Ao8-xGKtcLSN - - - - CFBundleIdentifier - dev.ares.luna - CFBundleDisplayName - luna - CFBundleExecutable - luna - CFBundleIconFile - luna.icns - NSHighResolutionCapable - - NSSupportsAutomaticGraphicsSwitching - - - diff --git a/luna/resource/luna.png b/luna/resource/luna.png deleted file mode 100644 index a12c79e5e9091abf22ec1f47e812cede5ba9009f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11155 zcmaKSWmr{Fv+zELl#r5=RumCwrAq`U={|IKcON7bknToGknTQ!fHV?^E|KnTxSRL> z_`dt&UY-ZmX0JVK&6+hm^F={U0vGEk761UaQj%gy0003WApj;iIA}W-nt}tW*?Zad z08kN$ePe(I{!eQpsU!;ko-Y9a9tZ$e;4AnB0JyLLz?MD$@Ff8NseM|bq5wF7ZYU!m z29Ds*<%cFeaCl@dsp$lc`v3Vouo4{xA26JyWW_Q5p^)PM#PV+8z5ww0vy|9-75ACl zc@KA$iA%)c{s4V!Z)?blz(8hH|MDMQ|o>2`P-{Tm&b*%J+PATtq1XAPt%pjhTsbhzeruXp z-o;aV-DeOHZComQ&I9$Vmff^Gz5T$5%r@a{Juxx+i`6>=9iQh-XCzfF*A}%quM9ia zL|?zAU^)HX;~(jdR;W+gECPj_f0bOCL_8P46tOSA`$yqN<6+wU@9}MEJ{-L&h3q82PX2UVk&scjwh>`~i%|=C?8!9FKq;-bSEo<-|M7YjP^0m_&Y$h=kPnaWo)rAqeg>foB zU@qq$BtGHYc*2wEo7|72DyYyU!|sFQ!PON$gm>W51DNW0IVoGuZF*eJ2M4E)63v3c zUGqjhE33Y_IeB%T>=)Jid4GU&2J?noGw52xOYQx0o)R`Ou_K??Wb8k_~recwbIX z1aiuFs=|{3vbJPwsG7ibQDrz6yE?^3ohL^@MsGwMfDDn|bvfs&u{zA3Zmn zC2es*8t=4D;e{#r_8-`d7!8PHL~5Z2`d=?HZC24x>~Ua!Rwxohl$5ns_GgLJ9FM7( zR$Vo!s3;E3M(S@tCr)u2q|9 z>$jw^IYS=HpS$I}XW@ZPesZ#%j_?uQ_~@8w?`oEwSJ{U%f|Z04E+WXlQ*s)%T%3zd zD`10pKpurUQs&lir5eV7H@WTN>84lMI5W_;$ctFi9n85&Gomv@IbdBnFU%HO7K6eM zf>{tsS)7GZAGQw!2XN&@%`qfa#+ zodA+D5p$I;69c|d7sg|VI~uK7*Xs9Xr$zq=5XDwROinrCoHV|)?VNcr7Tjdzyd=$K zMsirCXY=e@vf*}|cgbOC5!Ut!7G)rk9mJ>4ZjTbB;+&s<1UQPR_Y;ZcpuD zcNc%2IQ#b65Ty`IZs?B_z>dIEAPRAP015zsYLxUj*(fkCt)~x1l9fll68`8Cqd35k}S0&MJ=m64%4l5uVx+p>;PDW!KL%Z$2K;? z?=a&VrfitVeIlG8fvlP+IB0ytiO9UTxQUV$+fPkz?bK)m-h`$WxaHR8Cg^B(Wf5i% zL0zE|)xQ37vLG|PP#gcyuH`>P)ihj7F3fjnKFhUyxbQQuJ#kH~*zrIQ{;tN&(luN~C_^f8QTbM% z72g5}naR`Y<|=A#u8^b_&zr2*d&0}aS%cYkn_x?lQX!dJHem31EocSaIo2uCwT=|hAj%9=P zfqJ@#cNADVM8TdYj|%tTi-)tnU%+s%?YS+{3`T5(wM}YaHM?#-J;@pZ_nsW1Mmq&- z5Wle#Rm+za5KKRNl2G8|_yqUMpdbtz>QP}v@qVnJAawTCtFt#cE-|B(d+TBv z)d(x(2Zbo1w~nVZMg(eeYu1k+|M?j0f*C#`J>J~IeKCNGEOUdF-7aFDcv2Pa z^^t;>cl*@mA6?b~H!q?_#1fQ@FT!bKr`lrf<)*O#X(rBJ=*FM?;-Sq;jHe-^vV@Il_a)c#uT{8`s zVi(SbTtQb$p8I^NL7;@m znLYjS-DQV8>;)f3O3UXyrzIlLruv-+?^fMy3h)2^)5wt+gKzeCwGBt2AfsOVJB&rh zVZWCXSl*XIA@XLr7V1uiBm>&be!Sw^t9+XG$|+L1U^fB=&OVhT^x?SK8Soe>B5MbB~Pj*h?N z(z}vvdWZ<>=PCp@01~J19T&{Ub?-Kmt|Zw>hV*)we%$!wAZS$l4e8)rhO$?lvUk2E zOinL`g?L9iRF?J&F#=LR-hHN!22i6oufN{HyBLLLhb4bPkC_cVo*rGv;v#?a(MEjF z1thco-#4{B*GL=2abuL|{CWpzjE^`DJEAxEBdTGZ51Sa1i^xXs3f`-zMi&Qp%pA+( zcIc1zTS9JB!}uggMNng4O?{Pi|NHJ? zA7csy^n2LTMHK5t8trB(XwRQHQJ>a)%a zgzQ3dD>!Y=1s$K%QVJUyPn&4uP+wtib75d#h*rC?Xr6kPXa+nR*-%V%-Qsf#@7o&V zY+u)cwzqqNQc^rg3h$#!!Zr3-nR&p$l%m$6ok@Lt!dxf0*kw4Kyjsrj(_>Gp18LXi zkHA$_P(mPQ-dcZ&Hap6KdySW(F+8X7nt(d@l}189jCKZFK|^Kbn8Jyt$;!3y_{nmn z*GkI6L?4tbmAThs)kP>i@K{5L83)ipqi-Q8w(ARjV`1v~jC<*+ z?=_OXU+*8P!NIeIQdVtNK8{NpYvhn6pdjklN#&cxvjZBvjy(UfG}=$#x|O+P5}ZCo zL^jTHlTSeK+>c-nlSS`WvFO*$8x{v$Hj_xY>Z8A{C%OUD6oXOVrW1<1pK^w}{U ziUed{z<~-Ri~=!=#v7zYv8o{c3AdBow&5@>j-?iRT`ahbYQ?UT!es+r+f%ISZ4e1W z>zA|6SwRQf2RPm{j8`nDU>wEfB#m*Mm=5>dW6^`cF;!~LSS>9Fa6x)Bn96PHXA%MS zsZITf59_7hhRw`;tU|_Hlp>|Fakeszg`277n)b6nVii(CvPy^iPyob0uf-Yb?8=($ z0}UTu=OcF}A^LrR*fA9Hj%L%K*dI9b+H~|vMpn?sIX}D*%fhPgBe29elJ;blZ?p}6 zUbBo(JEXHJ4RU!O0RTFizBE90q+G3^1<>78to@$@K;gar?jiacS!#hH7_)fuNZbe7 z#y|h#3);DICbUbaQF#VIfYvmgM8kiBbj`L&hH{Hr>5#jTaf}cEd=T4dh~~qg&wvqp zVuSGUMvgtUe>Z`&aD%;9$`2EVfM-joN`ce<4sXfHcC1L~pXep?dj7r#-chB5vuo_v zVf(X?7``3Ze%gb%gy|N?_;8P|Kr}%&RteKzxd05FMu-n!bS$IvaFG)b(E7ONA&DId zGUln6;rg_lK{)_;9=0H;6tJ0|Ls3&2&VRb$+D?zq9c1p21CbD;DrZjJU0_D8npUz( z?NdguPdUtS>K^_S3dR!Hmm{F5XomV3zO z&yja|)j(iFv}a3W!EXcAqzsZoDXpNR+Ke*bN#1rsM8mI)q#otFt79LF^HJr}^TQx45snY) z>=(Q*Sz?lf{Sv0$9ZN_^c_~Mz%_spv(FefI;TA+=)umw)U0pmJ86Zj>-5H#VeA{bs zI@P7&3|&1^*dn1}vZ$DNxO{PQFPr0wgDxxUH6*YRdFzy=s6YVry&9&Q4C)n1I3+S) zVY|;gMVXWqm2^-1ft3ajXXoC-={obZ4#8z#zcuPd8&!>EG!X*OXTvF&WOXPTr;Rxd z-($SYb;#wN`fxE>=6W84T=G`}li$>m8pf%o4nlaABUt-@iR)VTfj8Qjr&8J@g+@4+ zQtyFoeb5veoTC5%@738{#g@45A>ki)wE(peJybdc89xljr}U&0s#jisH;tYJjm|m#BZnWDIr(eA zd#JZ2vRq7>f3)6x_G+EB>jv52P8vf12UHrvO;&1GKnc@7+13##C??f!sb+_G+!p_w zN-9LPPFF48C+C@Kx5`C9WSMx&b%0$pAnmVHTPA^GRO72C z7RFAkwU+s4Mafk{3^l|`ht7_Psmx92Eq5KIIuuU6fi=agcN2hQ{c6sB2V{*Yo{k=O z!hZeA42zGOm}&comeO*c&A$e*uJfUOtX;O-{|pB2of`F(Z549SD*mOANN9Lb{5OWL zC$Thc#S-8Nn+fi1#kh8|eWe`Q|HtWWzU^jJ7;pc(OHj3v(iSFQro-4n1)=4lTd3}I z6#(9GF$FTr;hvz?TfjneD%iWpN|lKc0lz+m;Bb*SpV=g3NJQXcF3UwvE!^Uw z>$LX|p7qOG#Yy@+XOHGawICjcYB9-4Yf`sa6QYbtx%DZCnHanrWr7(@o;gm ze(U&^22WslpsAj98kNSaf{3CkXwClK<#u^WLS!>%#eeUV)f8M7jrm5|j zG&rY&sY}X;7Zm>}aT2%?UX#`=MF*~%gcy!qyU?_-3z5B}H$c7H4L%BD1MGly_~lAn z4~14=%wj*UYvs}B59)o6GT6Y9nC^=Y=r3F-_$vp|XMZdsZl5*_JuAO?QnSoJ)LlEv zR&J-H4xYMZg@Gvz&nZ>waeW1ve%Uz2eXFZJm_*6lJ;}6p*ys3@Ez{?n&V&bk*RGAdMA2$Ldn@kwP#QJXQu03`Q4 zd;TwDjzCKtMm_zuNw{}bcTmpUsKg?6`Mv&+m0#h#R9CpvQPm5sJcQ)L__F5|`eX>u zVVaappK2{b5+4y?4=q}G=`do~?~4r$ zH(lC5cfu;e+qbX021%8#%ysDWs!dW?sAs=mL0KFoKea>vV0MgOUeOs78yidS_;Q>! z{hOl-N6$UsNYmHa5?_&iRpd*3Nlv_}$RpvROxQ zyVGu)T~g$m>=rc5?0aNIUHVWVv|K+1K1i6t^&EHeZC}zHOM1?X6?lu)M#JRm7;qtC zfHHo%@%F^T&wTXatR>UCdYEgRKHGgs#+s>FENq-a!+&Oe@(R>aoCWgIv4?m4Q;y3m zHPcikjZDB3eJ#>*53fJOeg}skSK&!Qj4ma+<(%biL8G4RGqe(2oWn$8&s>J47) zZRtyn0`5u5tPv2_sb&EN$4$kyVAJE3Ih-vErxGmG`^z_LfTvGfOQkCohL8IOr4&LY zKx;9d${I=i-6hXk6HFpfa8lWoZfi64C-b8q)B!O6kw}GGKDIf+tmoVrx~D_c8Q=qd zQ7DWDP*9tWW-ENgQw|YLT#S96E7Nk zu+VFed5+2>5wat!(ea~WtN027Oh~PKo8W%zoWeYXavJjNL!ke6rmg#G{zB9Hvk6X& zVASmhnEC(>82tX#cTK*vZ{Y8Dbptf8URx|DGRbS73UiP-2S@bh<595Z*7!JQ5xpLb zaCN#3JjWHEzoCMlpUG<1-St~^;-IJheAFN<)7rSC3)>p1oTma@^(h`}H~-U!y~~yh z*$cyC_?E)XYlCZ<0dHx0H5Pn3X|0mTLQuW{-egLA7(--?kl&d1QPA^4q@wlM-h9{m zJ%QSIr5=|ZQ{$E`JRMwP*Dr$nc(&)tPIS=e@%s{5??*LCpDr*^4&J{0E{~~j-_&z$ z7n9wZ-!H5xz9!dGI0Mz5!n#osAoxNG)p(;Oq=jsDHWBtKUq84ki82V5QvUI!_jz&a+Sbp1iA9NJ!OuvtxTK0jf@Z27_fe=E}F zUF`t7s4|s;vhwcxhO_o-&!4l6mfdWcquVK$*pK_gXg2QB8AO>58+ z?WECQhR+LLB0EjXA3xY<*D+O4h5^4WE^I~j2Tug7@1B#ZmW$(st|Y zo{>mKK4lck^g%Lt?Vi|9c01rn`VWJyErGfxQ%w@u>vQu}GkV;$^DqQ7FnhrRX{4p` ztT_k6^3lb1Vd~<{Lu&Tnli!2;)H3R6<%>7^O^E{Su@HSa1+0Ui5S9WKC$=E6Pc-*# zHyducR8>7>KkJ60$i7NPpDwkc8agSf7X0{RpX`R$7PcH_Hw@G$F?^5 zo3n8j0dl|+jt6PgP23;tM93ryF_!Fq`N{jG_R9y{LR=}oFDY*hIq9#<`8WL=5OgXF zt@;Q7L&@!$9@k;HBo4Z~NF*^1y@ca%g{P1It-VlD@isw5M)WC`zKwPDQD5ryyly>c zJ$$b9jJn@|nj$*M{JWrpC-lHgpNZ{HXPcgkJ&NVUDODD+h;_KbeqR?irRLF}Uw;e? z-Y>({*+!a=*6KjUREYJ}J^WYGTrqg0q_1Rdj(^Ry@X0%E{mk9n&OmOhvu$Ao|5&whlz`tPn#qpC3xm>5}G#l6O<5# zW9L2~2O}S1mt%UA2ib6rTNG&NOeiCj-+XJSvHi{Q*lS3pY=0&7c<}z(-r;<4f2HL9 zH!V>CIF z+B}M7ucoM}cR8Tvx_7aE9m1DNQPNB5`yO{X6m43-|2}8Tu$VnkeXn${d zQ^NOL>>ffu(0*h;90tb0C*-HX*Hia&3Hwqk5lkQL#$V23XToiM!uif@=j8y+8e0y`& zDWjGqX=hzs+p;lBq9SZf{u+0T>&C3H0&==1M397fvYtby_Yh&Y7+Ri_U{p0wDK^Kt*kJhQ*-02CA zGF;94+4bxj^IkmY==XBpyLX+&v-{{G-qJDa2Y8OZ9bJefXt%y!`v`jx?Ad^&Zd#$i z%ryDWq~+bc!e%3Lkc~BVB+Dt^yPV)B=QBc;3Lf~5hjSaEuPje>NXNZz7DVJ{5A&#t zG&(;7JdOZExPuJ-rtS!e__+_G4wngIW>y=*YeZn>P~;Z(v|VQZZs``xY*5!wkqM{G z$G6=&6r!uvd!hwRi0`uw2;EE{5rJN9O>tRWu1=RQlNj1(==g^&!vZ`n`&a8Xe$^Sr zsX3swYgw_O`69w$`RUHIHJm?EP;hUJtKpo#wgYD8zj>d!=*lAfW6C>nQo_urJ!L^x z+_*S*L|L$@OLdX0)n_B{kTE@$@YCI~VXeK_c_N$X7U`KqTPBpVMF*net?7yUXuh3=Ux(p-oHl<_-!5qdo z*-zHUa5lASna5>2bL@>366YF5`_zYuw_Y!EKYm2-?~@QVsp-J2V>YUq*)OA>$a7-$ zlH)YL#NXI2RP}1UEn^=@O3OD;6)5}JTzd1#VYeX|J?v83;{&sZhl!4$h_hHI0qtwP zsV9^_@ua13BEEfl`_V$jY?&8ZSg_9rkN@n#8{#e+=4nn27%CD`6KXL8Rhq1RGR!gg zPDXGcExk=9;9KD{Rfb>VG|J1om9v_137cgVuBz<&B&A6e+g)I;K}FZR61`~s(kaBK zV>43Wxlzi9r=+=1tx4lCsd1I*2mi3HN6WKFI~L=128o>znM0A%`}~8TFSHhghr^+A z7K+x|LR7I*F_)nTWo0ANjlf|Z*Bq!yY#WBXQa|5iN4i?@Q;JLtn3{x%D#}WaIY-gU zK#AL<^W-6`TffIYM;qn9=ougmMM67W_%tpSx9e>`RTi6IEpsN6@%8@nYO7tp)C-#t z?6u;&W9dpFP5y92rxp;jsd=qfi>Eq`|*pn@~5Uj-dI?-|NYx_@I zLwG*JDoc6;Gy4y_0H7$c`VpqAG^WXJ%#Ugd=F}m~`)I$Suk6aL<-=#i;;R-@*)A-%Gjd{OOqu>4MQ>s)fXhEY#L(|p-}o&n*R4TE7Uwq=#4 z{EdOV)Mio+3flL&P*2rp9A$4?*DH*$@Qz`{02CT7x*@x6Cd5Pp)B{;}F^i%XrKEb( z{r&f@)&X^B@k?W7PEuE%KzUY-;{sHyY});+?Pi7ZF5!2VmcWZ|@@)d$!+uR&Lf+|k z+L2Gs&ox`G@DB_p0SY*oa;X2XaN6%IUk-s+-aQF6;sf(nLth0>w1T0# zuV64;QyOc&e1uh0Z?Px+RmSqY4d1oV_!@_A`(!3W+nRJsoLWn98u8WcD9QK3Q-Y^< zY|mi%%0UyKT5Wh4jwtQKbSb`W4(`ZW<-PW8`kWvxR--T&TpbkbvD?(>4h z>XT``Xs1@DD~Y9Z*ktjK8+HJ0Y4`#N0EI-O>F~+e%REAo*RwN^hWVAX`v>^d4tBGZ zz(SUPPfe-1(}fiPyc0;mIbq^c?mSXuNamo6|BY$!2y+;8^g6-9-^E$h%9)NM6TAny? zf)A~3$~ttdD>Zekt7dI8p8}*e3_j)^drED4HYjJIfsBV*3mx;1!qviJ1Pg2RioIkw zca~+s=J-a&9$V8Kbv-79XHUs}R1ju4Oc*I6V%Sabjr$^q&*315i#o%^L)R)H&*Gz^o z*_#W(oqbl0Bk4bdX0PTyuf2BHiU+hQqep@ZZy86Wf7X(DwEfr6AoGI5J1eTaf zw%2f(83Eu#Lh!c~%EXI{b?nXt-=90;Q-sV~9x<7BhTolH?=kH;x86I3;cw``!_uJ( z=t^*1)d^D)AK$o`Q9iJK{y`y1I8Oq9P*vGzja1%lm3!FcdtWXcQ&U0B329vD2B}(?Dw#5L$3$AmW0y_MOW{ zq#%H|&UqP3q!AJ^V}FH8Nm)>}`EtcZ-nsp{JmFiC8~;~9@*~d$!lH)Wj1rd>!}Iif zk99dfoVVJBNbbC}0yZgM|JyQ1Jd?%*8QJ<^53Jju?l?8%HpxhraU~f$2#-~m^!nQ| zUqg{hvAdITTJ%2jJYS39Rzu&*PcOk}KTRGC97bmi7f;irfQ!;;#3Gy?0Bv@9oy#(J zct3iEZ3mKKEv|QgkaZ{X0lpr>cC}sp?4@`{tz{$V8QFJ z9_yXfKQ%Td1RsA_)aBAs(VRd$_}F_Gla)T_YWf98mlLq+R$s}2a4IA~ z0sgLhx;a^}x;WIC$Bd^86w1!;9^j`jJ+4!)N}Jq4`3a?lJ~r2p(0c({+WI8&!hgd? z_zxdroW%O6;ok0Ml4!1YRuEW}S-4vo$+NxDK@b%Jw51|Y#Kagx8Eys_I*SFX+p>s0#|(O8qxzAs)NCC{IXK`Te%FRI+^WgyknznF)auxkwn@*_$X^VRFN_ zU}@-S+-Y0aW~C} z5_Vv`u)XH{49EGI^UH7YbQ<}jO}XvX2Gf19&DV-tVBwEPcmiVz{f790#&LxkY%Mt_ zgWN#lc{&bLUcLx)Tp54sYwyK3Z>*#kOW7;fa}yMDxwJwlm)Vl#XNT5`eh2Z+b`iWy z2jRB9r5JNygjQsZZ;t2YP!zc8U*)RI)IOSQ%n)L{S0T>y^$72h`Bq^RX+$<$`edTc zkJzJVpNkL>c>d&_vpb&U*NOn$G9!h1dfT*^?zrvQx(od%b%m~&GP#4z#0D_ZzxtcH z@HM6E9=#}8Z#G;elqm{W@*ponW2l3sv)-AWhiiaUDbt$`<6s=?Aa zQMEeOta+Ik5Yo?bYBXI)?zImMsVQ}$jRlr;ZsD^EB>|5~{Wt{#lA=GrINe1EKU^{V zsdM|hILuyHVq?6%P-VTK_6xaNFkM~~wPksn=lhma1KxP(W}&m6APR-MUV+taDFi+X zJM%2r&jPzLRP-~M+{t%`+OY&Op6lkBRGNi$zL20!Fc4l%aP4caCKY>lx>4309jq*!4MM*~Z#FqBRknob3skp21dxhIBMK24Z^ zS7d*61>%!ZhhDfwPspFrdh57s;;qP$SHbbN@)+s}CQ$E>cI9szfBWE z-c%S&HaX~Nk(GU(!mGJuqvwCOfu>yf^)avaI3G)zyaW3<6vWE<7DP|r^3d`$HvCT!Oq0S3qHIM{*3WI0Br1x ZElfTBcK{Vbz9tX=kP?>@D;3rM{9l$?H8TJJ diff --git a/luna/resource/luna.rc b/luna/resource/luna.rc deleted file mode 100644 index 9fc5a37309..0000000000 --- a/luna/resource/luna.rc +++ /dev/null @@ -1,2 +0,0 @@ -1 24 "luna.Manifest" -2 ICON DISCARDABLE "luna.ico" diff --git a/luna/resource/resource.bml b/luna/resource/resource.bml deleted file mode 100644 index 4c33619813..0000000000 --- a/luna/resource/resource.bml +++ /dev/null @@ -1 +0,0 @@ -namespace name=Resource diff --git a/luna/resource/resource.cpp b/luna/resource/resource.cpp deleted file mode 100644 index a8b5415842..0000000000 --- a/luna/resource/resource.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "resource.hpp" - -namespace Resource { -} diff --git a/luna/resource/resource.hpp b/luna/resource/resource.hpp deleted file mode 100644 index 77c1762024..0000000000 --- a/luna/resource/resource.hpp +++ /dev/null @@ -1,2 +0,0 @@ -namespace Resource { -} diff --git a/luna/settings/settings.cpp b/luna/settings/settings.cpp deleted file mode 100644 index c80ed36a2c..0000000000 --- a/luna/settings/settings.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "../luna.hpp" -Settings settings; - -auto Settings::load() -> void { - if(auto document = file::read({Path::userSettings(), "luna/settings.bml"})) { - properties(0, BML::unserialize(document)); - } -} - -auto Settings::save() -> void { - Markup::Node document; - properties(1, document); - directory::create({Path::userSettings(), "luna/"}); - file::write({Path::userSettings(), "luna/settings.bml"}, BML::serialize(document)); -} - -auto Settings::properties(bool mode, Markup::Node document) -> void { - #define s(name) \ - if(mode == 0 && document[string{#name}.trimRight(".identifier", 1L).transform(".", "/")]) { \ - document[string{#name}.trimRight(".identifier", 1L).transform(".", "/")].value(name); \ - } \ - if(mode == 1) { \ - document(string{#name}.trimRight(".identifier", 1L).transform(".", "/")).setValue(name); \ - } - s(video.driver) - s(video.monitor) - s(video.format) - s(video.exclusive) - s(video.blocking) - s(video.flush) - s(video.luminance) - s(video.saturation) - s(video.gamma) - s(video.output) - s(video.aspectCorrection) - s(video.scale) - s(video.shader) - s(audio.driver) - s(audio.device) - s(audio.frequency) - s(audio.latency) - s(audio.exclusive) - s(audio.blocking) - s(audio.dynamic) - s(audio.skew) - s(audio.volume) - s(audio.balance) - s(audio.mute) - s(input.driver) - s(input.unfocused) - s(interface.showStatusBar) - s(interface.showSystemPanels) - s(interface.advancedMode) - s(hotkeys.toggleStatus.identifier) - s(hotkeys.togglePanels.identifier) - s(hotkeys.toggleFullscreen.identifier) - s(hotkeys.toggleMouseCapture.identifier) - s(hotkeys.fastForward.identifier) - s(hotkeys.saveState.identifier) - s(hotkeys.loadState.identifier) - s(hotkeys.incrementStateSlot.identifier) - s(hotkeys.decrementStateSlot.identifier) - s(hotkeys.pauseEmulation.identifier) - s(hotkeys.exportMemory.identifier) - s(hotkeys.quitEmulator.identifier) - #undef s -} diff --git a/luna/settings/settings.hpp b/luna/settings/settings.hpp deleted file mode 100644 index c2d6de10f2..0000000000 --- a/luna/settings/settings.hpp +++ /dev/null @@ -1,48 +0,0 @@ -struct Settings { - auto load() -> void; - auto save() -> void; - auto properties(bool mode, Markup::Node document) -> void; - - struct { - string driver = Video::safestDriver(); - string monitor = "Primary"; - string format = "ARGB24"; - bool exclusive = false; - bool blocking = false; - bool flush = false; - double luminance = 1.0; - double saturation = 1.0; - double gamma = 1.0; - string output = "Center"; - bool aspectCorrection = true; - uint scale = 2; - string shader = "Blur"; - } video; - - struct { - string driver = Audio::safestDriver(); - string device = "Default"; - uint frequency = 48000; - uint latency = 0; - bool exclusive = false; - bool blocking = true; - bool dynamic = false; - int skew = 0; - double volume = 1.0; - double balance = 0.0; - bool mute = false; - } audio; - - struct { - string driver = Input::safestDriver(); - string unfocused = "Block"; - } input; - - struct { - bool showStatusBar = true; - bool showSystemPanels = true; - bool advancedMode = false; - } interface; -}; - -extern Settings settings; diff --git a/mia/cartridge/colecovision.cpp b/mia/cartridge/colecovision.cpp index 8e3bdb2c87..b493a0c7d1 100644 --- a/mia/cartridge/colecovision.cpp +++ b/mia/cartridge/colecovision.cpp @@ -16,6 +16,7 @@ auto ColecoVision::heuristics(vector& data, string location) -> string { s += "game\n"; s +={" name: ", Media::name(location), "\n"}; s +={" label: ", Media::name(location), "\n"}; + s += " region: NTSC, PAL\n"; //database required to detect region s += " board\n"; s += " memory\n"; s += " type: ROM\n"; diff --git a/mia/cartridge/famicom.cpp b/mia/cartridge/famicom.cpp index 0e55f6f97a..96bffe7674 100644 --- a/mia/cartridge/famicom.cpp +++ b/mia/cartridge/famicom.cpp @@ -80,6 +80,7 @@ auto Famicom::heuristicsINES(vector& data, string location) -> string { s +={" sha256: ", digest, "\n"}; s +={" name: ", Media::name(location), "\n"}; s +={" label: ", Media::name(location), "\n"}; + s += " region: NTSC-J, NTSC-U, PAL\n"; //database required to detect region //Family BASIC (Japan) if(digest == "c8c0b6c21bdda7503bab7592aea0f945a0259c18504bb241aafb1eabe65846f3") { @@ -404,9 +405,10 @@ auto Famicom::heuristicsUNIF(vector& data, string location) -> string { string s; s += "game\n"; - s +={" name: ", Media::name(location), "\n"}; - s +={" label: ", Media::name(location), "\n"}; - s +={" board: ", board, "\n"}; + s +={" name: ", Media::name(location), "\n"}; + s +={" label: ", Media::name(location), "\n"}; + s +={" region: ", region, "\n"}; + s +={" board: ", board, "\n"}; if(mirroring) { s +={" mirror mode=", mirroring, "\n"}; } diff --git a/mia/cartridge/master-system.cpp b/mia/cartridge/master-system.cpp index 1e0e79d778..42556bbaab 100644 --- a/mia/cartridge/master-system.cpp +++ b/mia/cartridge/master-system.cpp @@ -14,8 +14,9 @@ auto MasterSystem::export(string location) -> vector { auto MasterSystem::heuristics(vector& data, string location) -> string { string s; s += "game\n"; - s +={" name: ", Media::name(location), "\n"}; - s +={" label: ", Media::name(location), "\n"}; + s +={" name: ", Media::name(location), "\n"}; + s +={" label: ", Media::name(location), "\n"}; + s += " region: NTSC-J, NTSC-U, PAL\n"; //database required to detect region s += " board\n"; s += " memory\n"; s += " type: ROM\n"; diff --git a/mia/cartridge/msx.cpp b/mia/cartridge/msx.cpp index d4e84409d8..47fce3d5d2 100644 --- a/mia/cartridge/msx.cpp +++ b/mia/cartridge/msx.cpp @@ -14,8 +14,9 @@ auto MSX::export(string location) -> vector { auto MSX::heuristics(vector& data, string location) -> string { string s; s += "game\n"; - s +={" name: ", Media::name(location), "\n"}; - s +={" label: ", Media::name(location), "\n"}; + s +={" name: ", Media::name(location), "\n"}; + s +={" label: ", Media::name(location), "\n"}; + s += " region: NTSC\n"; //database required to detect region s += " board\n"; s += " memory\n"; s += " type: ROM\n"; diff --git a/mia/cartridge/sg-1000.cpp b/mia/cartridge/sg-1000.cpp index d1a48ac20b..29d8ec4638 100644 --- a/mia/cartridge/sg-1000.cpp +++ b/mia/cartridge/sg-1000.cpp @@ -16,6 +16,7 @@ auto SG1000::heuristics(vector& data, string location) -> string { s += "game\n"; s +={" name: ", Media::name(location), "\n"}; s +={" label: ", Media::name(location), "\n"}; + s += " region: NTSC, PAL\n"; //database required to detect region s += " board\n"; s += " memory\n"; s += " type: ROM\n"; diff --git a/mia/program/program.cpp b/mia/program/program.cpp index a2a4cd5427..071ec34121 100644 --- a/mia/program/program.cpp +++ b/mia/program/program.cpp @@ -34,6 +34,7 @@ ProgramWindow::ProgramWindow() { .setLogo(logo) .setDescription("mia — a game analyzer and converter") .setVersion(ares::Version) + .setCopyright(ares::Copyright) .setLicense(ares::License, ares::LicenseURI) .setWebsite(ares::Website, ares::WebsiteURI) .setAlignment(*this) diff --git a/nall/GNUmakefile b/nall/GNUmakefile index 95833fd8f7..6a01d184eb 100644 --- a/nall/GNUmakefile +++ b/nall/GNUmakefile @@ -62,7 +62,7 @@ flags.deps = -MMD -MP -MF $(@:.o=.d) ifeq ($(compiler),) ifeq ($(platform),windows) compiler := g++ - compiler.cpp = $(compiler) -x c++ -std=gnu++17 + compiler.cpp = $(compiler) -x c++ -std=gnu++17 -fno-operator-names flags.cpp = -x c++ -std=gnu++17 -fno-operator-names else ifeq ($(platform),macos) compiler := clang++ @@ -107,7 +107,7 @@ endif # clang settings ifeq ($(findstring clang++,$(compiler)),clang++) - flags += -fno-strict-aliasing -fwrapv -Wno-everything + flags += -fno-strict-aliasing -fwrapv # gcc settings else ifeq ($(findstring g++,$(compiler)),g++) flags += -fno-strict-aliasing -fwrapv -Wno-trigraphs diff --git a/nall/adaptive-array.hpp b/nall/adaptive-array.hpp index 9ca84e7c6c..b1de354568 100644 --- a/nall/adaptive-array.hpp +++ b/nall/adaptive-array.hpp @@ -7,17 +7,17 @@ namespace nall { -template +template struct adaptive_array { - auto capacity() const -> uint { return Capacity; } - auto size() const -> uint { return _size; } + auto capacity() const -> u32 { return Capacity; } + auto size() const -> u32 { return _size; } auto reset() -> void { - for(uint n : range(_size)) _pool.t[n].~T(); + for(u32 n : range(_size)) _pool.t[n].~T(); _size = 0; } - auto operator[](uint index) -> T& { + auto operator[](u32 index) -> T& { #ifdef DEBUG struct out_of_bounds {}; if(index >= Capacity) throw out_of_bounds{}; @@ -25,7 +25,7 @@ struct adaptive_array { return _pool.t[index]; } - auto operator[](uint index) const -> const T& { + auto operator[](u32 index) const -> const T& { #ifdef DEBUG struct out_of_bounds {}; if(index >= Capacity) throw out_of_bounds{}; @@ -58,7 +58,7 @@ struct adaptive_array { ~U() {} T t[Capacity]; } _pool; - uint _size = 0; + u32 _size = 0; }; } diff --git a/nall/arguments.hpp b/nall/arguments.hpp index 6fb706d13a..7ecb536bff 100644 --- a/nall/arguments.hpp +++ b/nall/arguments.hpp @@ -12,10 +12,10 @@ struct Arguments { Arguments(vector arguments); explicit operator bool() const { return (bool)arguments; } - auto size() const -> uint { return arguments.size(); } + auto size() const -> u32 { return arguments.size(); } - auto operator[](uint index) -> string& { return arguments[index]; } - auto operator[](uint index) const -> const string& { return arguments[index]; } + auto operator[](u32 index) -> string& { return arguments[index]; } + auto operator[](u32 index) const -> const string& { return arguments[index]; } auto programPath() const -> string; auto programName() const -> string; @@ -67,7 +67,7 @@ inline Arguments::Arguments(int argc, char** argv) { #if defined(PLATFORM_WINDOWS) utf8_arguments(argc, argv); #endif - for(uint index : range(argc)) arguments.append(argv[index]); + for(u32 index : range(argc)) arguments.append(argv[index]); construct(); } @@ -89,7 +89,7 @@ inline auto Arguments::programLocation() const -> string { } inline auto Arguments::find(string_view name) const -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name)) { return true; } @@ -98,7 +98,7 @@ inline auto Arguments::find(string_view name) const -> bool { } inline auto Arguments::find(string_view name, bool& argument) const -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name) && arguments.size() >= index && (arguments[index + 1] == "true" || arguments[index + 1] == "false")) { argument = arguments[index + 1] == "true"; @@ -109,7 +109,7 @@ inline auto Arguments::find(string_view name, bool& argument) const -> bool { } inline auto Arguments::find(string_view name, string& argument) const -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name) && arguments.size() >= index) { argument = arguments[index + 1]; return true; @@ -126,7 +126,7 @@ inline auto Arguments::take() -> string { } inline auto Arguments::take(string_view name) -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name)) { arguments.remove(index); return true; @@ -136,7 +136,7 @@ inline auto Arguments::take(string_view name) -> bool { } inline auto Arguments::take(string_view name, bool& argument) -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name) && arguments.size() > index + 1 && (arguments[index + 1] == "true" || arguments[index + 1] == "false")) { arguments.remove(index); @@ -148,7 +148,7 @@ inline auto Arguments::take(string_view name, bool& argument) -> bool { } inline auto Arguments::take(string_view name, string& argument) -> bool { - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { if(arguments[index].match(name) && arguments.size() > index + 1) { arguments.remove(index); argument = arguments.take(index); diff --git a/nall/arithmetic.hpp b/nall/arithmetic.hpp index 388370f158..a82488665c 100644 --- a/nall/arithmetic.hpp +++ b/nall/arithmetic.hpp @@ -11,13 +11,13 @@ #include namespace nall { - template struct ArithmeticNatural; - template<> struct ArithmeticNatural< 8> { using type = uint8_t; }; - template<> struct ArithmeticNatural< 16> { using type = uint16_t; }; - template<> struct ArithmeticNatural< 32> { using type = uint32_t; }; - template<> struct ArithmeticNatural< 64> { using type = uint64_t; }; + template struct ArithmeticNatural; + template<> struct ArithmeticNatural< 8> { using type = u8; }; + template<> struct ArithmeticNatural< 16> { using type = u16; }; + template<> struct ArithmeticNatural< 32> { using type = u32; }; + template<> struct ArithmeticNatural< 64> { using type = u64; }; #if INTMAX_BITS >= 128 - template<> struct ArithmeticNatural<128> { using type = uint128_t; }; + template<> struct ArithmeticNatural<128> { using type = u128; }; #endif } @@ -85,5 +85,5 @@ namespace nall { //however, they still allow more bits than expressed ... //some sort of wrapper needs to be devised to ensure these sizes are masked and wrap appropriately - using uint192_t = uint256_t; + using u192 = u256; } diff --git a/nall/arithmetic/barrett.hpp b/nall/arithmetic/barrett.hpp index 7774b027a4..2e183370ff 100644 --- a/nall/arithmetic/barrett.hpp +++ b/nall/arithmetic/barrett.hpp @@ -2,7 +2,7 @@ namespace nall { -template struct BarrettReduction { +template struct BarrettReduction { using type = typename ArithmeticNatural<1 * Bits>::type; using pair = typename ArithmeticNatural<2 * Bits>::type; @@ -21,7 +21,7 @@ template struct BarrettReduction { const pair factor; }; -template auto operator%(T value, const BarrettReduction& modulo) { +template auto operator%(T value, const BarrettReduction& modulo) { return modulo(value); } diff --git a/nall/arithmetic/natural.hpp b/nall/arithmetic/natural.hpp index fcc902b8df..a6cc44ae27 100644 --- a/nall/arithmetic/natural.hpp +++ b/nall/arithmetic/natural.hpp @@ -1,4 +1,4 @@ -#define ConcatenateType(Size) uint##Size##_t +#define ConcatenateType(Size) u##Size #define DeclareType(Size) ConcatenateType(Size) #define Pair DeclareType(PairBits) @@ -28,8 +28,8 @@ struct Pair { auto operator++() -> Pair& { lo++; hi += lo == 0; return *this; } auto operator--() -> Pair& { hi -= lo == 0; lo--; return *this; } - auto operator++(int) -> Pair { Pair r = *this; lo++; hi += lo == 0; return r; } - auto operator--(int) -> Pair { Pair r = *this; hi -= lo == 0; lo--; return r; } + auto operator++(s32) -> Pair { Pair r = *this; lo++; hi += lo == 0; return r; } + auto operator--(s32) -> Pair { Pair r = *this; hi -= lo == 0; lo--; return r; } auto operator* (const Pair& rhs) const -> Pair { return mul(*this, rhs); } auto operator/ (const Pair& rhs) const -> Pair { Pair q, r; div(*this, rhs, q, r); return q; } @@ -83,7 +83,7 @@ struct Pair { friend auto upper(const Pair&) -> Type; friend auto lower(const Pair&) -> Type; - friend auto bits(Pair) -> uint; + friend auto bits(Pair) -> u32; friend auto square(const Pair&) -> Pair; friend auto square(const Pair&, Pair&, Pair&) -> void; friend auto mul(const Pair&, const Pair&) -> Pair; @@ -153,13 +153,13 @@ template alwaysinline auto _get(const Pair& lhs, T& rhs) -> enable_i alwaysinline auto upper(const Pair& value) -> Type { return value.hi; } alwaysinline auto lower(const Pair& value) -> Type { return value.lo; } -alwaysinline auto bits(Pair value) -> uint { +alwaysinline auto bits(Pair value) -> u32 { if(value.hi) { - uint bits = TypeBits; + u32 bits = TypeBits; while(value.hi) value.hi >>= 1, bits++; return bits; } else { - uint bits = 0; + u32 bits = 0; while(value.lo) value.lo >>= 1, bits++; return bits; } @@ -252,7 +252,7 @@ alwaysinline auto div(const Pair& lhs, const Pair& rhs, Pair& quotient, Pair& re template alwaysinline auto shl(const Pair& lhs, const T& rhs) -> Pair { if(!rhs) return lhs; - auto shift = (uint)rhs; + auto shift = (u32)rhs; if(shift < TypeBits) { return {lhs.hi << shift | lhs.lo >> (TypeBits - shift), lhs.lo << shift}; } else { @@ -262,7 +262,7 @@ template alwaysinline auto shl(const Pair& lhs, const T& rhs) -> Pai template alwaysinline auto shr(const Pair& lhs, const T& rhs) -> Pair { if(!rhs) return lhs; - auto shift = (uint)rhs; + auto shift = (u32)rhs; if(shift < TypeBits) { return {lhs.hi >> shift, lhs.hi << (TypeBits - shift) | lhs.lo >> shift}; } else { @@ -323,13 +323,13 @@ template<> struct stringify { } while(source); _size = p - _output; *p = 0; - for(int x = _size - 1, y = 0; x >= 0 && y < _size; x--, y++) _data[x] = _output[y]; + for(s32 x = _size - 1, y = 0; x >= 0 && y < _size; x--, y++) _data[x] = _output[y]; } auto data() const -> const char* { return _data; } - auto size() const -> uint { return _size; } + auto size() const -> u32 { return _size; } char _data[1 + sizeof(Pair) * 3]; - uint _size; + u32 _size; }; } diff --git a/nall/arithmetic/unsigned.hpp b/nall/arithmetic/unsigned.hpp index 5ed7ecd66d..78a508907f 100644 --- a/nall/arithmetic/unsigned.hpp +++ b/nall/arithmetic/unsigned.hpp @@ -34,8 +34,8 @@ inline auto ror(T lhs, U rhs, enable_if_t::value>* = 0) -> T { } #if INTMAX_BITS >= 128 -inline auto operator"" _u128(const char* s) -> uint128_t { - uint128_t p = 0; +inline auto operator"" _u128(const char* s) -> u128 { + u128 p = 0; if(s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) { s += 2; while(*s) { diff --git a/nall/array-span.hpp b/nall/array-span.hpp index 4590e42e19..71dec2123b 100644 --- a/nall/array-span.hpp +++ b/nall/array-span.hpp @@ -18,23 +18,23 @@ template struct array_span : array_view { super::_size = 0; } - array_span(void* data, uint64_t size) { + array_span(void* data, u64 size) { super::_data = (T*)data; - super::_size = (int)size; + super::_size = (s32)size; } operator T*() { return (T*)super::operator const T*(); } - auto operator[](uint index) -> T& { return (T&)super::operator[](index); } + auto operator[](u32 index) -> T& { return (T&)super::operator[](index); } template auto data() -> U* { return (U*)super::_data; } template auto data() const -> const U* { return (const U*)super::_data; } - auto begin() -> iterator { return {(T*)super::_data, (uint)0}; } - auto end() -> iterator { return {(T*)super::_data, (uint)super::_size}; } + auto begin() -> iterator { return {(T*)super::_data, (u32)0}; } + auto end() -> iterator { return {(T*)super::_data, (u32)super::_size}; } - auto rbegin() -> reverse_iterator { return {(T*)super::_data, (uint)super::_size - 1}; } - auto rend() -> reverse_iterator { return {(T*)super::_data, (uint)-1}; } + auto rbegin() -> reverse_iterator { return {(T*)super::_data, (u32)super::_size - 1}; } + auto rend() -> reverse_iterator { return {(T*)super::_data, (u32)-1}; } auto write(T value) -> void { operator[](0) = value; @@ -42,7 +42,7 @@ template struct array_span : array_view { super::_size--; } - auto span(uint offset, uint length) const -> type { + auto span(u32 offset, u32 length) const -> type { #ifdef DEBUG struct out_of_bounds {}; if(offset + length >= super::_size) throw out_of_bounds{}; @@ -50,30 +50,30 @@ template struct array_span : array_view { return {super::_data + offset, length}; } - //array_span specializations - template auto writel(U value, uint size) -> void; - template auto writem(U value, uint size) -> void; - template auto writevn(U value, uint size) -> void; - template auto writevi(U value, uint size) -> void; + //array_span specializations + template auto writel(U value, u32 size) -> void; + template auto writem(U value, u32 size) -> void; + template auto writevn(U value, u32 size) -> void; + template auto writevi(U value, u32 size) -> void; }; -//array_span +//array_span -template<> inline auto array_span::write(uint8_t value) -> void { +template<> inline auto array_span::write(u8 value) -> void { operator[](0) = value; _data++; _size--; } -template<> template inline auto array_span::writel(U value, uint size) -> void { - for(uint byte : range(size)) write(value >> byte * 8); +template<> template inline auto array_span::writel(U value, u32 size) -> void { + for(u32 byte : range(size)) write(value >> byte * 8); } -template<> template inline auto array_span::writem(U value, uint size) -> void { - for(uint byte : reverse(range(size))) write(value >> byte * 8); +template<> template inline auto array_span::writem(U value, u32 size) -> void { + for(u32 byte : reverse(range(size))) write(value >> byte * 8); } -template<> template inline auto array_span::writevn(U value, uint size) -> void { +template<> template inline auto array_span::writevn(U value, u32 size) -> void { while(true) { auto byte = value & 0x7f; value >>= 7; @@ -83,7 +83,7 @@ template<> template inline auto array_span::writevn(U value } } -template<> template inline auto array_span::writevi(U value, uint size) -> void { +template<> template inline auto array_span::writevi(U value, u32 size) -> void { bool negate = value < 0; if(negate) value = ~value; value = value << 1 | negate; diff --git a/nall/array-view.hpp b/nall/array-view.hpp index 06e689943b..2be439c7b1 100644 --- a/nall/array-view.hpp +++ b/nall/array-view.hpp @@ -19,9 +19,9 @@ template struct array_view { _size = 0; } - array_view(const void* data, uint64_t size) { + array_view(const void* data, u64 size) { _data = (const T*)data; - _size = (int)size; + _size = (s32)size; } explicit operator bool() const { return _data && _size > 0; } @@ -37,13 +37,13 @@ template struct array_view { auto operator++() -> type& { _data++; _size--; return *this; } auto operator--() -> type& { _data--; _size++; return *this; } - auto operator++(int) -> type { auto copy = *this; ++(*this); return copy; } - auto operator--(int) -> type { auto copy = *this; --(*this); return copy; } + auto operator++(s32) -> type { auto copy = *this; ++(*this); return copy; } + auto operator--(s32) -> type { auto copy = *this; --(*this); return copy; } - auto operator-=(int distance) -> type& { _data -= distance; _size += distance; return *this; } - auto operator+=(int distance) -> type& { _data += distance; _size -= distance; return *this; } + auto operator-=(s32 distance) -> type& { _data -= distance; _size += distance; return *this; } + auto operator+=(s32 distance) -> type& { _data += distance; _size -= distance; return *this; } - auto operator[](uint index) const -> const T& { + auto operator[](u32 index) const -> const T& { #ifdef DEBUG struct out_of_bounds {}; if(index >= _size) throw out_of_bounds{}; @@ -51,19 +51,19 @@ template struct array_view { return _data[index]; } - auto operator()(uint index, const T& fallback = {}) const -> T { + auto operator()(u32 index, const T& fallback = {}) const -> T { if(index >= _size) return fallback; return _data[index]; } template auto data() const -> const U* { return (const U*)_data; } - template auto size() const -> uint64_t { return _size * sizeof(T) / sizeof(U); } + template auto size() const -> u64 { return _size * sizeof(T) / sizeof(U); } - auto begin() const -> iterator_const { return {_data, (uint)0}; } - auto end() const -> iterator_const { return {_data, (uint)_size}; } + auto begin() const -> iterator_const { return {_data, (u32)0}; } + auto end() const -> iterator_const { return {_data, (u32)_size}; } - auto rbegin() const -> reverse_iterator_const { return {_data, (uint)_size - 1}; } - auto rend() const -> reverse_iterator_const { return {_data, (uint)-1}; } + auto rbegin() const -> reverse_iterator_const { return {_data, (u32)_size - 1}; } + auto rend() const -> reverse_iterator_const { return {_data, (u32)-1}; } auto read() -> T { auto value = operator[](0); @@ -72,7 +72,7 @@ template struct array_view { return value; } - auto view(uint offset, uint length) const -> type { + auto view(u32 offset, u32 length) const -> type { #ifdef DEBUG struct out_of_bounds {}; if(offset + length >= _size) throw out_of_bounds{}; @@ -80,43 +80,43 @@ template struct array_view { return {_data + offset, length}; } - //array_view specializations - template auto readl(U& value, uint size) -> U; - template auto readm(U& value, uint size) -> U; - template auto readvn(U& value, uint size) -> U; - template auto readvi(U& value, uint size) -> U; + //array_view specializations + template auto readl(U& value, u32 size) -> U; + template auto readm(U& value, u32 size) -> U; + template auto readvn(U& value, u32 size) -> U; + template auto readvi(U& value, u32 size) -> U; - template auto readl(U& value, uint offset, uint size) -> U { return view(offset, size).readl(value, size); } + template auto readl(U& value, u32 offset, u32 size) -> U { return view(offset, size).readl(value, size); } - template auto readl(uint size) -> U { U value; return readl(value, size); } - template auto readm(uint size) -> U { U value; return readm(value, size); } - template auto readvn(uint size) -> U { U value; return readvn(value, size); } - template auto readvi(uint size) -> U { U value; return readvi(value, size); } + template auto readl(u32 size) -> U { U value; return readl(value, size); } + template auto readm(u32 size) -> U { U value; return readm(value, size); } + template auto readvn(u32 size) -> U { U value; return readvn(value, size); } + template auto readvi(u32 size) -> U { U value; return readvi(value, size); } - template auto readl(uint offset, uint size) -> U { U value; return readl(value, offset, size); } + template auto readl(u32 offset, u32 size) -> U { U value; return readl(value, offset, size); } protected: const T* _data; - int _size; + s32 _size; }; -//array_view +//array_view -template<> template inline auto array_view::readl(U& value, uint size) -> U { +template<> template inline auto array_view::readl(U& value, u32 size) -> U { value = 0; - for(uint byte : range(size)) value |= (U)read() << byte * 8; + for(u32 byte : range(size)) value |= (U)read() << byte * 8; return value; } -template<> template inline auto array_view::readm(U& value, uint size) -> U { +template<> template inline auto array_view::readm(U& value, u32 size) -> U { value = 0; - for(uint byte : reverse(range(size))) value |= (U)read() << byte * 8; + for(u32 byte : reverse(range(size))) value |= (U)read() << byte * 8; return value; } -template<> template inline auto array_view::readvn(U& value, uint size) -> U { +template<> template inline auto array_view::readvn(U& value, u32 size) -> U { value = 0; - uint shift = 1; + u32 shift = 1; while(true) { auto byte = read(); value += (byte & 0x7f) * shift; @@ -127,7 +127,7 @@ template<> template inline auto array_view::readvn(U& value return value; } -template<> template inline auto array_view::readvi(U& value, uint size) -> U { +template<> template inline auto array_view::readvi(U& value, u32 size) -> U { value = readvn(); bool negate = value & 1; value >>= 1; diff --git a/nall/array.hpp b/nall/array.hpp index 3c9953d33a..86f0d31cc4 100644 --- a/nall/array.hpp +++ b/nall/array.hpp @@ -9,12 +9,12 @@ namespace nall { template struct array; -//usage: int x[256] => array x -template struct array { +//usage: s32 x[256] => array x +template struct array { array() = default; array(const initializer_list& source) { - uint index = 0; + u32 index = 0; for(auto& value : source) { operator[](index++) = value; } @@ -28,7 +28,7 @@ template struct array { return {data(), size()}; } - alwaysinline auto operator[](uint index) -> T& { + alwaysinline auto operator[](u32 index) -> T& { #ifdef DEBUG struct out_of_bounds {}; if(index >= Size) throw out_of_bounds{}; @@ -36,7 +36,7 @@ template struct array { return values[index]; } - alwaysinline auto operator[](uint index) const -> const T& { + alwaysinline auto operator[](u32 index) const -> const T& { #ifdef DEBUG struct out_of_bounds {}; if(index >= Size) throw out_of_bounds{}; @@ -44,7 +44,7 @@ template struct array { return values[index]; } - alwaysinline auto operator()(uint index, const T& fallback = {}) const -> const T& { + alwaysinline auto operator()(u32 index, const T& fallback = {}) const -> const T& { if(index >= Size) return fallback; return values[index]; } @@ -56,7 +56,7 @@ template struct array { auto data() -> T* { return values; } auto data() const -> const T* { return values; } - auto size() const -> uint { return Size; } + auto size() const -> u32 { return Size; } auto begin() -> T* { return &values[0]; } auto end() -> T* { return &values[Size]; } @@ -68,7 +68,7 @@ template struct array { T values[Size]; }; -template inline auto from_array(uint index) -> T { +template inline auto from_array(u32 index) -> T { static const array table{p...}; struct out_of_bounds {}; #if defined(DEBUG) @@ -77,8 +77,8 @@ template inline auto from_array(uint index) -> T { return table[index]; } -template inline auto from_array(uint index) -> int64_t { - static const array table{p...}; +template inline auto from_array(u32 index) -> s64 { + static const array table{p...}; struct out_of_bounds {}; #if defined(DEBUG) if(index >= sizeof...(p)) throw out_of_bounds{}; diff --git a/nall/atoi.hpp b/nall/atoi.hpp index d6fba252cf..e617fe0f76 100644 --- a/nall/atoi.hpp +++ b/nall/atoi.hpp @@ -4,7 +4,7 @@ namespace nall { -constexpr inline auto toBinary_(const char* s, uintmax sum = 0) -> uintmax { +constexpr inline auto toBinary_(const char* s, u64 sum = 0) -> u64 { return ( *s == '0' || *s == '1' ? toBinary_(s + 1, (sum << 1) | *s - '0') : *s == '\'' ? toBinary_(s + 1, sum) : @@ -12,7 +12,7 @@ constexpr inline auto toBinary_(const char* s, uintmax sum = 0) -> uintmax { ); } -constexpr inline auto toOctal_(const char* s, uintmax sum = 0) -> uintmax { +constexpr inline auto toOctal_(const char* s, u64 sum = 0) -> u64 { return ( *s >= '0' && *s <= '7' ? toOctal_(s + 1, (sum << 3) | *s - '0') : *s == '\'' ? toOctal_(s + 1, sum) : @@ -20,7 +20,7 @@ constexpr inline auto toOctal_(const char* s, uintmax sum = 0) -> uintmax { ); } -constexpr inline auto toDecimal_(const char* s, uintmax sum = 0) -> uintmax { +constexpr inline auto toDecimal_(const char* s, u64 sum = 0) -> u64 { return ( *s >= '0' && *s <= '9' ? toDecimal_(s + 1, (sum * 10) + *s - '0') : *s == '\'' ? toDecimal_(s + 1, sum) : @@ -28,7 +28,7 @@ constexpr inline auto toDecimal_(const char* s, uintmax sum = 0) -> uintmax { ); } -constexpr inline auto toHex_(const char* s, uintmax sum = 0) -> uintmax { +constexpr inline auto toHex_(const char* s, u64 sum = 0) -> u64 { return ( *s >= 'A' && *s <= 'F' ? toHex_(s + 1, (sum << 4) | *s - 'A' + 10) : *s >= 'a' && *s <= 'f' ? toHex_(s + 1, (sum << 4) | *s - 'a' + 10) : @@ -40,21 +40,21 @@ constexpr inline auto toHex_(const char* s, uintmax sum = 0) -> uintmax { // -constexpr inline auto toBinary(const char* s) -> uintmax { +constexpr inline auto toBinary(const char* s) -> u64 { return ( *s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? toBinary_(s + 2) : *s == '%' ? toBinary_(s + 1) : toBinary_(s) ); } -constexpr inline auto toOctal(const char* s) -> uintmax { +constexpr inline auto toOctal(const char* s) -> u64 { return ( *s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? toOctal_(s + 2) : toOctal_(s) ); } -constexpr inline auto toHex(const char* s) -> uintmax { +constexpr inline auto toHex(const char* s) -> u64 { return ( *s == '0' && (*(s + 1) == 'X' || *(s + 1) == 'x') ? toHex_(s + 2) : *s == '$' ? toHex_(s + 1) : toHex_(s) @@ -63,7 +63,7 @@ constexpr inline auto toHex(const char* s) -> uintmax { // -constexpr inline auto toNatural(const char* s) -> uintmax { +constexpr inline auto toNatural(const char* s) -> u64 { return ( *s == '0' && (*(s + 1) == 'B' || *(s + 1) == 'b') ? toBinary_(s + 2) : *s == '0' && (*(s + 1) == 'O' || *(s + 1) == 'o') ? toOctal_(s + 2) : @@ -72,7 +72,7 @@ constexpr inline auto toNatural(const char* s) -> uintmax { ); } -constexpr inline auto toInteger(const char* s) -> intmax { +constexpr inline auto toInteger(const char* s) -> s64 { return ( *s == '+' ? +toNatural(s + 1) : *s == '-' ? -toNatural(s + 1) : toNatural(s) ); @@ -80,7 +80,7 @@ constexpr inline auto toInteger(const char* s) -> intmax { // -inline auto toReal(const char* s) -> double { +inline auto toReal(const char* s) -> f64 { return atof(s); } diff --git a/nall/beat/archive/container.hpp b/nall/beat/archive/container.hpp deleted file mode 100644 index bdfce1da88..0000000000 --- a/nall/beat/archive/container.hpp +++ /dev/null @@ -1,200 +0,0 @@ -#pragma once - -#include - -namespace nall::Beat::Archive { - -struct Container { - Container(array_view = {}); - ~Container(); - - auto isCompressed() const -> bool { return (bool)compression.type; } - auto isSigned() const -> bool { return (bool)signature.type; } - auto isEncrypted() const -> bool { return (bool)encryption.type; } - - auto compressLZSA() -> void; - auto signEd25519(uint256_t privateKey) -> void; - auto encryptXChaCha20(uint256_t privateKey, uint192_t nonce = 0) -> void; - - auto validate() -> bool; - auto decryptXChaCha20(uint256_t privateKey) -> bool; - auto verifyEd25519(uint256_t publicKey) -> bool; - auto decompressLZSA() -> bool; - - auto append(string name, string location) -> shared_pointer; - auto appendPath(string name) -> shared_pointer; - auto appendFile(string name, array_view memory) -> shared_pointer; - auto remove(string name) -> bool; - auto find(string name) -> shared_pointer; - auto sort() -> void; - - auto begin() { return nodes.begin(); } - auto end() { return nodes.end(); } - - auto begin() const { return nodes.begin(); } - auto end() const { return nodes.end(); } - - auto rbegin() { return nodes.rbegin(); } - auto rend() { return nodes.rend(); } - - auto rbegin() const { return nodes.rbegin(); } - auto rend() const { return nodes.rend(); } - - vector> nodes; - vector memory; - string metadata; - - struct Compression { - string type; - } compression; - - struct Signature { - string type; - uint256_t privateKey = 0; - uint256_t publicKey = 0; - uint512_t value = 0; - } signature; - - struct Encryption { - string type; - uint256_t privateKey = 0; - uint192_t nonce = 0; - } encryption; -}; - -Container::Container(array_view memory) { - this->memory.resize(memory.size()); - nall::memory::copy(this->memory.data(), memory.data(), memory.size()); -} - -Container::~Container() { - metadata = {}; - signature = {}; - encryption = {}; -} - -// - -auto Container::compressLZSA() -> void { - compression.type = "lzsa"; -} - -auto Container::signEd25519(uint256_t privateKey) -> void { - signature.type = "ed25519"; - signature.privateKey = privateKey; -} - -auto Container::encryptXChaCha20(uint256_t privateKey, uint192_t nonce) -> void { - if(!nonce) { - CSPRNG::XChaCha20 csprng; - nonce = csprng.random(); - } - - encryption.type = "xchacha20"; - encryption.privateKey = privateKey; - encryption.nonce = nonce; -} - -// - -auto Container::validate() -> bool { - array_view memory = this->memory; - if(memory.size() < 44) return false; //8 (metadata size) + 32 (SHA256) + 4 (signature) - - if(memory[memory.size() - 4] != 'B') return false; - if(memory[memory.size() - 3] != 'P') return false; - if(memory[memory.size() - 2] != 'A') return false; - if(memory[memory.size() - 1] != '1') return false; - - auto sha256 = memory.readl(memory.size() - 36, 32); - if(Hash::SHA256({memory.data(), memory.size() - 36}).value() != sha256) return false; - - auto size = memory.readl(memory.size() - 44, 8); - - if(size & 1ull << 63) { - size -= 1ull << 63; - metadata = memory.view(memory.size() - 44 - size, size); - uint64_t offset = memory.size() - 44 - size; - for(auto& byte : metadata) byte ^= offset++; - } else { - metadata = memory.view(memory.size() - 44 - size, size); - } - - auto document = BML::unserialize(metadata); - - if(auto node = document["archive/encryption"]) { - if(node.text() == "xchacha20") { - encryption.type = node.text(); - encryption.nonce = Decode::Base<57, uint192_t>(node["nonce"].text()); - } - } - - if(auto node = document["archive/signature"]) { - if(node.text() == "ed25519") { - signature.type = node.text(); - signature.publicKey = Decode::Base<57, uint256_t>(node["publicKey"].text()); - signature.value = Decode::Base<57, uint512_t>(node["value"].text()); - } - } - - if(auto node = document["archive/compression"]) { - compression.type = node.text(); - } - - return true; -} - -auto Container::decryptXChaCha20(uint256_t privateKey) -> bool { - encryption.privateKey = privateKey; - Cipher::XChaCha20 xchacha20{encryption.privateKey, encryption.nonce}; - auto size = memory.readl(memory.size() - 44, 8); - memory = xchacha20.decrypt(memory.view(0, memory.size() - 44 - size)); - return true; -} - -auto Container::verifyEd25519(uint256_t publicKey) -> bool { - EllipticCurve::Ed25519 ed25519; - auto size = memory.readl(memory.size() - 44, 8); - return ed25519.verify(memory.view(0, memory.size() - 44 - size), signature.value, publicKey); -} - -auto Container::decompressLZSA() -> bool { - memory = Decode::LZSA(memory); - return (bool)memory; -} - -// - -auto Container::append(string name, string location) -> shared_pointer { - for(auto& node : nodes) if(node->name == name) return {}; - if(auto node = Node::create(name, location)) return nodes.append(node), node; - return {}; -} - -auto Container::appendPath(string name) -> shared_pointer { - for(auto& node : nodes) if(node->name == name) return {}; - if(auto node = Node::createPath(name)) return nodes.append(node), node; - return {}; -} - -auto Container::appendFile(string name, array_view memory) -> shared_pointer { - for(auto& node : nodes) if(node->name == name) return {}; - if(auto node = Node::createFile(name, memory)) return nodes.append(node), node; - return {}; -} - -auto Container::remove(string name) -> bool { - if(auto offset = nodes.find([&](auto& node) { return node->name == name; })) return nodes.remove(*offset), true; - return false; -} - -auto Container::find(string name) -> shared_pointer { - if(auto offset = nodes.find([&](auto& node) { return node->name == name; })) return nodes[*offset]; - return {}; -} - -auto Container::sort() -> void { - nodes.sort([&](auto& lhs, auto& rhs) { return string::icompare(lhs->name, rhs->name) < 0; }); -} - -} diff --git a/nall/beat/archive/create.hpp b/nall/beat/archive/create.hpp deleted file mode 100644 index 7014e48905..0000000000 --- a/nall/beat/archive/create.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#include -#include - -namespace nall::Beat::Archive { - -auto create(Container& container, string name) -> vector { - auto& metadata = container.metadata; - metadata = {}; - metadata.append("archive: ", Location::file(name), "\n"); - - vector memory; - - container.sort(); - for(auto& node : container.nodes) { - if(node->isFile()) { - node->offset = memory.size(); - memory.append(node->memory); - } - metadata.append(node->metadata()); - } - - metadata.append(" size: ", memory.size(), "\n"); - - if(container.compression.type == "lzsa") { - memory = Encode::LZSA(memory); - metadata.append(" compression: lzsa\n"); - metadata.append(" size: ", memory.size(), "\n"); - } - - if(container.signature.type == "ed25519") { - EllipticCurve::Ed25519 ed25519; - container.signature.publicKey = ed25519.publicKey(container.signature.privateKey); - container.signature.value = ed25519.sign(memory, container.signature.privateKey); - - metadata.append(" signature: ed25519\n"); - metadata.append(" publicKey: ", Encode::Base<57>(container.signature.publicKey), "\n"); - metadata.append(" value: ", Encode::Base<57>(container.signature.value), "\n"); - } - - for(auto& byte : metadata) memory.append(byte); - memory.appendl((uint64_t)metadata.size(), 8); - - auto sha256 = Hash::SHA256(memory).value(); - memory.appendl((uint256_t)sha256, 32); - - memory.append('B'); - memory.append('P'); - memory.append('A'); - memory.append('1'); - - if(container.encryption.type == "xchacha20") { - Cipher::XChaCha20 xchacha20{container.encryption.privateKey, container.encryption.nonce}; - memory = xchacha20.encrypt(memory); - - metadata = {}; - metadata.append("archive\n"); - metadata.append(" encryption: xchacha20\n"); - metadata.append(" nonce: ", Encode::Base<57>(container.encryption.nonce), "\n"); - - if(container.signature.type == "ed25519") { - EllipticCurve::Ed25519 ed25519; - container.signature.value = ed25519.sign(memory, container.signature.privateKey); - - metadata.append(" signature: ed25519\n"); - //metadata.append(" publicKey: ", Encode::Base<57>(container.signature.publicKey), "\n"); - metadata.append(" value: ", Encode::Base<57>(container.signature.value), "\n"); - } - - for(auto& byte : metadata) memory.append(byte ^ memory.size()); - memory.appendl((uint64_t)metadata.size() | 1ull << 63, 8); - - auto sha256 = Hash::SHA256(memory).value(); - memory.appendl((uint256_t)sha256, 32); - - memory.append('B'); - memory.append('P'); - memory.append('A'); - memory.append('1'); - } - - return memory; -} - -} diff --git a/nall/beat/archive/extract.hpp b/nall/beat/archive/extract.hpp deleted file mode 100644 index 41e4889139..0000000000 --- a/nall/beat/archive/extract.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include - -namespace nall::Beat::Archive { - -auto extract(Container& container) -> bool { - function extract = [&](auto metadata) { - if(metadata.name() != "path" && metadata.name() != "file") return; - shared_pointer node = new Node; - if(node->unserialize(container.memory, metadata)) { - container.nodes.append(node); - } - if(metadata.name() != "path") return; - for(auto node : metadata) extract(node); - }; - - container.nodes.reset(); - auto document = BML::unserialize(container.metadata); - for(auto node : document["archive"]) extract(node); - container.sort(); - - return true; -} - -} diff --git a/nall/beat/archive/node.hpp b/nall/beat/archive/node.hpp deleted file mode 100644 index a8821ff717..0000000000 --- a/nall/beat/archive/node.hpp +++ /dev/null @@ -1,332 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nall::Beat::Archive { - -struct Node { - static auto create(string name, string location) -> shared_pointer; - static auto createPath(string name) -> shared_pointer; - static auto createFile(string name, array_view memory) -> shared_pointer; - - explicit operator bool() const { return (bool)name; } - auto isPath() const -> bool { return name.endsWith("/"); } - auto isFile() const -> bool { return !name.endsWith("/"); } - auto isCompressed() const -> bool { return (bool)compression.type; } - - auto metadata(bool indented = true) const -> string; - auto compressLZSA() -> bool; - - auto unserialize(array_view container, Markup::Node metadata) -> bool; - auto decompress() -> bool; - - auto getTimestamp(string) const -> uint64_t; - auto getPermissions() const -> uint; - auto getOwner() const -> string; - auto getGroup() const -> string; - - //files and paths - string name; - - bool timestamps = false; - struct Timestamp { - string created; - string modified; - string accessed; - } timestamp; - - bool permissions = false; - struct Permission { - struct Owner { - string name; - bool readable = false; - bool writable = false; - bool executable = false; - } owner; - struct Group { - string name; - bool readable = false; - bool writable = false; - bool executable = false; - } group; - struct Other { - bool readable = false; - bool writable = false; - bool executable = false; - } other; - } permission; - - //files only - vector memory; - uint64_t offset = 0; - - struct Compression { - string type; - uint size = 0; //decompressed size; memory.size() == compressed size - } compression; -}; - -auto Node::create(string name, string location) -> shared_pointer { - if(!inode::exists(location)) return {}; - shared_pointer node = new Node; - - node->name = name; - - node->timestamps = true; - node->timestamp.created = chrono::utc::datetime(inode::timestamp(location, inode::time::create)); - node->timestamp.modified = chrono::utc::datetime(inode::timestamp(location, inode::time::modify)); - node->timestamp.accessed = chrono::utc::datetime(inode::timestamp(location, inode::time::access)); - - uint mode = inode::mode(location); - node->permissions = true; - node->permission.owner.name = inode::owner(location); - node->permission.group.name = inode::group(location); - node->permission.owner.readable = mode & 0400; - node->permission.owner.writable = mode & 0200; - node->permission.owner.executable = mode & 0100; - node->permission.group.readable = mode & 0040; - node->permission.group.writable = mode & 0020; - node->permission.group.executable = mode & 0010; - node->permission.other.readable = mode & 0004; - node->permission.other.writable = mode & 0002; - node->permission.other.executable = mode & 0001; - - if(file::exists(location)) { - node->memory = file::read(location); - } - - return node; -} - -auto Node::createPath(string name) -> shared_pointer { - if(!name) return {}; - shared_pointer node = new Node; - node->name = name; - return node; -} - -auto Node::createFile(string name, array_view memory) -> shared_pointer { - if(!name) return {}; - shared_pointer node = new Node; - node->name = name; - node->memory.resize(memory.size()); - memory::copy(node->memory.data(), memory.data(), memory.size()); - return node; -} - -auto Node::metadata(bool indented) const -> string { - string metadata; - if(!name) return metadata; - - string indent; - if(indented) { - indent.append(" "); - auto bytes = string{name}.trimRight("/"); - for(auto& byte : bytes) { - if(byte == '/') indent.append(" "); - } - } - - if(isPath()) { - metadata.append(indent, "path: ", name, "\n"); - } - - if(isFile()) { - metadata.append(indent, "file: ", name, "\n"); - } - - if(timestamps) { - metadata.append(indent, " timestamp\n"); - if(timestamp.created != timestamp.modified) - metadata.append(indent, " created: ", timestamp.created, "\n"); - metadata.append(indent, " modified: ", timestamp.modified, "\n"); - if(timestamp.accessed != timestamp.modified) - metadata.append(indent, " accessed: ", timestamp.accessed, "\n"); - } - - if(permissions) { - metadata.append(indent, " permission\n"); - metadata.append(indent, " owner: ", permission.owner.name, "\n"); - if(permission.owner.readable) - metadata.append(indent, " readable\n"); - if(permission.owner.writable) - metadata.append(indent, " writable\n"); - if(permission.owner.executable) - metadata.append(indent, " executable\n"); - metadata.append(indent, " group: ", permission.group.name, "\n"); - if(permission.group.readable) - metadata.append(indent, " readable\n"); - if(permission.group.writable) - metadata.append(indent, " writable\n"); - if(permission.group.executable) - metadata.append(indent, " executable\n"); - metadata.append(indent, " other\n"); - if(permission.other.readable) - metadata.append(indent, " readable\n"); - if(permission.other.writable) - metadata.append(indent, " writable\n"); - if(permission.other.executable) - metadata.append(indent, " executable\n"); - } - - if(isFile()) { - metadata.append(indent, " offset: ", offset, "\n"); - if(!isCompressed()) { - metadata.append(indent, " size: ", memory.size(), "\n"); - } else { - metadata.append(indent, " size: ", compression.size, "\n"); - metadata.append(indent, " compression: ", compression.type, "\n"); - metadata.append(indent, " size: ", memory.size(), "\n"); - } - } - - return metadata; -} - -auto Node::unserialize(array_view container, Markup::Node metadata) -> bool { - *this = {}; - if(!metadata.text()) return false; - - name = metadata.text(); - - if(auto node = metadata["timestamp"]) { - timestamps = true; - if(auto created = node["created" ]) timestamp.created = created.text(); - if(auto modified = node["modified"]) timestamp.modified = modified.text(); - if(auto accessed = node["accessed"]) timestamp.accessed = accessed.text(); - } - - if(auto node = metadata["permission"]) { - permissions = true; - if(auto owner = node["owner"]) { - permission.owner.name = owner.text(); - permission.owner.readable = (bool)owner["readable"]; - permission.owner.writable = (bool)owner["writable"]; - permission.owner.executable = (bool)owner["executable"]; - } - if(auto group = node["group"]) { - permission.group.name = group.text(); - permission.group.readable = (bool)group["readable"]; - permission.group.writable = (bool)group["writable"]; - permission.group.executable = (bool)group["executable"]; - } - if(auto other = node["other"]) { - permission.other.readable = (bool)other["readable"]; - permission.other.writable = (bool)other["writable"]; - permission.other.executable = (bool)other["executable"]; - } - } - - if(isPath()) return true; - - uint offset = metadata["offset"].natural(); - uint size = metadata["size"].natural(); - - if(metadata["compression"]) { - size = metadata["compression/size"].natural(); - compression.type = metadata["compression"].text(); - } - - if(offset + size >= container.size()) return false; - - memory.reallocate(size); - nall::memory::copy(memory.data(), container.view(offset, size), size); - return true; -} - -auto Node::compressLZSA() -> bool { - if(!memory) return true; //don't compress empty files - if(isCompressed()) return true; //don't recompress files - - auto compressedMemory = Encode::LZSA(memory); - if(compressedMemory.size() >= memory.size()) return true; //can't compress smaller than original size - - compression.type = "lzsa"; - compression.size = memory.size(); - memory = move(compressedMemory); - return true; -} - -auto Node::decompress() -> bool { - if(!isCompressed()) return true; - - if(compression.type == "lzsa") { - compression = {}; - memory = Decode::LZSA(memory); - return (bool)memory; - } - - return false; -} - -auto Node::getTimestamp(string type) const -> uint64_t { - if(!timestamps) return time(nullptr); - - string value = chrono::utc::datetime(); - if(type == "created" ) value = timestamp.created; - if(type == "modified") value = timestamp.modified; - if(type == "accessed") value = timestamp.accessed; - - #if !defined(PLATFORM_WINDOWS) - struct tm timeInfo{}; - if(strptime(value, "%Y-%m-%d %H:%M:%S", &timeInfo) != nullptr) { - //todo: not thread safe ... - auto tz = getenv("TZ"); - setenv("TZ", "", 1); - timeInfo.tm_isdst = -1; - auto result = mktime(&timeInfo); - if(tz) setenv("TZ", tz, 1); - else unsetenv("TZ"); - if(result != -1) return result; - } - #endif - - return time(nullptr); -} - -auto Node::getPermissions() const -> uint { - if(!permissions) return 0755; - uint mode = 0; - if(permission.owner.readable ) mode |= 0400; - if(permission.owner.writable ) mode |= 0200; - if(permission.owner.executable) mode |= 0100; - if(permission.group.readable ) mode |= 0040; - if(permission.group.writable ) mode |= 0020; - if(permission.group.executable) mode |= 0010; - if(permission.other.readable ) mode |= 0004; - if(permission.other.writable ) mode |= 0002; - if(permission.other.executable) mode |= 0001; - return mode; -} - -auto Node::getOwner() const -> string { - if(!permissions || !permission.owner.name) { - #if !defined(PLATFORM_WINDOWS) - struct passwd* pwd = getpwuid(getuid()); - assert(pwd); - return pwd->pw_name; - #endif - } - return permission.owner.name; -} - -auto Node::getGroup() const -> string { - if(!permissions || !permission.group.name) { - #if !defined(PLATFORM_WINDOWS) - struct group* grp = getgrgid(getgid()); - assert(grp); - return grp->gr_name; - #endif - } - return permission.group.name; -} - -} diff --git a/nall/beat/single/apply.hpp b/nall/beat/single/apply.hpp index cd81762ad9..81eb0ad02e 100644 --- a/nall/beat/single/apply.hpp +++ b/nall/beat/single/apply.hpp @@ -2,23 +2,23 @@ namespace nall::Beat::Single { -inline auto apply(array_view source, array_view beat, maybe manifest = {}, maybe result = {}) -> maybe> { +inline auto apply(array_view source, array_view beat, maybe manifest = {}, maybe result = {}) -> maybe> { #define error(text) { if(result) *result = {"error: ", text}; return {}; } #define warning(text) { if(result) *result = {"warning: ", text}; return target; } #define success() { if(result) *result = ""; return target; } if(beat.size() < 19) error("beat size mismatch"); - vector target; + vector target; - uint beatOffset = 0; - auto read = [&]() -> uint8_t { + u32 beatOffset = 0; + auto read = [&]() -> u8 { return beat[beatOffset++]; }; - auto decode = [&]() -> uint64_t { - uint64_t data = 0, shift = 1; + auto decode = [&]() -> u64 { + u64 data = 0, shift = 1; while(true) { - uint8_t x = read(); + u8 x = read(); data += (x & 0x7f) * shift; if(x & 0x80) break; shift <<= 7; @@ -27,7 +27,7 @@ inline auto apply(array_view source, array_view beat, maybe source, array_view beat, maybeappend((char)data); } - enum : uint { SourceRead, TargetRead, SourceCopy, TargetCopy }; + enum : u32 { SourceRead, TargetRead, SourceCopy, TargetCopy }; - uint sourceRelativeOffset = 0, targetRelativeOffset = 0; + u32 sourceRelativeOffset = 0, targetRelativeOffset = 0; while(beatOffset < beat.size() - 12) { - uint length = decode(); - uint mode = length & 3; + u32 length = decode(); + u32 mode = length & 3; length = (length >> 2) + 1; if(mode == SourceRead) { @@ -57,7 +57,7 @@ inline auto apply(array_view source, array_view beat, maybe> 1) : (offset >> 1); if(mode == SourceCopy) { sourceRelativeOffset += offset; @@ -69,10 +69,10 @@ inline auto apply(array_view source, array_view beat, maybe source, array_view target, string_view manifest = {}) -> vector { - vector beat; +inline auto create(array_view source, array_view target, string_view manifest = {}) -> vector { + vector beat; - auto write = [&](uint8_t data) { + auto write = [&](u8 data) { beat.append(data); }; - auto encode = [&](uint64_t data) { + auto encode = [&](u64 data) { while(true) { - uint64_t x = data & 0x7f; + u64 x = data & 0x7f; data >>= 7; if(data == 0) { write(0x80 | x); break; } write(x); @@ -31,21 +31,21 @@ inline auto create(array_view source, array_view target, strin auto sourceArray = SuffixArray(source); auto targetArray = SuffixArray(target).lpf(); - enum : uint { SourceRead, TargetRead, SourceCopy, TargetCopy }; - uint outputOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0; + enum : u32 { SourceRead, TargetRead, SourceCopy, TargetCopy }; + u32 outputOffset = 0, sourceRelativeOffset = 0, targetRelativeOffset = 0; - uint targetReadLength = 0; + u32 targetReadLength = 0; auto flush = [&] { if(!targetReadLength) return; encode(TargetRead | ((targetReadLength - 1) << 2)); - uint offset = outputOffset - targetReadLength; + u32 offset = outputOffset - targetReadLength; while(targetReadLength) write(target[offset++]), targetReadLength--; }; - uint overlap = min(source.size(), target.size()); + u32 overlap = min(source.size(), target.size()); while(outputOffset < target.size()) { - uint mode = TargetRead, longestLength = 3, longestOffset = 0; - int length = 0, offset = outputOffset; + u32 mode = TargetRead, longestLength = 3, longestOffset = 0; + s32 length = 0, offset = outputOffset; while(offset < overlap) { if(source[offset] != target[offset]) break; @@ -72,12 +72,12 @@ inline auto create(array_view source, array_view target, strin flush(); encode(mode | ((longestLength - 1) << 2)); if(mode == SourceCopy) { - int relativeOffset = longestOffset - sourceRelativeOffset; + s32 relativeOffset = longestOffset - sourceRelativeOffset; sourceRelativeOffset = longestOffset + longestLength; encode(relativeOffset < 0 | abs(relativeOffset) << 1); } if(mode == TargetCopy) { - int relativeOffset = longestOffset - targetRelativeOffset; + s32 relativeOffset = longestOffset - targetRelativeOffset; targetRelativeOffset = longestOffset + longestLength; encode(relativeOffset < 0 | abs(relativeOffset) << 1); } @@ -87,11 +87,11 @@ inline auto create(array_view source, array_view target, strin flush(); auto sourceHash = Hash::CRC32(source); - for(uint shift : range(0, 32, 8)) write(sourceHash.value() >> shift); + for(u32 shift : range(0, 32, 8)) write(sourceHash.value() >> shift); auto targetHash = Hash::CRC32(target); - for(uint shift : range(0, 32, 8)) write(targetHash.value() >> shift); + for(u32 shift : range(0, 32, 8)) write(targetHash.value() >> shift); auto beatHash = Hash::CRC32(beat); - for(uint shift : range(0, 32, 8)) write(beatHash.value() >> shift); + for(u32 shift : range(0, 32, 8)) write(beatHash.value() >> shift); return beat; } diff --git a/nall/bit.hpp b/nall/bit.hpp index 42898c1baf..13cf09dcb7 100644 --- a/nall/bit.hpp +++ b/nall/bit.hpp @@ -4,8 +4,8 @@ namespace nall { -template inline auto uclamp(T x) -> uint64_t { - enum : uint64_t { b = 1ull << (bits - 1), y = b * 2 - 1 }; +template inline auto uclamp(T x) -> u64 { + enum : u64 { b = 1ull << (bits - 1), y = b * 2 - 1 }; if constexpr(is_unsigned_v) { return y + ((x - y) & -(x < y)); //min(x, y); } @@ -14,23 +14,23 @@ template inline auto uclamp(T x) -> uint64_t { } } -template inline auto uclip(uint64_t x) -> uint64_t { - enum : uint64_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; +template inline auto uclip(u64 x) -> u64 { + enum : u64 { b = 1ull << (bits - 1), m = b * 2 - 1 }; return (x & m); } -template inline auto sclamp(int64_t x) -> int64_t { - enum : int64_t { b = 1ull << (bits - 1), m = b - 1 }; +template inline auto sclamp(s64 x) -> s64 { + enum : s64 { b = 1ull << (bits - 1), m = b - 1 }; return (x > m) ? m : (x < -b) ? -b : x; } -template inline auto sclip(int64_t x) -> int64_t { - enum : uint64_t { b = 1ull << (bits - 1), m = b * 2 - 1 }; +template inline auto sclip(s64 x) -> s64 { + enum : u64 { b = 1ull << (bits - 1), m = b * 2 - 1 }; return ((x & m) ^ b) - b; } namespace bit { - constexpr inline auto mask(const char* s, uint64_t sum = 0) -> uint64_t { + constexpr inline auto mask(const char* s, u64 sum = 0) -> u64 { return ( *s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) : *s == ' ' || *s == '_' ? mask(s + 1, sum) : @@ -39,7 +39,7 @@ namespace bit { ); } - constexpr inline auto test(const char* s, uint64_t sum = 0) -> uint64_t { + constexpr inline auto test(const char* s, u64 sum = 0) -> u64 { return ( *s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) : *s == ' ' || *s == '_' ? test(s + 1, sum) : @@ -49,38 +49,38 @@ namespace bit { } //lowest(0b1110) == 0b0010 - constexpr inline auto lowest(const uint64_t x) -> uint64_t { + constexpr inline auto lowest(const u64 x) -> u64 { return x & -x; } //clear_lowest(0b1110) == 0b1100 - constexpr inline auto clearLowest(const uint64_t x) -> uint64_t { + constexpr inline auto clearLowest(const u64 x) -> u64 { return x & (x - 1); } //set_lowest(0b0101) == 0b0111 - constexpr inline auto setLowest(const uint64_t x) -> uint64_t { + constexpr inline auto setLowest(const u64 x) -> u64 { return x | (x + 1); } //count number of bits set in a byte - constexpr inline auto count(uint64_t x) -> uint { - uint count = 0; + constexpr inline auto count(u64 x) -> u32 { + u32 count = 0; while(x) x &= x - 1, count++; //clear the least significant bit return count; } //return index of the first bit set (or zero of no bits are set) //first(0b1000) == 3 - constexpr inline auto first(uint64_t x) -> uint { - uint first = 0; + constexpr inline auto first(u64 x) -> u32 { + u32 first = 0; while(x) { if(x & 1) break; x >>= 1; first++; } return first; } //round up to next highest single bit: //round(15) == 16, round(16) == 16, round(17) == 32 - constexpr inline auto round(uint64_t x) -> uint64_t { + constexpr inline auto round(u64 x) -> u64 { if((x & (x - 1)) == 0) return x; while(x & (x - 1)) x &= x - 1; return x << 1; diff --git a/nall/bump-allocator.hpp b/nall/bump-allocator.hpp index ede574712b..88d7eb7ff1 100644 --- a/nall/bump-allocator.hpp +++ b/nall/bump-allocator.hpp @@ -1,10 +1,12 @@ #pragma once +#include + namespace nall { struct bump_allocator { - static constexpr uint32_t executable = 1 << 0; - static constexpr uint32_t zero_fill = 1 << 1; + static constexpr u32 executable = 1 << 0; + static constexpr u32 zero_fill = 1 << 1; ~bump_allocator() { reset(); @@ -15,15 +17,15 @@ struct bump_allocator { } auto reset() -> void { - free(_memory); + memory::free(_memory); _memory = nullptr; } - auto resize(uint32_t capacity, uint32_t flags = 0) -> bool { + auto resize(u32 capacity, u32 flags = 0) -> bool { reset(); _offset = 0; - _capacity = capacity + 4095 & ~4095; //alignment - _memory = (uint8_t*)malloc(_capacity); + _capacity = capacity + 4095 & ~4095; //capacity alignment + _memory = memory::allocate(_capacity); //_SC_PAGESIZE alignment if(!_memory) return false; if(flags & executable) { @@ -43,21 +45,21 @@ struct bump_allocator { } //release all acquired memory - auto release(uint32_t flags = 0) -> void { + auto release(u32 flags = 0) -> void { _offset = 0; if(flags & zero_fill) memset(_memory, 0x00, _capacity); } - auto capacity() const -> uint32_t { + auto capacity() const -> u32 { return _capacity; } - auto available() const -> uint32_t { + auto available() const -> u32 { return _capacity - _offset; } //for allocating blocks of known size - auto acquire(uint32_t size) -> uint8_t* { + auto acquire(u32 size) -> u8* { #ifdef DEBUG struct out_of_memory {}; if((_offset + size + 15 & ~15) > _capacity) throw out_of_memory{}; @@ -68,7 +70,7 @@ struct bump_allocator { } //for allocating blocks of unknown size (eg for a dynamic recompiler code block) - auto acquire() -> uint8_t* { + auto acquire() -> u8* { #ifdef DEBUG struct out_of_memory {}; if(_offset > _capacity) throw out_of_memory{}; @@ -77,7 +79,7 @@ struct bump_allocator { } //size can be reserved once the block size is known - auto reserve(uint32_t size) -> void { + auto reserve(u32 size) -> void { #ifdef DEBUG struct out_of_memory {}; if((_offset + size + 15 & ~15) > _capacity) throw out_of_memory{}; @@ -86,9 +88,9 @@ struct bump_allocator { } private: - uint8_t* _memory = nullptr; - uint32_t _capacity = 0; - uint32_t _offset = 0; + u8* _memory = nullptr; + u32 _capacity = 0; + u32 _offset = 0; }; } diff --git a/nall/cd/crc16.hpp b/nall/cd/crc16.hpp index d0b34b1cd2..edd3826618 100644 --- a/nall/cd/crc16.hpp +++ b/nall/cd/crc16.hpp @@ -4,11 +4,11 @@ namespace nall::CD { -inline auto CRC16(array_view data) -> uint16_t { - uint16_t crc = 0; +inline auto CRC16(array_view data) -> u16 { + u16 crc = 0; while(data) { crc ^= *data++ << 8; - for(uint bit : range(8)) { + for(u32 bit : range(8)) { crc = crc << 1 ^ (crc & 0x8000 ? 0x1021 : 0); } } diff --git a/nall/cd/edc.hpp b/nall/cd/edc.hpp index bcc645a57c..2bf91c687d 100644 --- a/nall/cd/edc.hpp +++ b/nall/cd/edc.hpp @@ -5,13 +5,13 @@ namespace nall::CD::EDC { //polynomial(x) = (x^16 + x^15 + x^2 + 1) * (x^16 + x^2 + x + 1) -inline auto polynomial(uint8_t x) -> uint32_t { - static uint32_t lookup[256]{}; +inline auto polynomial(u8 x) -> u32 { + static u32 lookup[256]{}; static bool once = false; if(!once) { once = true; - for(uint n : range(256)) { - uint32_t edc = n; - for(uint b : range(8)) edc = edc >> 1 ^ (edc & 1 ? 0xd8018001 : 0); + for(u32 n : range(256)) { + u32 edc = n; + for(u32 b : range(8)) edc = edc >> 1 ^ (edc & 1 ? 0xd8018001 : 0); lookup[n] = edc; } } @@ -20,13 +20,13 @@ inline auto polynomial(uint8_t x) -> uint32_t { // -inline auto create(array_view input) -> uint32_t { - uint32_t sum = 0; +inline auto create(array_view input) -> u32 { + u32 sum = 0; for(auto& byte : input) sum = sum >> 8 ^ polynomial(sum ^ byte); return sum; } -inline auto create(array_view input, array_span output) -> bool { +inline auto create(array_view input, array_span output) -> bool { if(output.size() != 4) return false; auto sum = create(input); output[0] = sum >> 0; @@ -36,28 +36,28 @@ inline auto create(array_view input, array_span output) -> boo return true; } -inline auto createMode1(array_span sector) -> bool { +inline auto createMode1(array_span sector) -> bool { if(sector.size() != 2352) return false; return create({sector, 2064}, {sector + 2064, 4}); } // -inline auto verify(array_view input, uint32_t edc) -> bool { +inline auto verify(array_view input, u32 edc) -> bool { return edc == create(input); } -inline auto verify(array_view input, array_view compare) -> bool { +inline auto verify(array_view input, array_view compare) -> bool { if(compare.size() != 4) return false; auto sum = create(input); - if(compare[0] != uint8_t(sum >> 0)) return false; - if(compare[1] != uint8_t(sum >> 8)) return false; - if(compare[2] != uint8_t(sum >> 16)) return false; - if(compare[3] != uint8_t(sum >> 24)) return false; + if(compare[0] != u8(sum >> 0)) return false; + if(compare[1] != u8(sum >> 8)) return false; + if(compare[2] != u8(sum >> 16)) return false; + if(compare[3] != u8(sum >> 24)) return false; return true; } -inline auto verifyMode1(array_view sector) -> bool { +inline auto verifyMode1(array_view sector) -> bool { if(sector.size() != 2352) return false; return verify({sector, 2064}, {sector + 2064, 4}); } diff --git a/nall/cd/efm.hpp b/nall/cd/efm.hpp index ea4896a858..6163263dec 100644 --- a/nall/cd/efm.hpp +++ b/nall/cd/efm.hpp @@ -6,8 +6,8 @@ namespace nall::CD::EFM { //the algorithm to generate this table is unknown -inline auto lookup(uint8_t index) -> uint16_t { - static const uint16_t lookup[256] = { +inline auto lookup(u8 index) -> u16 { + static const u16 lookup[256] = { 0x1220, 0x2100, 0x2420, 0x2220, 0x1100, 0x0110, 0x0420, 0x0900, 0x1240, 0x2040, 0x2440, 0x2240, 0x1040, 0x0040, 0x0440, 0x0840, 0x2020, 0x2080, 0x2480, 0x0820, 0x1080, 0x0080, 0x0480, 0x0880, @@ -46,23 +46,23 @@ inline auto lookup(uint8_t index) -> uint16_t { // -inline auto encode(uint8_t data) -> uint16_t { +inline auto encode(u8 data) -> u16 { return lookup(data); } // -inline auto decode(uint16_t data) -> maybe { - static uint16_t table[1 << 14]; +inline auto decode(u16 data) -> maybe { + static u16 table[1 << 14]; static bool once = true; if(once) { once = false; - for(uint n : range(1 << 14)) table[n] = 0xffff; - for(uint n : range(1 << 8)) table[lookup(n)] = n; + for(u32 n : range(1 << 14)) table[n] = 0xffff; + for(u32 n : range(1 << 8)) table[lookup(n)] = n; } - uint16_t result = table[data & 0x3fff]; + u16 result = table[data & 0x3fff]; if(result == 0xffff) return {}; - return (uint8_t)result; + return (u8)result; } } diff --git a/nall/cd/rspc.hpp b/nall/cd/rspc.hpp index 4f776dd2cd..84c928ba80 100644 --- a/nall/cd/rspc.hpp +++ b/nall/cd/rspc.hpp @@ -4,13 +4,13 @@ namespace nall::CD::RSPC { -inline auto encodeP(array_view input, array_span parity) -> bool { +inline auto encodeP(array_view input, array_span parity) -> bool { ReedSolomon<26,24> s; - uint lo = 0, hi = 43 * 2; - for(uint x : range(43)) { - for(uint w : range(2)) { //16-bit words - uint z = 0; - for(uint y : range(24)) { + u32 lo = 0, hi = 43 * 2; + for(u32 x : range(43)) { + for(u32 w : range(2)) { //16-bit words + u32 z = 0; + for(u32 y : range(24)) { s[z++] = input[(y * 43 + x) * 2 + w]; } s.generateParity(); @@ -21,13 +21,13 @@ inline auto encodeP(array_view input, array_span parity) -> bo return true; } -inline auto encodeQ(array_view input, array_span parity) -> bool { +inline auto encodeQ(array_view input, array_span parity) -> bool { ReedSolomon<45,43> s; - uint lo = 0, hi = 26 * 2; - for(uint y : range(26)) { - for(uint w : range(2)) { - uint z = 0; - for(uint x : range(43)) { + u32 lo = 0, hi = 26 * 2; + for(u32 y : range(26)) { + for(u32 w : range(2)) { + u32 z = 0; + for(u32 x : range(43)) { s[z++] = input[((x * 44 + y * 43) * 2 + w) % (26 * 43 * 2)]; } s.generateParity(); @@ -38,7 +38,7 @@ inline auto encodeQ(array_view input, array_span parity) -> bo return true; } -inline auto encodeMode1(array_span sector) -> bool { +inline auto encodeMode1(array_span sector) -> bool { if(sector.size() != 2352) return false; if(!encodeP({sector + 12, 2064}, {sector + 2076, 172})) return false; if(!encodeQ({sector + 12, 2236}, {sector + 2248, 104})) return false; @@ -47,15 +47,15 @@ inline auto encodeMode1(array_span sector) -> bool { // -inline auto decodeP(array_span input, array_span parity) -> int { +inline auto decodeP(array_span input, array_span parity) -> s32 { bool success = false; bool failure = false; ReedSolomon<26,24> s; - uint lo = 0, hi = 43 * 2; - for(uint x : range(43)) { - for(uint w : range(2)) { - uint z = 0; - for(uint y : range(24)) { + u32 lo = 0, hi = 43 * 2; + for(u32 x : range(43)) { + for(u32 w : range(2)) { + u32 z = 0; + for(u32 y : range(24)) { s[z++] = input[(y * 43 + x) * 2 + w]; } s[z++] = parity[lo++]; @@ -67,7 +67,7 @@ inline auto decodeP(array_span input, array_span parity) -> in if(count > 0) { success = true; z = 0; - for(uint y : range(24)) { + for(u32 y : range(24)) { input[(y * 43 + x) * 2 + w] = s[z++]; } parity[lo - 1] = s[z++]; @@ -79,15 +79,15 @@ inline auto decodeP(array_span input, array_span parity) -> in return success ? 1 : -1; //return success even if there are some failures } -inline auto decodeQ(array_span input, array_span parity) -> int { +inline auto decodeQ(array_span input, array_span parity) -> s32 { bool success = false; bool failure = false; ReedSolomon<45,43> s; - uint lo = 0, hi = 26 * 2; - for(uint y : range(26)) { - for(uint w : range(2)) { - uint z = 0; - for(uint x : range(43)) { + u32 lo = 0, hi = 26 * 2; + for(u32 y : range(26)) { + for(u32 w : range(2)) { + u32 z = 0; + for(u32 x : range(43)) { s[z++] = input[((x * 44 + y * 43) * 2 + w) % (26 * 43 * 2)]; } s[z++] = parity[lo++]; @@ -99,7 +99,7 @@ inline auto decodeQ(array_span input, array_span parity) -> in if(count > 0) { success = true; z = 0; - for(uint x : range(43)) { + for(u32 x : range(43)) { input[((x * 44 + y * 43) * 2 + w) % (26 * 43 * 2)] = s[z++]; } parity[lo - 1] = s[z++]; @@ -111,12 +111,12 @@ inline auto decodeQ(array_span input, array_span parity) -> in return success ? 1 : -1; } -inline auto decodeMode1(array_span sector) -> bool { +inline auto decodeMode1(array_span sector) -> bool { if(sector.size() != 2352) return false; //P corrections can allow Q corrections that previously failed to succeed, and vice versa. //the more iterations, the more chances to correct errors, but the more computationally expensive it is. //there must be a limit on the amount of retries, or this function may get stuck in an infinite loop. - for(uint attempt : range(4)) { + for(u32 attempt : range(4)) { auto p = decodeP({sector + 12, 2064}, {sector + 2076, 172}); auto q = decodeQ({sector + 12, 2236}, {sector + 2248, 104}); if(p == 0 && q == 0) return true; //no errors remaining diff --git a/nall/cd/scrambler.hpp b/nall/cd/scrambler.hpp index cf7380e522..43aa4fa3d5 100644 --- a/nall/cd/scrambler.hpp +++ b/nall/cd/scrambler.hpp @@ -3,14 +3,14 @@ namespace nall::CD::Scrambler { //polynomial(x) = x^15 + x + 1 -inline auto polynomial(uint x) -> uint8_t { - static uint8_t lookup[2340]{}; +inline auto polynomial(u32 x) -> u8 { + static u8 lookup[2340]{}; static bool once = false; if(!once) { once = true; - uint16_t shift = 0x0001; - for(uint n : range(2340)) { + u16 shift = 0x0001; + for(u32 n : range(2340)) { lookup[n] = shift; - for(uint b : range(8)) { + for(u32 b : range(8)) { bool carry = shift & 1 ^ shift >> 1 & 1; shift = (carry << 15 | shift) >> 1; } @@ -21,11 +21,11 @@ inline auto polynomial(uint x) -> uint8_t { // -inline auto transform(array_span sector) -> bool { +inline auto transform(array_span sector) -> bool { if(sector.size() == 2352) sector += 12; //header is not scrambled if(sector.size() != 2340) return false; //F1 frames only - for(uint index : range(2340)) { + for(u32 index : range(2340)) { sector[index] ^= polynomial(index); } diff --git a/nall/cd/session.hpp b/nall/cd/session.hpp index a5a4f96af0..395347e824 100644 --- a/nall/cd/session.hpp +++ b/nall/cd/session.hpp @@ -5,41 +5,41 @@ namespace nall::CD { -enum : int { InvalidLBA = 100 * 60 * 75 }; +enum : s32 { InvalidLBA = 100 * 60 * 75 }; struct BCD { - static auto encode(uint8_t value) -> uint8_t { return value / 10 << 4 | value % 10; } - static auto decode(uint8_t value) -> uint8_t { return (value >> 4) * 10 + (value & 15); } + static auto encode(u8 value) -> u8 { return value / 10 << 4 | value % 10; } + static auto decode(u8 value) -> u8 { return (value >> 4) * 10 + (value & 15); } }; struct MSF { - uint8_t minute; //00-99 - uint8_t second; //00-59 - uint8_t frame = -1; //00-74 + u8 minute; //00-99 + u8 second; //00-59 + u8 frame = -1; //00-74 MSF() = default; - MSF(uint8_t m, uint8_t s, uint8_t f) : minute(m), second(s), frame(f) {} - MSF(int lba) { *this = fromLBA(lba); } + MSF(u8 m, u8 s, u8 f) : minute(m), second(s), frame(f) {} + MSF(s32 lba) { *this = fromLBA(lba); } explicit operator bool() const { return minute <= 99 && second <= 59 && frame <= 74; } - static auto fromBCD(uint8_t minute, uint8_t second, uint8_t frame) -> MSF { + static auto fromBCD(u8 minute, u8 second, u8 frame) -> MSF { return {BCD::decode(minute), BCD::decode(second), BCD::decode(frame)}; } - static auto fromLBA(int lba) -> MSF { + static auto fromLBA(s32 lba) -> MSF { if(lba < 0) lba = 100 * 60 * 75 + lba; if(lba >= 100 * 60 * 75) return {}; - uint8_t minute = lba / 75 / 60 % 100; - uint8_t second = lba / 75 % 60; - uint8_t frame = lba % 75; + u8 minute = lba / 75 / 60 % 100; + u8 second = lba / 75 % 60; + u8 frame = lba % 75; return {minute, second, frame}; } - auto toLBA() const -> int { - int lba = minute * 60 * 75 + second * 75 + frame; + auto toLBA() const -> s32 { + s32 lba = minute * 60 * 75 + second * 75 + frame; if(minute < 90) return lba; return -(100 * 60 * 75 - lba); } @@ -52,25 +52,25 @@ struct MSF { }; struct Index { - int lba = InvalidLBA; - int end = InvalidLBA; //inclusive range + s32 lba = InvalidLBA; + s32 end = InvalidLBA; //inclusive range explicit operator bool() const { return lba != InvalidLBA; } - auto inRange(int sector) const -> bool { + auto inRange(s32 sector) const -> bool { if(lba == InvalidLBA || end == InvalidLBA) return false; return sector >= lba && sector <= end; } }; struct Track { - uint8_t control = 0b1111; //4-bit - uint8_t address = 0b1111; //4-bit + u8 control = 0b1111; //4-bit + u8 address = 0b1111; //4-bit Index indices[100]; - uint8_t firstIndex = -1; - uint8_t lastIndex = -1; + u8 firstIndex = -1; + u8 lastIndex = -1; explicit operator bool() const { return (bool)indices[1]; @@ -84,13 +84,13 @@ struct Track { return control & 2; } - auto channels() const -> uint { + auto channels() const -> u32 { if((control & 0b1100) == 0b0000) return 2; if((control & 0b1100) == 0b1000) return 4; return 0; //data track or reserved } - auto pregap() const -> int { + auto pregap() const -> s32 { if(!indices[0] || !indices[1]) return InvalidLBA; return indices[1].lba - indices[0].lba; } @@ -103,19 +103,19 @@ struct Track { return (control & 0b1100) == 0b0100; } - auto inIndex(int lba) const -> maybe { - for(uint8_t index : range(100)) { + auto inIndex(s32 lba) const -> maybe { + for(u8 index : range(100)) { if(indices[index].inRange(lba)) return index; } return {}; } - auto inRange(int lba) const -> bool { + auto inRange(s32 lba) const -> bool { if(firstIndex > 99 || lastIndex > 99) return false; return lba >= indices[firstIndex].lba && lba <= indices[lastIndex].end; } - auto index(uint8_t indexID) -> maybe { + auto index(u8 indexID) -> maybe { if(indexID < 100 && indices[indexID]) return indices[indexID]; return {}; } @@ -125,51 +125,51 @@ struct Session { Index leadIn; //00 Track tracks[100]; //01-99 Index leadOut; //aa - uint8_t firstTrack = -1; - uint8_t lastTrack = -1; + u8 firstTrack = -1; + u8 lastTrack = -1; - auto inLeadIn(int lba) const -> bool { + auto inLeadIn(s32 lba) const -> bool { return lba < 0; } - auto inTrack(int lba) const -> maybe { - for(uint8_t trackID : range(100)) { + auto inTrack(s32 lba) const -> maybe { + for(u8 trackID : range(100)) { auto& track = tracks[trackID]; if(track && track.inRange(lba)) return trackID; } return {}; } - auto inLeadOut(int lba) const -> bool { + auto inLeadOut(s32 lba) const -> bool { return lba >= leadOut.lba; } - auto track(uint8_t trackID) -> maybe { + auto track(u8 trackID) -> maybe { if(trackID < 100 && tracks[trackID]) return tracks[trackID]; return {}; } - auto encode(uint sectors) const -> vector { + auto encode(u32 sectors) const -> vector { if(sectors < abs(leadIn.lba) + leadOut.lba) return {}; //not enough sectors - vector data; + vector data; data.resize(sectors * 96 + 96); //add one sector for P shift - auto toP = [&](int lba) -> array_span { + auto toP = [&](s32 lba) -> array_span { //P is encoded one sector later than Q return {&data[(lba + abs(leadIn.lba) + 1) * 96], 12}; }; - auto toQ = [&](int lba) -> array_span { + auto toQ = [&](s32 lba) -> array_span { return {&data[(lba + abs(leadIn.lba)) * 96 + 12], 12}; }; //lead-in - int lba = leadIn.lba; + s32 lba = leadIn.lba; while(lba < 0) { //tracks - for(uint trackID : range(100)) { - for(uint repeat : range(3)) { + for(u32 trackID : range(100)) { + for(u32 repeat : range(3)) { auto& track = tracks[trackID]; if(!track) continue; auto q = toQ(lba); @@ -192,7 +192,7 @@ struct Session { }}if( lba >= 0) break; //first track - for(uint repeat : range(3)) { + for(u32 repeat : range(3)) { auto q = toQ(lba); q[0] = 0x01; //control value unverified; address = 1 q[1] = 0x00; //track# = 00 (TOC) @@ -212,7 +212,7 @@ struct Session { } if( lba >= 0) break; //last track - for(uint repeat : range(3)) { + for(u32 repeat : range(3)) { auto q = toQ(lba); q[0] = 0x01; q[1] = 0x00; @@ -232,7 +232,7 @@ struct Session { } if( lba >= 0) break; //lead-out point - for(uint repeat : range(3)) { + for(u32 repeat : range(3)) { auto q = toQ(lba); q[0] = 0x01; q[1] = 0x00; @@ -254,20 +254,20 @@ struct Session { } //tracks - int end = leadOut.lba; - for(uint8_t trackID : reverse(range(100))) { + s32 end = leadOut.lba; + for(u8 trackID : reverse(range(100))) { auto& track = tracks[trackID]; if(!track) continue; //indices - for(uint8_t indexID : reverse(range(100))) { + for(u8 indexID : reverse(range(100))) { auto& index = track.indices[indexID]; if(!index) continue; - for(int lba = index.lba; lba < end; lba++) { + for(s32 lba = index.lba; lba < end; lba++) { auto p = toP(lba); - uint8_t byte = indexID == 0 ? 0xff : 0x00; - for(uint index : range(12)) p[index] = byte; + u8 byte = indexID == 0 ? 0xff : 0x00; + for(u32 index : range(12)) p[index] = byte; auto q = toQ(lba); q[0] = track.control << 4 | track.address << 0; @@ -292,9 +292,9 @@ struct Session { } //lead-out - for(int lba : range(sectors - abs(leadIn.lba) - leadOut.lba)) { + for(s32 lba : range(sectors - abs(leadIn.lba) - leadOut.lba)) { auto p = toP(leadOut.lba + lba); - uint8_t byte; + u8 byte; if(lba < 150) { //2s start (standard specifies 2-3s start) byte = 0x00; @@ -302,7 +302,7 @@ struct Session { //2hz duty cycle; rounded downward (standard specifies 2% tolerance) byte = (lba - 150) / (75 >> 1) & 1 ? 0xff : 0x00; } - for(uint index : range(12)) p[index] = byte; + for(u32 index : range(12)) p[index] = byte; auto q = toQ(leadOut.lba + lba); q[0] = 0x01; @@ -326,25 +326,25 @@ struct Session { return data; } - auto decode(array_view data, uint size, uint leadOutSectors = 0) -> bool { + auto decode(array_view data, u32 size, u32 leadOutSectors = 0) -> bool { *this = {}; //reset session //three data[] types supported: subcode Q only, subcode P-W only, data+subcode complete image if(size != 12 && size != 96 && size != 2448) return false; //determine lead-in sector count - for(int lba : range(7500)) { //7500 max sectors scanned - uint offset = lba * size; + for(s32 lba : range(7500)) { //7500 max sectors scanned + u32 offset = lba * size; if(size == 96) offset += 12; if(size == 2448) offset += 12 + 2352; if(offset + 12 > data.size()) break; - auto q = array_view{&data[offset], 12}; + auto q = array_view{&data[offset], 12}; auto crc16 = CRC16({q, 10}); - if(q[10] != uint8_t(crc16 >> 8)) continue; - if(q[11] != uint8_t(crc16 >> 0)) continue; + if(q[10] != u8(crc16 >> 8)) continue; + if(q[11] != u8(crc16 >> 0)) continue; - uint8_t control = q[0] >> 4; - uint8_t address = q[0] & 15; - uint8_t trackID = q[1]; + u8 control = q[0] >> 4; + u8 address = q[0] & 15; + u8 trackID = q[1]; if(address != 1) continue; if(trackID != 0) continue; @@ -354,8 +354,8 @@ struct Session { } if(leadIn.lba == InvalidLBA || leadIn.lba >= 0) return false; - auto toQ = [&](int lba) -> array_view { - uint offset = (lba + abs(leadIn.lba)) * size; + auto toQ = [&](s32 lba) -> array_view { + u32 offset = (lba + abs(leadIn.lba)) * size; if(size == 96) offset += 12; if(size == 2448) offset += 12 + 2352; if(offset + 12 > data.size()) return {}; @@ -363,16 +363,16 @@ struct Session { }; //lead-in - for(int lba = leadIn.lba; lba < 0; lba++) { + for(s32 lba = leadIn.lba; lba < 0; lba++) { auto q = toQ(lba); if(!q) break; auto crc16 = CRC16({q, 10}); - if(q[10] != uint8_t(crc16 >> 8)) continue; - if(q[11] != uint8_t(crc16 >> 0)) continue; + if(q[10] != u8(crc16 >> 8)) continue; + if(q[11] != u8(crc16 >> 0)) continue; - uint8_t control = q[0] >> 4; - uint8_t address = q[0] & 15; - uint8_t trackID = q[1]; + u8 control = q[0] >> 4; + u8 address = q[0] & 15; + u8 trackID = q[1]; if(address != 1) continue; if(trackID != 0) continue; @@ -400,17 +400,17 @@ struct Session { if(leadOut.lba == InvalidLBA) return false; //tracks - for(int lba = 0; lba < leadOut.lba; lba++) { + for(s32 lba = 0; lba < leadOut.lba; lba++) { auto q = toQ(lba); if(!q) break; auto crc16 = CRC16({q, 10}); - if(q[10] != uint8_t(crc16 >> 8)) continue; - if(q[11] != uint8_t(crc16 >> 0)) continue; + if(q[10] != u8(crc16 >> 8)) continue; + if(q[11] != u8(crc16 >> 0)) continue; - uint8_t control = q[0] >> 4; - uint8_t address = q[0] & 15; - uint8_t trackID = BCD::decode(q[1]); - uint8_t indexID = BCD::decode(q[2]); + u8 control = q[0] >> 4; + u8 address = q[0] & 15; + u8 trackID = BCD::decode(q[1]); + u8 indexID = BCD::decode(q[2]); if(address != 1) continue; if(trackID > 99) continue; if(indexID > 99) continue; @@ -429,14 +429,14 @@ struct Session { //calculates Index::end variables: //needed for Session::isTrack() and Track::isIndex() to function. - auto synchronize(uint leadOutSectors = 0) -> void { + auto synchronize(u32 leadOutSectors = 0) -> void { leadIn.end = -1; - int end = leadOut.lba - 1; - for(uint trackID : reverse(range(100))) { + s32 end = leadOut.lba - 1; + for(u32 trackID : reverse(range(100))) { auto& track = tracks[trackID]; if(!track) continue; - for(uint indexID : reverse(range(100))) { + for(u32 indexID : reverse(range(100))) { auto& index = track.indices[indexID]; if(!index) continue; @@ -444,12 +444,12 @@ struct Session { end = index.lba - 1; } - for(uint indexID : range(100)) { + for(u32 indexID : range(100)) { auto& index = track.indices[indexID]; if(index) { track.firstIndex = indexID; break; } } - for(uint indexID : reverse(range(100))) { + for(u32 indexID : reverse(range(100))) { auto& index = track.indices[indexID]; if(index) { track.lastIndex = indexID; break; } } @@ -463,7 +463,7 @@ struct Session { s.append("session\n"); s.append(" leadIn: "); s.append(MSF(leadIn.lba).toString(), " - ", MSF(leadIn.end).toString(), "\n"); - for(uint trackID : range(100)) { + for(u32 trackID : range(100)) { auto& track = tracks[trackID]; if(!track) continue; s.append(" track", pad(trackID, 2, '0')); @@ -472,7 +472,7 @@ struct Session { s.append("\n"); s.append(" control: ", binary(track.control, 4, '0'), "\n"); s.append(" address: ", binary(track.address, 4, '0'), "\n"); - for(uint indexID : range(100)) { + for(u32 indexID : range(100)) { auto& index = track.indices[indexID]; if(!index) continue; s.append(" index", pad(indexID, 2, '0'), ": "); diff --git a/nall/cd/sync.hpp b/nall/cd/sync.hpp index 2d9620a241..6ae08fe32f 100644 --- a/nall/cd/sync.hpp +++ b/nall/cd/sync.hpp @@ -2,10 +2,10 @@ namespace nall::CD::Sync { -inline auto create(array_span sector) -> bool { +inline auto create(array_span sector) -> bool { if(sector.size() != 12 && sector.size() != 2352) return false; - for(uint n : range(12)) { + for(u32 n : range(12)) { sector[n] = ((n == 0 || n == 11) ? 0x00 : 0xff); } @@ -14,10 +14,10 @@ inline auto create(array_span sector) -> bool { // -inline auto verify(array_view sector) -> bool { +inline auto verify(array_view sector) -> bool { if(sector.size() != 12 && sector.size() != 2352) return false; - for(uint n : range(12)) { + for(u32 n : range(12)) { if(sector[n] != ((n == 0 || n == 11) ? 0x00 : 0xff)) return false; } diff --git a/nall/chrono.hpp b/nall/chrono.hpp index 7e4ea829aa..68615f50e6 100644 --- a/nall/chrono.hpp +++ b/nall/chrono.hpp @@ -7,17 +7,17 @@ namespace nall::chrono { //passage of time functions (from unknown epoch) -inline auto nanosecond() -> uint64_t { +inline auto nanosecond() -> u64 { timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); return tv.tv_sec * 1'000'000'000 + tv.tv_nsec; } -inline auto microsecond() -> uint64_t { return nanosecond() / 1'000; } -inline auto millisecond() -> uint64_t { return nanosecond() / 1'000'000; } -inline auto second() -> uint64_t { return nanosecond() / 1'000'000'000; } +inline auto microsecond() -> u64 { return nanosecond() / 1'000; } +inline auto millisecond() -> u64 { return nanosecond() / 1'000'000; } +inline auto second() -> u64 { return nanosecond() / 1'000'000'000; } -inline auto benchmark(const function& f, uint64_t times = 1) -> void { +inline auto benchmark(const function& f, u64 times = 1) -> void { auto start = nanosecond(); while(times--) f(); auto end = nanosecond(); @@ -27,71 +27,68 @@ inline auto benchmark(const function& f, uint64_t times = 1) -> void { //exact date/time functions (from system epoch) struct timeinfo { - timeinfo( - uint year = 0, uint month = 0, uint day = 0, - uint hour = 0, uint minute = 0, uint second = 0, uint weekday = 0 - ) : year(year), month(month), day(day), - hour(hour), minute(minute), second(second), weekday(weekday) { + timeinfo(u32 year = 0, u32 month = 0, u32 day = 0, u32 hour = 0, u32 minute = 0, u32 second = 0, u32 weekday = 0): + year(year), month(month), day(day), hour(hour), minute(minute), second(second), weekday(weekday) { } explicit operator bool() const { return month; } - uint year; //... - uint month; //1 - 12 - uint day; //1 - 31 - uint hour; //0 - 23 - uint minute; //0 - 59 - uint second; //0 - 60 - uint weekday; //0 - 6 + u32 year; //... + u32 month; //1 - 12 + u32 day; //1 - 31 + u32 hour; //0 - 23 + u32 minute; //0 - 59 + u32 second; //0 - 60 + u32 weekday; //0 - 6 }; -inline auto timestamp() -> uint64_t { +inline auto timestamp() -> u64 { return ::time(nullptr); } //0 = failure condition -inline auto timestamp(const string& datetime) -> uint64_t { - static const uint monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - uint64_t timestamp = 0; +inline auto timestamp(const string& datetime) -> u64 { + static constexpr u32 monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + u64 timestamp = 0; if(datetime.match("??????????")) { return datetime.natural(); } if(datetime.match("????*")) { - uint year = datetime.slice(0, 4).natural(); + u32 year = datetime.slice(0, 4).natural(); if(year < 1970 || year > 2199) return 0; - for(uint y = 1970; y < year && y < 2999; y++) { - uint daysInYear = 365; + for(u32 y = 1970; y < year && y < 2999; y++) { + u32 daysInYear = 365; if(y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) daysInYear++; timestamp += daysInYear * 24 * 60 * 60; } } if(datetime.match("????-??*")) { - uint y = datetime.slice(0, 4).natural(); - uint month = datetime.slice(5, 2).natural(); + u32 y = datetime.slice(0, 4).natural(); + u32 month = datetime.slice(5, 2).natural(); if(month < 1 || month > 12) return 0; - for(uint m = 1; m < month && m < 12; m++) { - uint daysInMonth = monthDays[m - 1]; + for(u32 m = 1; m < month && m < 12; m++) { + u32 daysInMonth = monthDays[m - 1]; if(m == 2 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) daysInMonth++; timestamp += daysInMonth * 24 * 60 * 60; } } if(datetime.match("????-??-??*")) { - uint day = datetime.slice(8, 2).natural(); + u32 day = datetime.slice(8, 2).natural(); if(day < 1 || day > 31) return 0; timestamp += (day - 1) * 24 * 60 * 60; } if(datetime.match("????-??-?? ??*")) { - uint hour = datetime.slice(11, 2).natural(); + u32 hour = datetime.slice(11, 2).natural(); if(hour > 23) return 0; timestamp += hour * 60 * 60; } if(datetime.match("????-??-?? ??:??*")) { - uint minute = datetime.slice(14, 2).natural(); + u32 minute = datetime.slice(14, 2).natural(); if(minute > 59) return 0; timestamp += minute * 60; } if(datetime.match("????-??-?? ??:??:??*")) { - uint second = datetime.slice(17, 2).natural(); + u32 second = datetime.slice(17, 2).natural(); if(second > 59) return 0; timestamp += second; } @@ -99,38 +96,38 @@ inline auto timestamp(const string& datetime) -> uint64_t { } namespace utc { - inline auto timeinfo(uint64_t time = 0) -> chrono::timeinfo { + inline auto timeinfo(u64 time = 0) -> chrono::timeinfo { auto stamp = time ? (time_t)time : (time_t)timestamp(); auto info = gmtime(&stamp); return { - (uint)info->tm_year + 1900, - (uint)info->tm_mon + 1, - (uint)info->tm_mday, - (uint)info->tm_hour, - (uint)info->tm_min, - (uint)info->tm_sec, - (uint)info->tm_wday + (u32)info->tm_year + 1900, + (u32)info->tm_mon + 1, + (u32)info->tm_mday, + (u32)info->tm_hour, + (u32)info->tm_min, + (u32)info->tm_sec, + (u32)info->tm_wday }; } - inline auto year(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).year, 4, '0'); } - inline auto month(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).month, 2, '0'); } - inline auto day(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).day, 2, '0'); } - inline auto hour(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).hour, 2, '0'); } - inline auto minute(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).minute, 2, '0'); } - inline auto second(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).second, 2, '0'); } + inline auto year(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).year, 4, '0'); } + inline auto month(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).month, 2, '0'); } + inline auto day(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).day, 2, '0'); } + inline auto hour(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).hour, 2, '0'); } + inline auto minute(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).minute, 2, '0'); } + inline auto second(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).second, 2, '0'); } - inline auto date(uint64_t timestamp = 0) -> string { + inline auto date(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return {pad(t.year, 4, '0'), "-", pad(t.month, 2, '0'), "-", pad(t.day, 2, '0')}; } - inline auto time(uint64_t timestamp = 0) -> string { + inline auto time(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return {pad(t.hour, 2, '0'), ":", pad(t.minute, 2, '0'), ":", pad(t.second, 2, '0')}; } - inline auto datetime(uint64_t timestamp = 0) -> string { + inline auto datetime(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return { pad(t.year, 4, '0'), "-", pad(t.month, 2, '0'), "-", pad(t.day, 2, '0'), " ", @@ -140,38 +137,38 @@ namespace utc { } namespace local { - inline auto timeinfo(uint64_t time = 0) -> chrono::timeinfo { + inline auto timeinfo(u64 time = 0) -> chrono::timeinfo { auto stamp = time ? (time_t)time : (time_t)timestamp(); auto info = localtime(&stamp); return { - (uint)info->tm_year + 1900, - (uint)info->tm_mon + 1, - (uint)info->tm_mday, - (uint)info->tm_hour, - (uint)info->tm_min, - (uint)info->tm_sec, - (uint)info->tm_wday + (u32)info->tm_year + 1900, + (u32)info->tm_mon + 1, + (u32)info->tm_mday, + (u32)info->tm_hour, + (u32)info->tm_min, + (u32)info->tm_sec, + (u32)info->tm_wday }; } - inline auto year(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).year, 4, '0'); } - inline auto month(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).month, 2, '0'); } - inline auto day(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).day, 2, '0'); } - inline auto hour(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).hour, 2, '0'); } - inline auto minute(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).minute, 2, '0'); } - inline auto second(uint64_t timestamp = 0) -> string { return pad(timeinfo(timestamp).second, 2, '0'); } + inline auto year(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).year, 4, '0'); } + inline auto month(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).month, 2, '0'); } + inline auto day(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).day, 2, '0'); } + inline auto hour(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).hour, 2, '0'); } + inline auto minute(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).minute, 2, '0'); } + inline auto second(u64 timestamp = 0) -> string { return pad(timeinfo(timestamp).second, 2, '0'); } - inline auto date(uint64_t timestamp = 0) -> string { + inline auto date(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return {pad(t.year, 4, '0'), "-", pad(t.month, 2, '0'), "-", pad(t.day, 2, '0')}; } - inline auto time(uint64_t timestamp = 0) -> string { + inline auto time(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return {pad(t.hour, 2, '0'), ":", pad(t.minute, 2, '0'), ":", pad(t.second, 2, '0')}; } - inline auto datetime(uint64_t timestamp = 0) -> string { + inline auto datetime(u64 timestamp = 0) -> string { auto t = timeinfo(timestamp); return { pad(t.year, 4, '0'), "-", pad(t.month, 2, '0'), "-", pad(t.day, 2, '0'), " ", diff --git a/nall/cipher/chacha20.hpp b/nall/cipher/chacha20.hpp index 4dcb0afd8b..4d0088056a 100644 --- a/nall/cipher/chacha20.hpp +++ b/nall/cipher/chacha20.hpp @@ -7,8 +7,8 @@ namespace nall::Cipher { //64-bit nonce; 64-bit x 64-byte (256GB) counter struct ChaCha20 { - ChaCha20(uint256_t key, uint64_t nonce, uint64_t counter = 0) { - static const uint128_t sigma = 0x6b20657479622d323320646e61707865_u128; //"expand 32-byte k" + ChaCha20(u256 key, u64 nonce, u64 counter = 0) { + static const u128 sigma = 0x6b20657479622d323320646e61707865_u128; //"expand 32-byte k" input[ 0] = sigma >> 0; input[ 1] = sigma >> 32; @@ -30,8 +30,8 @@ struct ChaCha20 { offset = 0; } - auto encrypt(array_view input) -> vector { - vector output; + auto encrypt(array_view input) -> vector { + vector output; while(input) { if(!offset) { cipher(); @@ -44,16 +44,16 @@ struct ChaCha20 { return output; } - auto decrypt(array_view input) -> vector { + auto decrypt(array_view input) -> vector { return encrypt(input); //reciprocal cipher } //protected: - auto rol(uint32_t value, uint bits) -> uint32_t { + auto rol(u32 value, u32 bits) -> u32 { return value << bits | value >> 32 - bits; } - auto quarterRound(uint32_t x[16], uint a, uint b, uint c, uint d) -> void { + auto quarterRound(u32 x[16], u32 a, u32 b, u32 c, u32 d) -> void { x[a] += x[b]; x[d] = rol(x[d] ^ x[a], 16); x[c] += x[d]; x[b] = rol(x[b] ^ x[c], 12); x[a] += x[b]; x[d] = rol(x[d] ^ x[a], 8); @@ -62,7 +62,7 @@ struct ChaCha20 { auto cipher() -> void { memory::copy(block, input, 64); - for(uint n : range(10)) { + for(u32 n : range(10)) { quarterRound(block, 0, 4, 8, 12); quarterRound(block, 1, 5, 9, 13); quarterRound(block, 2, 6, 10, 14); @@ -75,33 +75,33 @@ struct ChaCha20 { } auto increment() -> void { - for(uint n : range(16)) { + for(u32 n : range(16)) { block[n] += input[n]; } if(!++input[12]) ++input[13]; } - uint32_t input[16]; - uint32_t block[16]; - uint64_t offset; + u32 input[16]; + u32 block[16]; + u64 offset; }; struct HChaCha20 : protected ChaCha20 { - HChaCha20(uint256_t key, uint128_t nonce) : ChaCha20(key, nonce >> 64, nonce >> 0) { + HChaCha20(u256 key, u128 nonce) : ChaCha20(key, nonce >> 64, nonce >> 0) { cipher(); } - auto key() const -> uint256_t { - uint256_t key = 0; - for(uint n : range(4)) key |= (uint256_t)block[ 0 + n] << (n + 0) * 32; - for(uint n : range(4)) key |= (uint256_t)block[12 + n] << (n + 4) * 32; + auto key() const -> u256 { + u256 key = 0; + for(u32 n : range(4)) key |= (u256)block[ 0 + n] << (n + 0) * 32; + for(u32 n : range(4)) key |= (u256)block[12 + n] << (n + 4) * 32; return key; } }; //192-bit nonce; 64-bit x 64-byte (256GB) counter struct XChaCha20 : ChaCha20 { - XChaCha20(uint256_t key, uint192_t nonce, uint64_t counter = 0): + XChaCha20(u256 key, u192 nonce, u64 counter = 0): ChaCha20(HChaCha20(key, nonce).key(), nonce >> 128, counter) { } }; diff --git a/nall/counting-sort.hpp b/nall/counting-sort.hpp index e4f7100e4d..0fad8d1429 100644 --- a/nall/counting-sort.hpp +++ b/nall/counting-sort.hpp @@ -5,15 +5,15 @@ namespace nall { //counting sort by powers of two: used to implement radix sort -template -auto counting_sort(T* output, const T* input, uint size) -> void { +template +auto counting_sort(T* output, const T* input, u32 size) -> void { static_assert(Bits >= 1 && Bits <= 20, "must be between 1 and 20 bits"); - enum : uint { Base = 1 << Bits, Mask = Base - 1 }; + enum : u32 { Base = 1 << Bits, Mask = Base - 1 }; - uint64_t count[Base] = {}, last = 0; - for(uint n : range(size)) ++count[(input[n] >> Shift) & Mask]; - for(uint n : range(Base)) last += count[n], count[n] = last - count[n]; - for(uint n : range(size)) output[count[(input[n] >> Shift) & Mask]++] = input[n]; + u64 count[Base] = {}, last = 0; + for(u32 n : range(size)) ++count[(input[n] >> Shift) & Mask]; + for(u32 n : range(Base)) last += count[n], count[n] = last - count[n]; + for(u32 n : range(size)) output[count[(input[n] >> Shift) & Mask]++] = input[n]; } } diff --git a/nall/database/odbc.hpp b/nall/database/odbc.hpp index bd3cba17e9..ba19541fb3 100644 --- a/nall/database/odbc.hpp +++ b/nall/database/odbc.hpp @@ -27,37 +27,37 @@ struct ODBC { return *this; } - auto columns() -> unsigned { + auto columns() -> u32 { SQLSMALLINT columns = 0; if(statement()) SQLNumResultCols(statement(), &columns); return columns; } - auto integer(unsigned column) -> int64_t { - if(auto value = _values(column)) return value.get(0); - int64_t value = 0; + auto integer(u32 column) -> s64 { + if(auto value = _values(column)) return value.get(0); + s64 value = 0; SQLGetData(statement(), 1 + column, SQL_C_SBIGINT, &value, 0, nullptr); - _values(column) = (int64_t)value; + _values(column) = (s64)value; return value; } - auto natural(unsigned column) -> uint64_t { - if(auto value = _values(column)) return value.get(0); - uint64_t value = 0; + auto natural(u32 column) -> u64 { + if(auto value = _values(column)) return value.get(0); + u64 value = 0; SQLGetData(statement(), 1 + column, SQL_C_UBIGINT, &value, 0, nullptr); - _values(column) = (uint64_t)value; + _values(column) = (u64)value; return value; } - auto real(unsigned column) -> double { - if(auto value = _values(column)) return value.get(0.0); - double value = 0.0; + auto real(u32 column) -> double { + if(auto value = _values(column)) return value.get(0.0); + f64 value = 0.0; SQLGetData(statement(), 1 + column, SQL_C_DOUBLE, &value, 0, nullptr); - _values(column) = (double)value; + _values(column) = (f64)value; return value; } - auto text(unsigned column) -> string { + auto text(u32 column) -> string { if(auto value = _values(column)) return value.get({}); string value; value.resize(65535); @@ -68,28 +68,28 @@ struct ODBC { return value; } - auto data(unsigned column) -> vector { - if(auto value = _values(column)) return value.get>({}); - vector value; + auto data(u32 column) -> vector { + if(auto value = _values(column)) return value.get>({}); + vector value; value.resize(65535); SQLLEN size = 0; SQLGetData(statement(), 1 + column, SQL_C_CHAR, value.data(), value.size(), &size); value.resize(size); - _values(column) = (vector)value; + _values(column) = (vector)value; return value; } - auto integer() -> int64_t { return integer(_output++); } - auto natural() -> uint64_t { return natural(_output++); } - auto real() -> double { return real(_output++); } + auto integer() -> s64 { return integer(_output++); } + auto natural() -> u64 { return natural(_output++); } + auto real() -> f64 { return real(_output++); } auto text() -> string { return text(_output++); } - auto data() -> vector { return data(_output++); } + auto data() -> vector { return data(_output++); } protected: virtual auto statement() -> SQLHANDLE { return _statement; } SQLHANDLE _statement = nullptr; - unsigned _output = 0; + u32 _output = 0; vector _values; //some ODBC drivers (eg MS-SQL) do not allow the same column to be read more than once }; @@ -129,23 +129,23 @@ struct ODBC { //if the bound paramters go out of scope before the query is executed, binding would reference dangling pointers //so to work around this, we cache all parameters inside Query until the query is executed - auto& bind(unsigned column, nullptr_t) { return _bindings.append({column, any{(nullptr_t)nullptr}}), *this; } - auto& bind(unsigned column, int32_t value) { return _bindings.append({column, any{(int32_t)value}}), *this; } - auto& bind(unsigned column, uint32_t value) { return _bindings.append({column, any{(uint32_t)value}}), *this; } - auto& bind(unsigned column, int64_t value) { return _bindings.append({column, any{(int64_t)value}}), *this; } - auto& bind(unsigned column, uint64_t value) { return _bindings.append({column, any{(uint64_t)value}}), *this; } - auto& bind(unsigned column, double value) { return _bindings.append({column, any{(double)value}}), *this; } - auto& bind(unsigned column, const string& value) { return _bindings.append({column, any{(string)value}}), *this; } - auto& bind(unsigned column, const vector& value) { return _bindings.append({column, any{(vector)value}}), *this; } + auto& bind(u32 column, nullptr_t) { return _bindings.append({column, any{(nullptr_t)nullptr}}), *this; } + auto& bind(u32 column, s32 value) { return _bindings.append({column, any{(s32)value}}), *this; } + auto& bind(u32 column, u32 value) { return _bindings.append({column, any{(u32)value}}), *this; } + auto& bind(u32 column, s64 value) { return _bindings.append({column, any{(s64)value}}), *this; } + auto& bind(u32 column, u64 value) { return _bindings.append({column, any{(u64)value}}), *this; } + auto& bind(u32 column, f64 value) { return _bindings.append({column, any{(f64)value}}), *this; } + auto& bind(u32 column, const string& value) { return _bindings.append({column, any{(string)value}}), *this; } + auto& bind(u32 column, const vector& value) { return _bindings.append({column, any{(vector)value}}), *this; } auto& bind(nullptr_t) { return bind(_input++, nullptr); } - auto& bind(int32_t value) { return bind(_input++, value); } - auto& bind(uint32_t value) { return bind(_input++, value); } - auto& bind(int64_t value) { return bind(_input++, value); } - auto& bind(uint64_t value) { return bind(_input++, value); } - auto& bind(double value) { return bind(_input++, value); } + auto& bind(s32 value) { return bind(_input++, value); } + auto& bind(u32 value) { return bind(_input++, value); } + auto& bind(s64 value) { return bind(_input++, value); } + auto& bind(u64 value) { return bind(_input++, value); } + auto& bind(f64 value) { return bind(_input++, value); } auto& bind(const string& value) { return bind(_input++, value); } - auto& bind(const vector& value) { return bind(_input++, value); } + auto& bind(const vector& value) { return bind(_input++, value); } auto step() -> bool { if(!_stepped) { @@ -153,22 +153,22 @@ struct ODBC { if(binding.value.is()) { SQLLEN length = SQL_NULL_DATA; SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_NUMERIC, SQL_NUMERIC, 0, 0, nullptr, 0, &length); - } else if(binding.value.is()) { - SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); - } else if(binding.value.is()) { - SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); - } else if(binding.value.is()) { - SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); - } else if(binding.value.is()) { - SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_UBIGINT, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); - } else if(binding.value.is()) { - SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &binding.value.get(), 0, nullptr); + } else if(binding.value.is()) { + SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); + } else if(binding.value.is()) { + SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); + } else if(binding.value.is()) { + SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); + } else if(binding.value.is()) { + SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_UBIGINT, SQL_INTEGER, 0, 0, &binding.value.get(), 0, nullptr); + } else if(binding.value.is()) { + SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &binding.value.get(), 0, nullptr); } else if(binding.value.is()) { auto& value = binding.value.get(); SQLLEN length = SQL_NTS; SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, value.size(), 0, (SQLPOINTER)value.data(), 0, &length); - } else if(binding.value.is>()) { - auto& value = binding.value.get>(); + } else if(binding.value.is>()) { + auto& value = binding.value.get>(); SQLLEN length = value.size(); SQLBindParameter(_statement, 1 + binding.column, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARBINARY, value.size(), 0, (SQLPOINTER)value.data(), 0, &length); } @@ -210,13 +210,13 @@ struct ODBC { } struct Binding { - unsigned column; + u32 column; any value; }; vector _bindings; SQLRETURN _result = SQL_SUCCESS; - unsigned _input = 0; + u32 _input = 0; bool _stepped = false; }; diff --git a/nall/database/sqlite3.hpp b/nall/database/sqlite3.hpp index 10ab87299b..ac53aec0c9 100644 --- a/nall/database/sqlite3.hpp +++ b/nall/database/sqlite3.hpp @@ -32,27 +32,27 @@ struct SQLite3 { return sqlite3_data_count(statement()); } - auto columns() -> uint { + auto columns() -> u32 { return sqlite3_column_count(statement()); } - auto boolean(uint column) -> bool { + auto boolean(u32 column) -> bool { return sqlite3_column_int64(statement(), column) != 0; } - auto integer(uint column) -> int64_t { + auto integer(u32 column) -> s64 { return sqlite3_column_int64(statement(), column); } - auto natural(uint column) -> uint64_t { + auto natural(u32 column) -> u64 { return sqlite3_column_int64(statement(), column); } - auto real(uint column) -> double { + auto real(u32 column) -> f64 { return sqlite3_column_double(statement(), column); } - auto string(uint column) -> nall::string { + auto string(u32 column) -> nall::string { nall::string result; if(auto text = sqlite3_column_text(statement(), column)) { result.resize(sqlite3_column_bytes(statement(), column)); @@ -61,8 +61,8 @@ struct SQLite3 { return result; } - auto data(uint column) -> vector { - vector result; + auto data(u32 column) -> vector { + vector result; if(auto data = sqlite3_column_blob(statement(), column)) { result.resize(sqlite3_column_bytes(statement(), column)); memory::copy(result.data(), data, result.size()); @@ -71,18 +71,18 @@ struct SQLite3 { } auto boolean() -> bool { return boolean(_output++); } - auto integer() -> int64_t { return integer(_output++); } - auto natural() -> uint64_t { return natural(_output++); } - auto real() -> double { return real(_output++); } + auto integer() -> s64 { return integer(_output++); } + auto natural() -> u64 { return natural(_output++); } + auto real() -> f64 { return real(_output++); } auto string() -> nall::string { return string(_output++); } - auto data() -> vector { return data(_output++); } + auto data() -> vector { return data(_output++); } protected: virtual auto statement() -> sqlite3_stmt* { return _statement; } sqlite3_stmt* _statement = nullptr; - int _response = SQLITE_OK; - uint _output = 0; + s32 _response = SQLITE_OK; + u32 _output = 0; }; struct Query : Statement { @@ -105,35 +105,35 @@ struct SQLite3 { return *this; } - auto& bind(uint column, nullptr_t) { sqlite3_bind_null(_statement, 1 + column); return *this; } - auto& bind(uint column, bool value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } - auto& bind(uint column, int32_t value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } - auto& bind(uint column, uint32_t value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } - auto& bind(uint column, int64_t value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, uint64_t value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, intmax value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, uintmax value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, nall::boolean value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, nall::integer value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, nall::natural value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } - auto& bind(uint column, double value) { sqlite3_bind_double(_statement, 1 + column, value); return *this; } - auto& bind(uint column, const nall::string& value) { sqlite3_bind_text(_statement, 1 + column, value.data(), value.size(), SQLITE_TRANSIENT); return *this; } - auto& bind(uint column, const vector& value) { sqlite3_bind_blob(_statement, 1 + column, value.data(), value.size(), SQLITE_TRANSIENT); return *this; } + auto& bind(u32 column, nullptr_t) { sqlite3_bind_null(_statement, 1 + column); return *this; } + auto& bind(u32 column, bool value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, s32 value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, u32 value) { sqlite3_bind_int(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, s64 value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, u64 value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, intmax value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, uintmax value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, nall::boolean value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, nall::integer value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, nall::natural value) { sqlite3_bind_int64(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, f64 value) { sqlite3_bind_double(_statement, 1 + column, value); return *this; } + auto& bind(u32 column, const nall::string& value) { sqlite3_bind_text(_statement, 1 + column, value.data(), value.size(), SQLITE_TRANSIENT); return *this; } + auto& bind(u32 column, const vector& value) { sqlite3_bind_blob(_statement, 1 + column, value.data(), value.size(), SQLITE_TRANSIENT); return *this; } auto& bind(nullptr_t) { return bind(_input++, nullptr); } auto& bind(bool value) { return bind(_input++, value); } - auto& bind(int32_t value) { return bind(_input++, value); } - auto& bind(uint32_t value) { return bind(_input++, value); } - auto& bind(int64_t value) { return bind(_input++, value); } - auto& bind(uint64_t value) { return bind(_input++, value); } + auto& bind(s32 value) { return bind(_input++, value); } + auto& bind(u32 value) { return bind(_input++, value); } + auto& bind(s64 value) { return bind(_input++, value); } + auto& bind(u64 value) { return bind(_input++, value); } auto& bind(intmax value) { return bind(_input++, value); } auto& bind(uintmax value) { return bind(_input++, value); } auto& bind(nall::boolean value) { return bind(_input++, value); } auto& bind(nall::integer value) { return bind(_input++, value); } auto& bind(nall::natural value) { return bind(_input++, value); } - auto& bind(double value) { return bind(_input++, value); } + auto& bind(f64 value) { return bind(_input++, value); } auto& bind(const nall::string& value) { return bind(_input++, value); } - auto& bind(const vector& value) { return bind(_input++, value); } + auto& bind(const vector& value) { return bind(_input++, value); } auto step() -> bool { _stepped = true; @@ -160,7 +160,7 @@ struct SQLite3 { return _statement; } - uint _input = 0; + u32 _input = 0; bool _stepped = false; }; @@ -196,7 +196,7 @@ struct SQLite3 { return query; } - auto lastInsertID() const -> uint64_t { + auto lastInsertID() const -> u64 { return _database ? sqlite3_last_insert_rowid(_database) : 0; } diff --git a/nall/decode/base.hpp b/nall/decode/base.hpp index d20f1a5e4f..f7932548c9 100644 --- a/nall/decode/base.hpp +++ b/nall/decode/base.hpp @@ -4,7 +4,7 @@ namespace nall::Decode { -template inline auto Base(const string& value) -> T { +template inline auto Base(const string& value) -> T { static const string format = Bits == 2 ? "01" : Bits == 8 ? "01234567" @@ -19,10 +19,10 @@ template inline auto Base(const string& value) -> T { : Bits == 85 ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%()+,-.:;=@[]^_`{|}~" //\ "&'*/<>? : ""; static bool initialized = false; - static uint8_t lookup[256] = {0}; + static u8 lookup[256] = {}; if(!initialized) { initialized = true; - for(uint n : range(format.size())) { + for(u32 n : range(format.size())) { lookup[format[n]] = n; } } diff --git a/nall/decode/base64.hpp b/nall/decode/base64.hpp index a613d346ca..70ea759504 100644 --- a/nall/decode/base64.hpp +++ b/nall/decode/base64.hpp @@ -2,22 +2,22 @@ namespace nall::Decode { -inline auto Base64(const string& text) -> vector { +inline auto Base64(const string& text) -> vector { static bool initialized = false; - static uint8_t lookup[256] = {0}; + static u8 lookup[256] = {}; if(!initialized) { initialized = true; - for(uint n : range(26)) lookup['A' + n] = n; - for(uint n : range(26)) lookup['a' + n] = n + 26; - for(uint n : range(10)) lookup['0' + n] = n + 52; + for(u32 n : range(26)) lookup['A' + n] = n; + for(u32 n : range(26)) lookup['a' + n] = n + 26; + for(u32 n : range(10)) lookup['0' + n] = n + 52; lookup['+'] = lookup['-'] = 62; lookup['/'] = lookup['_'] = 63; } - vector result; - uint8_t buffer, output; - for(uint n : range(text.size())) { - uint8_t buffer = lookup[text[n]]; + vector result; + u8 buffer, output; + for(u32 n : range(text.size())) { + u8 buffer = lookup[text[n]]; switch(n & 3) { case 0: diff --git a/nall/decode/bmp.hpp b/nall/decode/bmp.hpp index fcfcf40751..271cb1d246 100644 --- a/nall/decode/bmp.hpp +++ b/nall/decode/bmp.hpp @@ -5,7 +5,7 @@ namespace nall::Decode { struct BMP { BMP() = default; BMP(const string& filename) { load(filename); } - BMP(const uint8_t* data, uint size) { load(data, size); } + BMP(const u8* data, u32 size) { load(data, size); } explicit operator bool() const { return _data; } @@ -13,45 +13,45 @@ struct BMP { if(_data) { delete[] _data; _data = nullptr; } } - auto data() -> uint32_t* { return _data; } - auto data() const -> const uint32_t* { return _data; } - auto width() const -> uint { return _width; } - auto height() const -> uint { return _height; } + auto data() -> u32* { return _data; } + auto data() const -> const u32* { return _data; } + auto width() const -> u32 { return _width; } + auto height() const -> u32 { return _height; } auto load(const string& filename) -> bool { auto buffer = file::read(filename); return load(buffer.data(), buffer.size()); } - auto load(const uint8_t* data, uint size) -> bool { + auto load(const u8* data, u32 size) -> bool { if(size < 0x36) return false; - const uint8_t* p = data; + const u8* p = data; if(read(p, 2) != 0x4d42) return false; //signature read(p, 8); - uint offset = read(p, 4); + u32 offset = read(p, 4); if(read(p, 4) != 40) return false; //DIB size - int width = (int32_t)read(p, 4); + s32 width = (s32)read(p, 4); if(width < 0) width = -width; - int height = (int32_t)read(p, 4); + s32 height = (s32)read(p, 4); bool flip = height >= 0; if(height < 0) height = -height; read(p, 2); - uint bitsPerPixel = read(p, 2); + u32 bitsPerPixel = read(p, 2); if(bitsPerPixel != 24 && bitsPerPixel != 32) return false; if(read(p, 4) != 0) return false; //compression type _width = width; _height = height; - _data = new uint32_t[width * height]; + _data = new u32[width * height]; - uint bytesPerPixel = bitsPerPixel / 8; - uint alignedWidth = width * bytesPerPixel; - uint paddingLength = 0; + u32 bytesPerPixel = bitsPerPixel / 8; + u32 alignedWidth = width * bytesPerPixel; + u32 paddingLength = 0; while(alignedWidth % 4) alignedWidth++, paddingLength++; p = data + offset; for(auto y : range(height)) { - uint32_t* output = flip ? _data + (height - 1 - y) * width : _data + y * width; + u32* output = flip ? _data + (height - 1 - y) * width : _data + y * width; for(auto x : range(width)) { *output++ = read(p, bytesPerPixel) | (bitsPerPixel == 24 ? 255u << 24 : 0); } @@ -62,13 +62,13 @@ struct BMP { } private: - uint32_t* _data = nullptr; - uint _width = 0; - uint _height = 0; + u32* _data = nullptr; + u32 _width = 0; + u32 _height = 0; - auto read(const uint8_t*& buffer, uint length) -> uint64_t { - uint64_t result = 0; - for(uint n : range(length)) result |= (uint64_t)*buffer++ << (n << 3); + auto read(const u8*& buffer, u32 length) -> u64 { + u64 result = 0; + for(u32 n : range(length)) result |= (u64)*buffer++ << (n << 3); return result; } }; diff --git a/nall/decode/bwt.hpp b/nall/decode/bwt.hpp index 5aeb1f8cd2..c3691473c5 100644 --- a/nall/decode/bwt.hpp +++ b/nall/decode/bwt.hpp @@ -6,37 +6,37 @@ namespace nall::Decode { -inline auto BWT(array_view input) -> vector { - vector output; +inline auto BWT(array_view input) -> vector { + vector output; - uint size = 0; - for(uint byte : range(8)) size |= *input++ << byte * 8; + u32 size = 0; + for(u32 byte : range(8)) size |= *input++ << byte * 8; output.resize(size); - uint I = 0; - for(uint byte : range(8)) I |= *input++ << byte * 8; + u32 I = 0; + for(u32 byte : range(8)) I |= *input++ << byte * 8; auto suffixes = SuffixArray(input); auto L = input; - auto F = new uint8_t[size]; - for(uint offset : range(size)) F[offset] = L[suffixes[offset + 1]]; + auto F = new u8[size]; + for(u32 offset : range(size)) F[offset] = L[suffixes[offset + 1]]; - uint64_t K[256] = {}; - auto C = new int[size]; - for(uint i : range(size)) { + u64 K[256] = {}; + auto C = new s32[size]; + for(u32 i : range(size)) { C[i] = K[L[i]]; K[L[i]]++; } - int M[256]; - memory::fill(M, 256, -1); - for(uint i : range(size)) { + s32 M[256]; + memory::fill(M, 256, -1); + for(u32 i : range(size)) { if(M[F[i]] == -1) M[F[i]] = i; } - uint i = I; - for(uint j : reverse(range(size))) { + u32 i = I; + for(u32 j : reverse(range(size))) { output[j] = L[i]; i = C[i] + M[L[i]]; } diff --git a/nall/decode/cue.hpp b/nall/decode/cue.hpp index 0c22d2743a..91e72f79b3 100644 --- a/nall/decode/cue.hpp +++ b/nall/decode/cue.hpp @@ -9,26 +9,26 @@ namespace nall::Decode { struct CUE { struct Index { - auto sectorCount() const -> uint; + auto sectorCount() const -> u32; - int number; //01-99 - int lba = -1; - int end = -1; + s32 number; //01-99 + s32 lba = -1; + s32 end = -1; }; struct Track { - auto sectorCount() const -> uint; - auto sectorSize() const -> uint; + auto sectorCount() const -> u32; + auto sectorSize() const -> u32; - int number; //01-99 + s32 number; //01-99 string type; vector indices; - maybe pregap; - maybe postgap; + maybe pregap; + maybe postgap; }; struct File { - auto sectorCount() const -> uint; + auto sectorCount() const -> u32; auto scan(const string& pathname) -> bool; string name; @@ -37,21 +37,21 @@ struct CUE { }; auto load(const string& location) -> bool; - auto sectorCount() const -> uint; + auto sectorCount() const -> u32; vector files; private: - auto loadFile(vector& lines, uint& offset) -> File; - auto loadTrack(vector& lines, uint& offset) -> Track; - auto loadIndex(vector& lines, uint& offset) -> Index; - auto toLBA(const string& msf) -> uint; + auto loadFile(vector& lines, u32& offset) -> File; + auto loadTrack(vector& lines, u32& offset) -> Track; + auto loadIndex(vector& lines, u32& offset) -> Index; + auto toLBA(const string& msf) -> u32; }; inline auto CUE::load(const string& location) -> bool { auto lines = string::read(location).replace("\r", "").split("\n"); - uint offset = 0; + u32 offset = 0; while(offset < lines.size()) { lines[offset].strip(); if(lines[offset].ibeginsWith("FILE ")) { @@ -84,7 +84,7 @@ inline auto CUE::load(const string& location) -> bool { return true; } -inline auto CUE::loadFile(vector& lines, uint& offset) -> File { +inline auto CUE::loadFile(vector& lines, u32& offset) -> File { File file; lines[offset].itrimLeft("FILE ", 1L).strip(); @@ -108,7 +108,7 @@ inline auto CUE::loadFile(vector& lines, uint& offset) -> File { return file; } -inline auto CUE::loadTrack(vector& lines, uint& offset) -> Track { +inline auto CUE::loadTrack(vector& lines, u32& offset) -> Track { Track track; lines[offset].itrimLeft("TRACK ", 1L).strip(); @@ -141,7 +141,7 @@ inline auto CUE::loadTrack(vector& lines, uint& offset) -> Track { return track; } -inline auto CUE::loadIndex(vector& lines, uint& offset) -> Index { +inline auto CUE::loadIndex(vector& lines, u32& offset) -> Index { Index index; lines[offset].itrimLeft("INDEX ", 1L); @@ -155,15 +155,15 @@ inline auto CUE::loadIndex(vector& lines, uint& offset) -> Index { return index; } -inline auto CUE::toLBA(const string& msf) -> uint { - uint m = msf.split(":")(0).natural(); - uint s = msf.split(":")(1).natural(); - uint f = msf.split(":")(2).natural(); +inline auto CUE::toLBA(const string& msf) -> u32 { + u32 m = msf.split(":")(0).natural(); + u32 s = msf.split(":")(1).natural(); + u32 f = msf.split(":")(2).natural(); return m * 60 * 75 + s * 75 + f; } -inline auto CUE::sectorCount() const -> uint { - uint count = 0; +inline auto CUE::sectorCount() const -> u32 { + u32 count = 0; for(auto& file : files) count += file.sectorCount(); return count; } @@ -172,7 +172,7 @@ inline auto CUE::File::scan(const string& pathname) -> bool { string location = {Location::path(pathname), name}; if(!file::exists(location)) return false; - uint64_t size = 0; + u64 size = 0; if(type == "binary") { size = file::size(location); @@ -200,19 +200,19 @@ inline auto CUE::File::scan(const string& pathname) -> bool { return true; } -inline auto CUE::File::sectorCount() const -> uint { - uint count = 0; +inline auto CUE::File::sectorCount() const -> u32 { + u32 count = 0; for(auto& track : tracks) count += track.sectorCount(); return count; } -inline auto CUE::Track::sectorCount() const -> uint { - uint count = 0; +inline auto CUE::Track::sectorCount() const -> u32 { + u32 count = 0; for(auto& index : indices) count += index.sectorCount(); return count; } -inline auto CUE::Track::sectorSize() const -> uint { +inline auto CUE::Track::sectorSize() const -> u32 { if(type == "mode1/2048") return 2048; if(type == "mode1/2352") return 2352; if(type == "mode2/2352") return 2352; @@ -220,7 +220,7 @@ inline auto CUE::Track::sectorSize() const -> uint { return 0; } -inline auto CUE::Index::sectorCount() const -> uint { +inline auto CUE::Index::sectorCount() const -> u32 { if(end < 0) return 0; return end - lba + 1; } diff --git a/nall/decode/gzip.hpp b/nall/decode/gzip.hpp index 20f754cd76..b4b5ce7677 100644 --- a/nall/decode/gzip.hpp +++ b/nall/decode/gzip.hpp @@ -9,11 +9,11 @@ struct GZIP { inline ~GZIP(); inline auto decompress(const string& filename) -> bool; - inline auto decompress(const uint8_t* data, uint size) -> bool; + inline auto decompress(const u8* data, u32 size) -> bool; string filename; - uint8_t* data = nullptr; - uint size = 0; + u8* data = nullptr; + u32 size = 0; }; GZIP::~GZIP() { @@ -27,34 +27,34 @@ auto GZIP::decompress(const string& filename) -> bool { return false; } -auto GZIP::decompress(const uint8_t* data, uint size) -> bool { +auto GZIP::decompress(const u8* data, u32 size) -> bool { if(size < 18) return false; if(data[0] != 0x1f) return false; if(data[1] != 0x8b) return false; - uint cm = data[2]; - uint flg = data[3]; - uint mtime = data[4]; + u32 cm = data[2]; + u32 flg = data[3]; + u32 mtime = data[4]; mtime |= data[5] << 8; mtime |= data[6] << 16; mtime |= data[7] << 24; - uint xfl = data[8]; - uint os = data[9]; - uint p = 10; - uint isize = data[size - 4]; + u32 xfl = data[8]; + u32 os = data[9]; + u32 p = 10; + u32 isize = data[size - 4]; isize |= data[size - 3] << 8; isize |= data[size - 2] << 16; isize |= data[size - 1] << 24; filename = ""; if(flg & 0x04) { //FEXTRA - uint xlen = data[p + 0]; + u32 xlen = data[p + 0]; xlen |= data[p + 1] << 8; p += 2 + xlen; } if(flg & 0x08) { //FNAME char buffer[PATH_MAX]; - for(uint n = 0; n < PATH_MAX; n++, p++) { + for(u32 n = 0; n < PATH_MAX; n++, p++) { buffer[n] = data[p]; if(data[p] == 0) break; } @@ -71,7 +71,7 @@ auto GZIP::decompress(const uint8_t* data, uint size) -> bool { } this->size = isize; - this->data = new uint8_t[this->size]; + this->data = new u8[this->size]; return inflate(this->data, this->size, data + p, size - p - 8); } diff --git a/nall/decode/html.hpp b/nall/decode/html.hpp index ccec3e8dea..2cfd072db5 100644 --- a/nall/decode/html.hpp +++ b/nall/decode/html.hpp @@ -4,7 +4,7 @@ namespace nall::Decode { inline auto HTML(const string& input) -> string { string output; - for(uint n = 0; n < input.size();) { + for(u32 n = 0; n < input.size();) { if(input[n] == '&') { if(input(n + 1) == 'a' && input(n + 2) == 'm' && input(n + 3) == 'p' && input(n + 4) == ';') { output.append('&'); diff --git a/nall/decode/huffman.hpp b/nall/decode/huffman.hpp index cb8c3929d6..5f0f39c6b5 100644 --- a/nall/decode/huffman.hpp +++ b/nall/decode/huffman.hpp @@ -2,26 +2,26 @@ namespace nall::Decode { -inline auto Huffman(array_view input) -> vector { - vector output; +inline auto Huffman(array_view input) -> vector { + vector output; - uint size = 0; - for(uint byte : range(8)) size |= *input++ << byte * 8; + u32 size = 0; + for(u32 byte : range(8)) size |= *input++ << byte * 8; output.reserve(size); - uint byte = 0, bits = 0; + u32 byte = 0, bits = 0; auto read = [&]() -> bool { if(bits == 0) bits = 8, byte = *input++; return byte >> --bits & 1; }; - uint nodes[256][2] = {}; - for(uint offset : range(256)) { - for(uint index : range(9)) nodes[offset][0] = nodes[offset][0] << 1 | read(); - for(uint index : range(9)) nodes[offset][1] = nodes[offset][1] << 1 | read(); + u32 nodes[256][2] = {}; + for(u32 offset : range(256)) { + for(u32 index : range(9)) nodes[offset][0] = nodes[offset][0] << 1 | read(); + for(u32 index : range(9)) nodes[offset][1] = nodes[offset][1] << 1 | read(); } - uint node = 511; + u32 node = 511; while(output.size() < size) { node = nodes[node - 256][read()]; if(node < 256) { diff --git a/nall/decode/inflate.hpp b/nall/decode/inflate.hpp index 0f659b709a..5e1d7d2d19 100644 --- a/nall/decode/inflate.hpp +++ b/nall/decode/inflate.hpp @@ -8,24 +8,18 @@ namespace nall::Decode { namespace puff { - inline auto puff( - unsigned char* dest, unsigned long* destlen, - unsigned char* source, unsigned long* sourcelen - ) -> int; + inline auto puff(u8* dest, u32* destlen, u8* source, u32* sourcelen) -> s32; } -inline auto inflate( - uint8_t* target, uint targetLength, - const uint8_t* source, uint sourceLength -) -> bool { - unsigned long tl = targetLength, sl = sourceLength; - int result = puff::puff((unsigned char*)target, &tl, (unsigned char*)source, &sl); +inline auto inflate(u8* target, u32 targetLength, const u8* source, u32 sourceLength) -> bool { + u32 tl = targetLength, sl = sourceLength; + s32 result = puff::puff((u8*)target, &tl, (u8*)source, &sl); return result == 0; } namespace puff { -enum : uint { +enum : u32 { MAXBITS = 15, MAXLCODES = 286, MAXDCODES = 30, @@ -34,42 +28,42 @@ enum : uint { }; struct state { - unsigned char* out; - unsigned long outlen; - unsigned long outcnt; + u8* out; + u32 outlen; + u32 outcnt; - unsigned char* in; - unsigned long inlen; - unsigned long incnt; - int bitbuf; - int bitcnt; + u8* in; + u32 inlen; + u32 incnt; + s32 bitbuf; + s32 bitcnt; jmp_buf env; }; struct huffman { - short* count; - short* symbol; + s16* count; + s16* symbol; }; -inline auto bits(state* s, int need) -> int { - long val; +inline auto bits(state* s, s32 need) -> s32 { + s32 val; val = s->bitbuf; while(s->bitcnt < need) { if(s->incnt == s->inlen) longjmp(s->env, 1); - val |= (long)(s->in[s->incnt++]) << s->bitcnt; + val |= (s32)(s->in[s->incnt++]) << s->bitcnt; s->bitcnt += 8; } - s->bitbuf = (int)(val >> need); + s->bitbuf = (s32)(val >> need); s->bitcnt -= need; - return (int)(val & ((1L << need) - 1)); + return (s32)(val & ((1L << need) - 1)); } -inline auto stored(state* s) -> int { - uint len; +inline auto stored(state* s) -> s32 { + u32 len; s->bitbuf = 0; s->bitcnt = 0; @@ -93,9 +87,9 @@ inline auto stored(state* s) -> int { return 0; } -inline auto decode(state* s, huffman* h) -> int { - int len, code, first, count, index, bitbuf, left; - short* next; +inline auto decode(state* s, huffman* h) -> s32 { + s32 len, code, first, count, index, bitbuf, left; + s16* next; bitbuf = s->bitbuf; left = s->bitcnt; @@ -128,9 +122,9 @@ inline auto decode(state* s, huffman* h) -> int { return -10; } -inline auto construct(huffman* h, short* length, int n) -> int { - int symbol, len, left; - short offs[MAXBITS + 1]; +inline auto construct(huffman* h, s16* length, s32 n) -> s32 { + s32 symbol, len, left; + s16 offs[MAXBITS + 1]; for(len = 0; len <= MAXBITS; len++) h->count[len] = 0; for(symbol = 0; symbol < n; symbol++) h->count[length[symbol]]++; @@ -153,23 +147,23 @@ inline auto construct(huffman* h, short* length, int n) -> int { return left; } -inline auto codes(state* s, huffman* lencode, huffman* distcode) -> int { - int symbol, len; - uint dist; - static const short lens[29] = { +inline auto codes(state* s, huffman* lencode, huffman* distcode) -> s32 { + s32 symbol, len; + u32 dist; + static const s16 lens[29] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 }; - static const short lext[29] = { + static const s16 lext[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; - static const short dists[30] = { + static const s16 dists[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 }; - static const short dext[30] = { + static const s16 dext[30] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 @@ -215,15 +209,15 @@ inline auto codes(state* s, huffman* lencode, huffman* distcode) -> int { return 0; } -inline auto fixed(state* s) -> int { - static int virgin = 1; - static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; - static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; +inline auto fixed(state* s) -> s32 { + static s32 virgin = 1; + static s16 lencnt[MAXBITS + 1], lensym[FIXLCODES]; + static s16 distcnt[MAXBITS + 1], distsym[MAXDCODES]; static huffman lencode, distcode; if(virgin) { - int symbol = 0; - short lengths[FIXLCODES]; + s32 symbol = 0; + s16 lengths[FIXLCODES]; lencode.count = lencnt; lencode.symbol = lensym; @@ -245,13 +239,13 @@ inline auto fixed(state* s) -> int { return codes(s, &lencode, &distcode); } -inline auto dynamic(state* s) -> int { - int nlen, ndist, ncode, index, err; - short lengths[MAXCODES]; - short lencnt[MAXBITS + 1], lensym[MAXLCODES]; - short distcnt[MAXBITS + 1], distsym[MAXDCODES]; +inline auto dynamic(state* s) -> s32 { + s32 nlen, ndist, ncode, index, err; + s16 lengths[MAXCODES]; + s16 lencnt[MAXBITS + 1], lensym[MAXLCODES]; + s16 distcnt[MAXBITS + 1], distsym[MAXDCODES]; huffman lencode, distcode; - static const short order[19] = { + static const s16 order[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; @@ -273,7 +267,7 @@ inline auto dynamic(state* s) -> int { index = 0; while(index < nlen + ndist) { - int symbol, len; + s32 symbol, len; symbol = decode(s, &lencode); if(symbol < 16) { @@ -305,12 +299,9 @@ inline auto dynamic(state* s) -> int { return codes(s, &lencode, &distcode); } -inline auto puff( - unsigned char* dest, unsigned long* destlen, - unsigned char* source, unsigned long* sourcelen -) -> int { +inline auto puff(u8* dest, u32* destlen, u8* source, u32* sourcelen) -> s32 { state s; - int last, type, err; + s32 last, type, err; s.out = dest; s.outlen = *destlen; diff --git a/nall/decode/lzsa.hpp b/nall/decode/lzsa.hpp index a0e9c9c440..df5790e9a0 100644 --- a/nall/decode/lzsa.hpp +++ b/nall/decode/lzsa.hpp @@ -4,18 +4,18 @@ namespace nall::Decode { -inline auto LZSA(array_view input) -> vector { - vector output; - uint index = 0; +inline auto LZSA(array_view input) -> vector { + vector output; + u32 index = 0; - uint size = 0; - for(uint byte : range(8)) size |= *input++ << byte * 8; + u32 size = 0; + for(u32 byte : range(8)) size |= *input++ << byte * 8; output.resize(size); - auto load = [&]() -> vector { - uint size = 0; - for(uint byte : range(8)) size |= *input++ << byte * 8; - vector buffer; + auto load = [&]() -> vector { + u32 size = 0; + for(u32 byte : range(8)) size |= *input++ << byte * 8; + vector buffer; buffer.reserve(size); while(size--) buffer.append(*input++); return buffer; @@ -27,29 +27,29 @@ inline auto LZSA(array_view input) -> vector { auto offsets = Decode::Huffman(load()); auto flagData = flags.data(); - uint byte = 0, bits = 0; + u32 byte = 0, bits = 0; auto flagRead = [&]() -> bool { if(bits == 0) bits = 8, byte = *flagData++; return byte >> --bits & 1; }; auto literalData = literals.data(); - auto literalRead = [&]() -> uint8_t { + auto literalRead = [&]() -> u8 { return *literalData++; }; auto lengthData = lengths.data(); - auto lengthRead = [&]() -> uint64_t { - uint byte = *lengthData++, bytes = 1; + auto lengthRead = [&]() -> u64 { + u32 byte = *lengthData++, bytes = 1; while(!(byte & 1)) byte >>= 1, bytes++; - uint length = byte >> 1, shift = 8 - bytes; + u32 length = byte >> 1, shift = 8 - bytes; while(--bytes) length |= *lengthData++ << shift, shift += 8; return length; }; auto offsetData = offsets.data(); - auto offsetRead = [&]() -> uint { - uint offset = 0; + auto offsetRead = [&]() -> u32 { + u32 offset = 0; offset |= *offsetData++ << 0; if(index < 1 << 8) return offset; offset |= *offsetData++ << 8; if(index < 1 << 16) return offset; offset |= *offsetData++ << 16; if(index < 1 << 24) return offset; @@ -60,8 +60,8 @@ inline auto LZSA(array_view input) -> vector { if(!flagRead()) { output[index++] = literalRead(); } else { - uint length = lengthRead() + 6; - uint offset = index - offsetRead(); + u32 length = lengthRead() + 6; + u32 offset = index - offsetRead(); while(length--) output[index++] = output[offset++]; } } diff --git a/nall/decode/mtf.hpp b/nall/decode/mtf.hpp index d70e16834b..3e2a46cae1 100644 --- a/nall/decode/mtf.hpp +++ b/nall/decode/mtf.hpp @@ -4,16 +4,16 @@ namespace nall::Decode { -inline auto MTF(array_view input) -> vector { - vector output; +inline auto MTF(array_view input) -> vector { + vector output; output.resize(input.size()); - uint8_t order[256]; - for(uint n : range(256)) order[n] = n; + u8 order[256]; + for(u32 n : range(256)) order[n] = n; - for(uint offset : range(input.size())) { - uint data = input[offset]; - uint value = order[data]; + for(u32 offset : range(input.size())) { + u32 data = input[offset]; + u32 value = order[data]; output[offset] = value; memory::move(&order[1], &order[0], data); order[0] = value; diff --git a/nall/decode/png.hpp b/nall/decode/png.hpp index 775f84d4b3..75c6e81651 100644 --- a/nall/decode/png.hpp +++ b/nall/decode/png.hpp @@ -10,48 +10,48 @@ struct PNG { ~PNG(); auto load(const string& filename) -> bool; - auto load(const uint8_t* sourceData, uint sourceSize) -> bool; - auto readbits(const uint8_t*& data) -> uint; + auto load(const u8* sourceData, u32 sourceSize) -> bool; + auto readbits(const u8*& data) -> u32; struct Info { - uint width; - uint height; - uint bitDepth; + u32 width; + u32 height; + u32 bitDepth; //colorType: //0 = L (luma) //2 = R,G,B //3 = P (palette) //4 = L,A //6 = R,G,B,A - uint colorType; - uint compressionMethod; - uint filterType; - uint interlaceMethod; + u32 colorType; + u32 compressionMethod; + u32 filterType; + u32 interlaceMethod; - uint bytesPerPixel; - uint pitch; + u32 bytesPerPixel; + u32 pitch; - uint8_t palette[256][3]; + u8 palette[256][3]; } info; - uint8_t* data = nullptr; - uint size = 0; + u8* data = nullptr; + u32 size = 0; - uint bitpos = 0; + u32 bitpos = 0; protected: - enum class FourCC : uint { + enum class FourCC : u32 { IHDR = 0x49484452, PLTE = 0x504c5445, IDAT = 0x49444154, IEND = 0x49454e44, }; - auto interlace(uint pass, uint index) -> uint; - auto inflateSize() -> uint; - auto deinterlace(const uint8_t*& inputData, uint pass) -> bool; - auto filter(uint8_t* outputData, const uint8_t* inputData, uint width, uint height) -> bool; - auto read(const uint8_t* data, uint length) -> uint; + auto interlace(u32 pass, u32 index) -> u32; + auto inflateSize() -> u32; + auto deinterlace(const u8*& inputData, u32 pass) -> bool; + auto filter(u8* outputData, const u8* inputData, u32 width, u32 height) -> bool; + auto read(const u8* data, u32 length) -> u32; }; inline PNG::PNG() { @@ -68,21 +68,21 @@ inline auto PNG::load(const string& filename) -> bool { return false; } -inline auto PNG::load(const uint8_t* sourceData, uint sourceSize) -> bool { +inline auto PNG::load(const u8* sourceData, u32 sourceSize) -> bool { if(sourceSize < 8) return false; if(read(sourceData + 0, 4) != 0x89504e47) return false; if(read(sourceData + 4, 4) != 0x0d0a1a0a) return false; - uint8_t* compressedData = nullptr; - uint compressedSize = 0; + u8* compressedData = nullptr; + u32 compressedSize = 0; - uint offset = 8; + u32 offset = 8; while(offset < sourceSize) { - uint length = read(sourceData + offset + 0, 4); - uint fourCC = read(sourceData + offset + 4, 4); - uint checksum = read(sourceData + offset + 8 + length, 4); + u32 length = read(sourceData + offset + 0, 4); + u32 fourCC = read(sourceData + offset + 4, 4); + u32 checksum = read(sourceData + offset + 8 + length, 4); - if(fourCC == (uint)FourCC::IHDR) { + if(fourCC == (u32)FourCC::IHDR) { info.width = read(sourceData + offset + 8, 4); info.height = read(sourceData + offset + 12, 4); info.bitDepth = read(sourceData + offset + 16, 1); @@ -112,33 +112,33 @@ inline auto PNG::load(const uint8_t* sourceData, uint sourceSize) -> bool { if(info.colorType == 3 && info.bitDepth == 16) return false; info.bytesPerPixel = (info.bytesPerPixel + 7) / 8; - info.pitch = (int)info.width * info.bytesPerPixel; + info.pitch = (s32)info.width * info.bytesPerPixel; } - if(fourCC == (uint)FourCC::PLTE) { + if(fourCC == (u32)FourCC::PLTE) { if(length % 3) return false; - for(uint n = 0, p = offset + 8; n < length / 3; n++) { + for(u32 n = 0, p = offset + 8; n < length / 3; n++) { info.palette[n][0] = sourceData[p++]; info.palette[n][1] = sourceData[p++]; info.palette[n][2] = sourceData[p++]; } } - if(fourCC == (uint)FourCC::IDAT) { - compressedData = (uint8_t*)realloc(compressedData, compressedSize + length); + if(fourCC == (u32)FourCC::IDAT) { + compressedData = (u8*)realloc(compressedData, compressedSize + length); memcpy(compressedData + compressedSize, sourceData + offset + 8, length); compressedSize += length; } - if(fourCC == (uint)FourCC::IEND) { + if(fourCC == (u32)FourCC::IEND) { break; } offset += 4 + 4 + length + 4; } - uint interlacedSize = inflateSize(); - auto interlacedData = new uint8_t[interlacedSize]; + u32 interlacedSize = inflateSize(); + auto interlacedData = new u8[interlacedSize]; bool result = inflate(interlacedData, interlacedSize, compressedData + 2, compressedSize - 6); free(compressedData); @@ -149,7 +149,7 @@ inline auto PNG::load(const uint8_t* sourceData, uint sourceSize) -> bool { } size = info.width * info.height * info.bytesPerPixel; - data = new uint8_t[size]; + data = new u8[size]; if(info.interlaceMethod == 0) { if(filter(data, interlacedData, info.width, info.height) == false) { @@ -159,8 +159,8 @@ inline auto PNG::load(const uint8_t* sourceData, uint sourceSize) -> bool { return false; } } else { - const uint8_t* passData = interlacedData; - for(uint pass = 0; pass < 7; pass++) { + const u8* passData = interlacedData; + for(u32 pass = 0; pass < 7; pass++) { if(deinterlace(passData, pass) == false) { delete[] interlacedData; delete[] data; @@ -174,8 +174,8 @@ inline auto PNG::load(const uint8_t* sourceData, uint sourceSize) -> bool { return true; } -inline auto PNG::interlace(uint pass, uint index) -> uint { - static const uint data[7][4] = { +inline auto PNG::interlace(u32 pass, u32 index) -> u32 { + static const u32 data[7][4] = { //x-distance, y-distance, x-origin, y-origin {8, 8, 0, 0}, {8, 8, 4, 0}, @@ -188,39 +188,39 @@ inline auto PNG::interlace(uint pass, uint index) -> uint { return data[pass][index]; } -inline auto PNG::inflateSize() -> uint { +inline auto PNG::inflateSize() -> u32 { if(info.interlaceMethod == 0) { return info.width * info.height * info.bytesPerPixel + info.height; } - uint size = 0; - for(uint pass = 0; pass < 7; pass++) { - uint xd = interlace(pass, 0), yd = interlace(pass, 1); - uint xo = interlace(pass, 2), yo = interlace(pass, 3); - uint width = (info.width + (xd - xo - 1)) / xd; - uint height = (info.height + (yd - yo - 1)) / yd; + u32 size = 0; + for(u32 pass = 0; pass < 7; pass++) { + u32 xd = interlace(pass, 0), yd = interlace(pass, 1); + u32 xo = interlace(pass, 2), yo = interlace(pass, 3); + u32 width = (info.width + (xd - xo - 1)) / xd; + u32 height = (info.height + (yd - yo - 1)) / yd; if(width == 0 || height == 0) continue; size += width * height * info.bytesPerPixel + height; } return size; } -inline auto PNG::deinterlace(const uint8_t*& inputData, uint pass) -> bool { - uint xd = interlace(pass, 0), yd = interlace(pass, 1); - uint xo = interlace(pass, 2), yo = interlace(pass, 3); - uint width = (info.width + (xd - xo - 1)) / xd; - uint height = (info.height + (yd - yo - 1)) / yd; +inline auto PNG::deinterlace(const u8*& inputData, u32 pass) -> bool { + u32 xd = interlace(pass, 0), yd = interlace(pass, 1); + u32 xo = interlace(pass, 2), yo = interlace(pass, 3); + u32 width = (info.width + (xd - xo - 1)) / xd; + u32 height = (info.height + (yd - yo - 1)) / yd; if(width == 0 || height == 0) return true; - uint outputSize = width * height * info.bytesPerPixel; - auto outputData = new uint8_t[outputSize]; + u32 outputSize = width * height * info.bytesPerPixel; + auto outputData = new u8[outputSize]; bool result = filter(outputData, inputData, width, height); - const uint8_t* rd = outputData; - for(uint y = yo; y < info.height; y += yd) { - uint8_t* wr = data + y * info.pitch; - for(uint x = xo; x < info.width; x += xd) { - for(uint b = 0; b < info.bytesPerPixel; b++) { + const u8* rd = outputData; + for(u32 y = yo; y < info.height; y += yd) { + u8* wr = data + y * info.pitch; + for(u32 x = xo; x < info.width; x += xd) { + for(u32 b = 0; b < info.bytesPerPixel; b++) { wr[x * info.bytesPerPixel + b] = *rd++; } } @@ -231,53 +231,53 @@ inline auto PNG::deinterlace(const uint8_t*& inputData, uint pass) -> bool { return result; } -inline auto PNG::filter(uint8_t* outputData, const uint8_t* inputData, uint width, uint height) -> bool { - uint8_t* wr = outputData; - const uint8_t* rd = inputData; - int bpp = info.bytesPerPixel, pitch = width * bpp; - for(int y = 0; y < height; y++) { - uint8_t filter = *rd++; +inline auto PNG::filter(u8* outputData, const u8* inputData, u32 width, u32 height) -> bool { + u8* wr = outputData; + const u8* rd = inputData; + s32 bpp = info.bytesPerPixel, pitch = width * bpp; + for(s32 y = 0; y < height; y++) { + u8 filter = *rd++; switch(filter) { case 0x00: //None - for(int x = 0; x < pitch; x++) { + for(s32 x = 0; x < pitch; x++) { wr[x] = rd[x]; } break; case 0x01: //Subtract - for(int x = 0; x < pitch; x++) { + for(s32 x = 0; x < pitch; x++) { wr[x] = rd[x] + (x - bpp < 0 ? 0 : wr[x - bpp]); } break; case 0x02: //Above - for(int x = 0; x < pitch; x++) { + for(s32 x = 0; x < pitch; x++) { wr[x] = rd[x] + (y - 1 < 0 ? 0 : wr[x - pitch]); } break; case 0x03: //Average - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; + for(s32 x = 0; x < pitch; x++) { + s16 a = x - bpp < 0 ? 0 : wr[x - bpp]; + s16 b = y - 1 < 0 ? 0 : wr[x - pitch]; - wr[x] = rd[x] + (uint8_t)((a + b) / 2); + wr[x] = rd[x] + (u8)((a + b) / 2); } break; case 0x04: //Paeth - for(int x = 0; x < pitch; x++) { - short a = x - bpp < 0 ? 0 : wr[x - bpp]; - short b = y - 1 < 0 ? 0 : wr[x - pitch]; - short c = x - bpp < 0 || y - 1 < 0 ? 0 : wr[x - pitch - bpp]; + for(s32 x = 0; x < pitch; x++) { + s16 a = x - bpp < 0 ? 0 : wr[x - bpp]; + s16 b = y - 1 < 0 ? 0 : wr[x - pitch]; + s16 c = x - bpp < 0 || y - 1 < 0 ? 0 : wr[x - pitch - bpp]; - short p = a + b - c; - short pa = p > a ? p - a : a - p; - short pb = p > b ? p - b : b - p; - short pc = p > c ? p - c : c - p; + s16 p = a + b - c; + s16 pa = p > a ? p - a : a - p; + s16 pb = p > b ? p - b : b - p; + s16 pc = p > c ? p - c : c - p; - auto paeth = (uint8_t)((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); + auto paeth = (u8)((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); wr[x] = rd[x] + paeth; } @@ -294,14 +294,14 @@ inline auto PNG::filter(uint8_t* outputData, const uint8_t* inputData, uint widt return true; } -inline auto PNG::read(const uint8_t* data, uint length) -> uint { - uint result = 0; +inline auto PNG::read(const u8* data, u32 length) -> u32 { + u32 result = 0; while(length--) result = (result << 8) | (*data++); return result; } -inline auto PNG::readbits(const uint8_t*& data) -> uint { - uint result = 0; +inline auto PNG::readbits(const u8*& data) -> u32 { + u32 result = 0; switch(info.bitDepth) { case 1: result = (*data >> bitpos) & 1; diff --git a/nall/decode/rle.hpp b/nall/decode/rle.hpp index 4a6c67ca97..059ca521e0 100644 --- a/nall/decode/rle.hpp +++ b/nall/decode/rle.hpp @@ -2,28 +2,28 @@ namespace nall::Decode { -template //S = word size; M = match length -inline auto RLE(array_view input) -> vector { - vector output; +template //S = word size; M = match length +inline auto RLE(array_view input) -> vector { + vector output; - auto load = [&]() -> uint8_t { + auto load = [&]() -> u8 { return input ? *input++ : 0; }; - uint base = 0; - uint64_t size = 0; - for(uint byte : range(8)) size |= load() << byte * 8; + u32 base = 0; + u64 size = 0; + for(u32 byte : range(8)) size |= load() << byte * 8; output.resize(size); - auto read = [&]() -> uint64_t { - uint64_t value = 0; - for(uint byte : range(S)) value |= load() << byte * 8; + auto read = [&]() -> u64 { + u64 value = 0; + for(u32 byte : range(S)) value |= load() << byte * 8; return value; }; - auto write = [&](uint64_t value) -> void { + auto write = [&](u64 value) -> void { if(base >= size) return; - for(uint byte : range(S)) output[base++] = value >> byte * 8; + for(u32 byte : range(S)) output[base++] = value >> byte * 8; }; while(base < size) { diff --git a/nall/decode/url.hpp b/nall/decode/url.hpp index 56526c928e..18382d1c96 100644 --- a/nall/decode/url.hpp +++ b/nall/decode/url.hpp @@ -5,7 +5,7 @@ namespace nall::Decode { //returns empty string on malformed content inline auto URL(string_view input) -> string { string output; - for(uint n = 0; n < input.size();) { + for(u32 n = 0; n < input.size();) { char c = input[n]; //unreserved characters diff --git a/nall/decode/wav.hpp b/nall/decode/wav.hpp index 7805e07d0d..7ba6ee14d3 100644 --- a/nall/decode/wav.hpp +++ b/nall/decode/wav.hpp @@ -8,16 +8,16 @@ namespace nall::Decode { struct WAV { auto open(const string& filename) -> bool; auto close() -> void; - auto read() -> uint64_t; + auto read() -> u64; auto end() const -> bool; - auto size() const -> uint64_t; + auto size() const -> u64; file_buffer fp; - uint channels = 0; - uint frequency = 0; - uint bitrate = 0; - uint samples = 0; - uint headerSize = 0; + u32 channels = 0; + u32 frequency = 0; + u32 bitrate = 0; + u32 samples = 0; + u32 headerSize = 0; }; inline auto WAV::open(const string& filename) -> bool { @@ -29,7 +29,7 @@ inline auto WAV::open(const string& filename) -> bool { if(fp.read() != 'F') return false; if(fp.read() != 'F') return false; - uint32_t chunkSize = fp.readl(4); + u32 chunkSize = fp.readl(4); if(fp.read() != 'W') return false; if(fp.read() != 'A') return false; @@ -41,16 +41,16 @@ inline auto WAV::open(const string& filename) -> bool { if(fp.read() != 't') return false; if(fp.read() != ' ') return false; - uint32_t subchunkSize = fp.readl(4); + u32 subchunkSize = fp.readl(4); if(subchunkSize != 16) return false; - uint16_t format = fp.readl(2); + u16 format = fp.readl(2); if(format != 1) return false; //only PCM is supported channels = fp.readl(2); frequency = fp.readl(4); - uint32_t byteRate = fp.readl(4); - uint16_t blockAlign = fp.readl(2); + u32 byteRate = fp.readl(4); + u16 blockAlign = fp.readl(2); bitrate = fp.readl(2); //todo: handle LIST chunk better than this @@ -60,8 +60,8 @@ inline auto WAV::open(const string& filename) -> bool { while(!fp.end() && fp.read() != 'a'); if(fp.end()) return false; - uint32_t dataSize = fp.readl(4); - uint32_t remaining = fp.size() - fp.offset(); + u32 dataSize = fp.readl(4); + u32 remaining = fp.size() - fp.offset(); samples = remaining / (bitrate / 8) / channels; headerSize = fp.offset(); return true; @@ -78,7 +78,7 @@ inline auto WAV::close() -> void { samples = 0; } -inline auto WAV::read() -> uint64_t { +inline auto WAV::read() -> u64 { return fp.readl((bitrate / 8) * channels); } @@ -86,7 +86,7 @@ inline auto WAV::end() const -> bool { return fp.end(); } -inline auto WAV::size() const -> uint64_t { +inline auto WAV::size() const -> u64 { return samples * (bitrate / 8) * channels; } diff --git a/nall/decode/zip.hpp b/nall/decode/zip.hpp index 316009dd93..f980df08ae 100644 --- a/nall/decode/zip.hpp +++ b/nall/decode/zip.hpp @@ -10,11 +10,11 @@ namespace nall::Decode { struct ZIP { struct File { string name; - const uint8_t* data; - uint size; - uint csize; - uint cmode; //0 = uncompressed, 8 = deflate - uint crc32; + const u8* data; + u32 size; + u32 csize; + u32 cmode; //0 = uncompressed, 8 = deflate + u32 crc32; time_t timestamp; }; @@ -32,7 +32,7 @@ struct ZIP { return true; } - auto open(const uint8_t* data, uint size) -> bool { + auto open(const u8* data, u32 size) -> bool { if(size < 22) return false; filedata = data; @@ -40,19 +40,19 @@ struct ZIP { file.reset(); - const uint8_t* footer = data + size - 22; + const u8* footer = data + size - 22; while(true) { if(footer <= data + 22) return false; if(read(footer, 4) == 0x06054b50) { - uint commentlength = read(footer + 20, 2); + u32 commentlength = read(footer + 20, 2); if(footer + 22 + commentlength == data + size) break; } footer--; } - const uint8_t* directory = data + read(footer + 16, 4); + const u8* directory = data + read(footer + 16, 4); while(true) { - uint signature = read(directory + 0, 4); + u32 signature = read(directory + 0, 4); if(signature != 0x02014b50) break; File file; @@ -61,8 +61,8 @@ struct ZIP { file.csize = read(directory + 20, 4); file.size = read(directory + 24, 4); - uint16_t dosTime = read(directory + 12, 2); - uint16_t dosDate = read(directory + 14, 2); + u16 dosTime = read(directory + 12, 2); + u16 dosDate = read(directory + 14, 2); tm info = {}; info.tm_sec = (dosTime >> 0 & 31) << 1; info.tm_min = (dosTime >> 5 & 63); @@ -73,9 +73,9 @@ struct ZIP { info.tm_isdst = -1; file.timestamp = mktime(&info); - uint namelength = read(directory + 28, 2); - uint extralength = read(directory + 30, 2); - uint commentlength = read(directory + 32, 2); + u32 namelength = read(directory + 28, 2); + u32 extralength = read(directory + 30, 2); + u32 commentlength = read(directory + 32, 2); char* filename = new char[namelength + 1]; memcpy(filename, directory + 46, namelength); @@ -83,9 +83,9 @@ struct ZIP { file.name = filename; delete[] filename; - uint offset = read(directory + 42, 4); - uint offsetNL = read(data + offset + 26, 2); - uint offsetEL = read(data + offset + 28, 2); + u32 offset = read(directory + 42, 4); + u32 offsetNL = read(data + offset + 26, 2); + u32 offsetEL = read(data + offset + 28, 2); file.data = data + offset + 30 + offsetNL + offsetEL; directory += 46 + namelength + extralength + commentlength; @@ -96,8 +96,8 @@ struct ZIP { return true; } - auto extract(File& file) -> vector { - vector buffer; + auto extract(File& file) -> vector { + vector buffer; if(file.cmode == 0) { buffer.resize(file.size); @@ -120,11 +120,11 @@ struct ZIP { protected: file_map fm; - const uint8_t* filedata; - uint filesize; + const u8* filedata; + u32 filesize; - auto read(const uint8_t* data, uint size) -> uint { - uint result = 0, shift = 0; + auto read(const u8* data, u32 size) -> u32 { + u32 result = 0, shift = 0; while(size--) { result |= *data++ << shift; shift += 8; } return result; } diff --git a/nall/directory.hpp b/nall/directory.hpp index 7dc6b8ff3b..37629da9cd 100644 --- a/nall/directory.hpp +++ b/nall/directory.hpp @@ -22,7 +22,7 @@ struct directory : inode { directory() = delete; static auto copy(const string& source, const string& target) -> bool; //recursive - static auto create(const string& pathname, uint permissions = 0755) -> bool; //recursive + static auto create(const string& pathname, u32 permissions = 0755) -> bool; //recursive static auto remove(const string& pathname) -> bool; //recursive static auto exists(const string& pathname) -> bool; @@ -170,7 +170,7 @@ inline auto directory::copy(const string& source, const string& target) -> bool } #if defined(PLATFORM_WINDOWS) - inline auto directory::create(const string& pathname, uint permissions) -> bool { + inline auto directory::create(const string& pathname, u32 permissions) -> bool { string path; auto list = string{pathname}.transform("\\", "/").trimRight("/").split("/"); bool result = true; @@ -184,10 +184,11 @@ inline auto directory::copy(const string& source, const string& target) -> bool inline auto directory::remove(const string& pathname) -> bool { if(!pathname || pathname == "/" || pathname.match("?:") || pathname.match("?:/")) return false; //safeguard + string separator = pathname.endsWith("/") || pathname.endsWith("\\") ? "" : "/"; auto list = directory::contents(pathname); for(auto& name : list) { - if(name.endsWith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); + if(name.endsWith("/")) directory::remove({pathname, separator, name}); + else file::remove({pathname, separator, name}); } return _wrmdir(utf16_t(pathname)) == 0; } @@ -280,7 +281,7 @@ inline auto directory::copy(const string& source, const string& target) -> bool return false; } - inline auto directory::create(const string& pathname, uint permissions) -> bool { + inline auto directory::create(const string& pathname, u32 permissions) -> bool { string path; auto list = string{pathname}.trimRight("/").split("/"); bool result = true; @@ -294,10 +295,11 @@ inline auto directory::copy(const string& source, const string& target) -> bool inline auto directory::remove(const string& pathname) -> bool { if(!pathname || pathname == "/") return false; //safeguard + string separator = pathname.endsWith("/") ? "" : "/"; auto list = directory::contents(pathname); for(auto& name : list) { - if(name.endsWith("/")) directory::remove({pathname, name}); - else file::remove({pathname, name}); + if(name.endsWith("/")) directory::remove({pathname, separator, name}); + else file::remove({pathname, separator, name}); } return rmdir(pathname) == 0; } diff --git a/nall/dsp/dsp.hpp b/nall/dsp/dsp.hpp deleted file mode 100644 index f8bf82e2b4..0000000000 --- a/nall/dsp/dsp.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -namespace nall::DSP { - -} diff --git a/nall/dsp/iir/biquad.hpp b/nall/dsp/iir/biquad.hpp index c36273b2d8..5ab85bad5a 100644 --- a/nall/dsp/iir/biquad.hpp +++ b/nall/dsp/iir/biquad.hpp @@ -1,13 +1,11 @@ #pragma once -#include - //transposed direct form II biquadratic second-order IIR filter namespace nall::DSP::IIR { struct Biquad { - enum class Type : uint { + enum class Type : u32 { LowPass, HighPass, BandPass, @@ -17,23 +15,23 @@ struct Biquad { HighShelf, }; - auto reset(Type type, double cutoffFrequency, double samplingFrequency, double quality, double gain = 0.0) -> void; - auto process(double in) -> double; //normalized sample (-1.0 to +1.0) + auto reset(Type type, f64 cutoffFrequency, f64 samplingFrequency, f64 quality, f64 gain = 0.0) -> void; + auto process(f64 in) -> f64; //normalized sample (-1.0 to +1.0) - static auto shelf(double gain, double slope) -> double; - static auto butterworth(uint order, uint phase) -> double; + static auto shelf(f64 gain, f64 slope) -> f64; + static auto butterworth(u32 order, u32 phase) -> f64; private: Type type; - double cutoffFrequency; - double samplingFrequency; - double quality; //frequency response quality - double gain; //peak gain - double a0, a1, a2, b1, b2; //coefficients - double z1, z2; //second-order IIR + f64 cutoffFrequency; + f64 samplingFrequency; + f64 quality; //frequency response quality + f64 gain; //peak gain + f64 a0, a1, a2, b1, b2; //coefficients + f64 z1, z2; //second-order IIR }; -inline auto Biquad::reset(Type type, double cutoffFrequency, double samplingFrequency, double quality, double gain) -> void { +inline auto Biquad::reset(Type type, f64 cutoffFrequency, f64 samplingFrequency, f64 quality, f64 gain) -> void { this->type = type; this->cutoffFrequency = cutoffFrequency; this->samplingFrequency = samplingFrequency; @@ -43,10 +41,10 @@ inline auto Biquad::reset(Type type, double cutoffFrequency, double samplingFreq z1 = 0.0; z2 = 0.0; - double v = pow(10, fabs(gain) / 20.0); - double k = tan(Math::Pi * cutoffFrequency / samplingFrequency); - double q = quality; - double n = 0.0; + f64 v = pow(10, fabs(gain) / 20.0); + f64 k = tan(Math::Pi * cutoffFrequency / samplingFrequency); + f64 q = quality; + f64 n = 0.0; switch(type) { @@ -143,21 +141,21 @@ inline auto Biquad::reset(Type type, double cutoffFrequency, double samplingFreq } } -inline auto Biquad::process(double in) -> double { - double out = in * a0 + z1; +inline auto Biquad::process(f64 in) -> f64 { + f64 out = in * a0 + z1; z1 = in * a1 + z2 - b1 * out; z2 = in * a2 - b2 * out; return out; } //compute Q values for low-shelf and high-shelf filtering -inline auto Biquad::shelf(double gain, double slope) -> double { - double a = pow(10, gain / 40); +inline auto Biquad::shelf(f64 gain, f64 slope) -> f64 { + f64 a = pow(10, gain / 40); return 1 / sqrt((a + 1 / a) * (1 / slope - 1) + 2); } //compute Q values for Nth-order butterworth filtering -inline auto Biquad::butterworth(uint order, uint phase) -> double { +inline auto Biquad::butterworth(u32 order, u32 phase) -> f64 { return -0.5 / cos(Math::Pi * (phase + order + 0.5) / order); } diff --git a/nall/dsp/iir/dc-removal.hpp b/nall/dsp/iir/dc-removal.hpp index fcd413031f..db77790c52 100644 --- a/nall/dsp/iir/dc-removal.hpp +++ b/nall/dsp/iir/dc-removal.hpp @@ -1,18 +1,16 @@ #pragma once -#include - //DC offset removal IIR filter namespace nall::DSP::IIR { struct DCRemoval { auto reset() -> void; - auto process(double in) -> double; //normalized sample (-1.0 to +1.0) + auto process(f64 in) -> f64; //normalized sample (-1.0 to +1.0) private: - double x; - double y; + f64 x; + f64 y; }; inline auto DCRemoval::reset() -> void { @@ -20,7 +18,7 @@ inline auto DCRemoval::reset() -> void { y = 0.0; } -inline auto DCRemoval::process(double in) -> double { +inline auto DCRemoval::process(f64 in) -> f64 { x = 0.999 * x + in - y; y = in; return x; diff --git a/nall/dsp/iir/one-pole.hpp b/nall/dsp/iir/one-pole.hpp index 0498d6854c..9feab2dc01 100644 --- a/nall/dsp/iir/one-pole.hpp +++ b/nall/dsp/iir/one-pole.hpp @@ -1,35 +1,33 @@ #pragma once -#include - //one-pole first-order IIR filter namespace nall::DSP::IIR { struct OnePole { - enum class Type : uint { + enum class Type : u32 { LowPass, HighPass, }; - auto reset(Type type, double cutoffFrequency, double samplingFrequency) -> void; - auto process(double in) -> double; //normalized sample (-1.0 to +1.0) + auto reset(Type type, f64 cutoffFrequency, f64 samplingFrequency) -> void; + auto process(f64 in) -> f64; //normalized sample (-1.0 to +1.0) private: Type type; - double cutoffFrequency; - double samplingFrequency; - double a0, b1; //coefficients - double z1; //first-order IIR + f64 cutoffFrequency; + f64 samplingFrequency; + f64 a0, b1; //coefficients + f64 z1; //first-order IIR }; -inline auto OnePole::reset(Type type, double cutoffFrequency, double samplingFrequency) -> void { +inline auto OnePole::reset(Type type, f64 cutoffFrequency, f64 samplingFrequency) -> void { this->type = type; this->cutoffFrequency = cutoffFrequency; this->samplingFrequency = samplingFrequency; z1 = 0.0; - double x = cos(2.0 * Math::Pi * cutoffFrequency / samplingFrequency); + f64 x = cos(2.0 * Math::Pi * cutoffFrequency / samplingFrequency); if(type == Type::LowPass) { b1 = +2.0 - x - sqrt((+2.0 - x) * (+2.0 - x) - 1); a0 = 1.0 - b1; @@ -39,7 +37,7 @@ inline auto OnePole::reset(Type type, double cutoffFrequency, double samplingFre } } -inline auto OnePole::process(double in) -> double { +inline auto OnePole::process(f64 in) -> f64 { return z1 = in * a0 + z1 * b1; } diff --git a/nall/dsp/resampler/cubic.hpp b/nall/dsp/resampler/cubic.hpp index 995239e456..f690e78d33 100644 --- a/nall/dsp/resampler/cubic.hpp +++ b/nall/dsp/resampler/cubic.hpp @@ -2,32 +2,31 @@ #include #include -#include namespace nall::DSP::Resampler { struct Cubic { - auto inputFrequency() const -> double { return _inputFrequency; } - auto outputFrequency() const -> double { return _outputFrequency; } + auto inputFrequency() const -> f64 { return _inputFrequency; } + auto outputFrequency() const -> f64 { return _outputFrequency; } - auto reset(double inputFrequency, double outputFrequency = 0, uint queueSize = 0) -> void; - auto setInputFrequency(double inputFrequency) -> void; + auto reset(f64 inputFrequency, f64 outputFrequency = 0, u32 queueSize = 0) -> void; + auto setInputFrequency(f64 inputFrequency) -> void; auto pending() const -> bool; - auto read() -> double; - auto write(double sample) -> void; + auto read() -> f64; + auto write(f64 sample) -> void; auto serialize(serializer&) -> void; private: - double _inputFrequency; - double _outputFrequency; + f64 _inputFrequency; + f64 _outputFrequency; - double _ratio; - double _fraction; - double _history[4]; - queue _samples; + f64 _ratio; + f64 _fraction; + f64 _history[4]; + queue _samples; }; -inline auto Cubic::reset(double inputFrequency, double outputFrequency, uint queueSize) -> void { +inline auto Cubic::reset(f64 inputFrequency, f64 outputFrequency, u32 queueSize) -> void { _inputFrequency = inputFrequency; _outputFrequency = outputFrequency ? outputFrequency : _inputFrequency; @@ -37,7 +36,7 @@ inline auto Cubic::reset(double inputFrequency, double outputFrequency, uint que _samples.resize(queueSize ? queueSize : _outputFrequency * 0.02); //default to 20ms max queue size } -inline auto Cubic::setInputFrequency(double inputFrequency) -> void { +inline auto Cubic::setInputFrequency(f64 inputFrequency) -> void { _inputFrequency = inputFrequency; _ratio = _inputFrequency / _outputFrequency; } @@ -50,7 +49,7 @@ inline auto Cubic::read() -> double { return _samples.read(); } -inline auto Cubic::write(double sample) -> void { +inline auto Cubic::write(f64 sample) -> void { auto& mu = _fraction; auto& s = _history; @@ -60,10 +59,10 @@ inline auto Cubic::write(double sample) -> void { s[3] = sample; while(mu <= 1.0) { - double A = s[3] - s[2] - s[0] + s[1]; - double B = s[0] - s[1] - A; - double C = s[2] - s[0]; - double D = s[1]; + f64 A = s[3] - s[2] - s[0] + s[1]; + f64 B = s[0] - s[1] - A; + f64 C = s[2] - s[0]; + f64 D = s[1]; _samples.write(A * mu * mu * mu + B * mu * mu + C * mu + D); mu += _ratio; diff --git a/nall/elliptic-curve/curve25519.hpp b/nall/elliptic-curve/curve25519.hpp index 8aed835987..e97dd080b1 100644 --- a/nall/elliptic-curve/curve25519.hpp +++ b/nall/elliptic-curve/curve25519.hpp @@ -9,7 +9,7 @@ namespace nall::EllipticCurve { struct Curve25519 { - auto sharedKey(uint256_t secretKey, uint256_t basepoint = 9) const -> uint256_t { + auto sharedKey(u256 secretKey, u256 basepoint = 9) const -> u256 { secretKey &= (1_u256 << 254) - 8; secretKey |= (1_u256 << 254); basepoint &= ~0_u256 >> 1; @@ -39,9 +39,9 @@ struct Curve25519 { }; } - auto scalarMultiply(field b, uint256_t exponent) const -> point { + auto scalarMultiply(field b, u256 exponent) const -> point { point p{1, 0}, q{b, 1}; - for(uint bit : reverse(range(255))) { + for(u32 bit : reverse(range(255))) { bool condition = exponent >> bit & 1; cswap(condition, p.x, q.x); cswap(condition, p.z, q.z); diff --git a/nall/elliptic-curve/ed25519.hpp b/nall/elliptic-curve/ed25519.hpp index 501104260b..76b0628402 100644 --- a/nall/elliptic-curve/ed25519.hpp +++ b/nall/elliptic-curve/ed25519.hpp @@ -9,34 +9,34 @@ namespace nall::EllipticCurve { -static const uint256_t L = (1_u256 << 252) + 27742317777372353535851937790883648493_u256; +static const u256 L = (1_u256 << 252) + 27742317777372353535851937790883648493_u256; struct Ed25519 { - auto publicKey(uint256_t privateKey) const -> uint256_t { + auto publicKey(u256 privateKey) const -> u256 { return compress(scalarMultiply(B, clamp(hash(privateKey)) % L)); } - auto sign(array_view message, uint256_t privateKey) const -> uint512_t { - uint512_t H = hash(privateKey); - uint256_t a = clamp(H) % L; - uint256_t A = compress(scalarMultiply(B, a)); + auto sign(array_view message, u256 privateKey) const -> u512 { + u512 H = hash(privateKey); + u256 a = clamp(H) % L; + u256 A = compress(scalarMultiply(B, a)); - uint512_t r = hash(upper(H), message) % L; - uint256_t R = compress(scalarMultiply(B, r)); + u512 r = hash(upper(H), message) % L; + u256 R = compress(scalarMultiply(B, r)); - uint512_t k = hash(R, A, message) % L; - uint256_t S = (k * a + r) % L; + u512 k = hash(R, A, message) % L; + u256 S = (k * a + r) % L; - return uint512_t(S) << 256 | R; + return u512(S) << 256 | R; } - auto verify(array_view message, uint512_t signature, uint256_t publicKey) const -> bool { + auto verify(array_view message, u512 signature, u256 publicKey) const -> bool { auto R = decompress(lower(signature)); auto A = decompress(publicKey); if(!R || !A) return false; - uint256_t S = upper(signature) % L; - uint512_t r = hash(lower(signature), publicKey, message) % L; + u256 S = upper(signature) % L; + u512 r = hash(lower(signature), publicKey, message) % L; auto p = scalarMultiply(B, S); auto q = edwardsAdd(R(), scalarMultiply(A(), r)); @@ -55,25 +55,25 @@ struct Ed25519 { auto input(Hash::SHA512&) const -> void {} - template auto input(Hash::SHA512& hash, uint256_t value, P&&... p) const -> void { - for(uint byte : range(32)) hash.input(uint8_t(value >> byte * 8)); + template auto input(Hash::SHA512& hash, u256 value, P&&... p) const -> void { + for(u32 byte : range(32)) hash.input(u8(value >> byte * 8)); input(hash, forward

(p)...); } - template auto input(Hash::SHA512& hash, array_view value, P&&... p) const -> void { + template auto input(Hash::SHA512& hash, array_view value, P&&... p) const -> void { hash.input(value); input(hash, forward

(p)...); } - template auto hash(P&&... p) const -> uint512_t { + template auto hash(P&&... p) const -> u512 { Hash::SHA512 hash; input(hash, forward

(p)...); - uint512_t result; + u512 result; for(auto byte : reverse(hash.output())) result = result << 8 | byte; return result; } - auto clamp(uint256_t p) const -> uint256_t { + auto clamp(u256 p) const -> u256 { p &= (1_u256 << 254) - 8; p |= (1_u256 << 254); return p; @@ -86,7 +86,7 @@ struct Ed25519 { return true; } - auto decompress(uint256_t c) const -> maybe { + auto decompress(u256 c) const -> maybe { field y = c & ~0_u256 >> 1; field x = squareRoot((square(y) - 1) * reciprocal(D * square(y) + 1)); if(c >> 255) x = -x; @@ -95,7 +95,7 @@ struct Ed25519 { return p; } - auto compress(point p) const -> uint256_t { + auto compress(point p) const -> u256 { field r = reciprocal(p.z); field x = p.x * r; field y = p.y * r; @@ -126,9 +126,9 @@ struct Ed25519 { return {e * f, g * h, f * g, e * h}; } - auto scalarMultiply(point q, uint256_t exponent) const -> point { + auto scalarMultiply(point q, u256 exponent) const -> point { point p{0, 1, 1, 0}, c; - for(uint bit : reverse(range(253))) { + for(u32 bit : reverse(range(253))) { p = edwardsDouble(p); c = edwardsAdd(p, q); bool condition = exponent >> bit & 1; diff --git a/nall/elliptic-curve/modulo25519-optimized.hpp b/nall/elliptic-curve/modulo25519-optimized.hpp index 261cdf51ff..d0e0f4e4d7 100644 --- a/nall/elliptic-curve/modulo25519-optimized.hpp +++ b/nall/elliptic-curve/modulo25519-optimized.hpp @@ -4,26 +4,26 @@ namespace nall::EllipticCurve { -static const uint256_t P = (1_u256 << 255) - 19; +static const u256 P = (1_u256 << 255) - 19; #define Mask ((1ull << 51) - 1) struct Modulo25519 { Modulo25519() = default; Modulo25519(const Modulo25519&) = default; - Modulo25519(uint64_t a, uint64_t b = 0, uint64_t c = 0, uint64_t d = 0, uint64_t e = 0) : l{a, b, c, d, e} {} - Modulo25519(uint256_t n); + Modulo25519(u64 a, u64 b = 0, u64 c = 0, u64 d = 0, u64 e = 0) : l{a, b, c, d, e} {} + Modulo25519(u256 n); explicit operator bool() const { return (bool)operator()(); } - auto operator[](uint index) -> uint64_t& { return l[index]; } - auto operator[](uint index) const -> uint64_t { return l[index]; } - auto operator()() const -> uint256_t; + auto operator[](u32 index) -> u64& { return l[index]; } + auto operator[](u32 index) const -> u64 { return l[index]; } + auto operator()() const -> u256; private: - uint64_t l[5]; //51-bits per limb; 255-bits total + u64 l[5]; //51-bits per limb; 255-bits total }; -inline Modulo25519::Modulo25519(uint256_t n) { +inline Modulo25519::Modulo25519(u256 n) { l[0] = n >> 0 & Mask; l[1] = n >> 51 & Mask; l[2] = n >> 102 & Mask; @@ -31,7 +31,7 @@ inline Modulo25519::Modulo25519(uint256_t n) { l[4] = n >> 204 & Mask; } -inline auto Modulo25519::operator()() const -> uint256_t { +inline auto Modulo25519::operator()() const -> u256 { Modulo25519 o = *this; o[1] += (o[0] >> 51); o[0] &= Mask; @@ -65,11 +65,11 @@ inline auto Modulo25519::operator()() const -> uint256_t { o[4] += o[3] >> 51; o[3] &= Mask; o[4] &= Mask; - return (uint256_t)o[0] << 0 | (uint256_t)o[1] << 51 | (uint256_t)o[2] << 102 | (uint256_t)o[3] << 153 | (uint256_t)o[4] << 204; + return (u256)o[0] << 0 | (u256)o[1] << 51 | (u256)o[2] << 102 | (u256)o[3] << 153 | (u256)o[4] << 204; } inline auto cmove(bool move, Modulo25519& l, const Modulo25519& r) -> void { - uint64_t mask = -move; + u64 mask = -move; l[0] ^= mask & (l[0] ^ r[0]); l[1] ^= mask & (l[1] ^ r[1]); l[2] ^= mask & (l[2] ^ r[2]); @@ -78,7 +78,7 @@ inline auto cmove(bool move, Modulo25519& l, const Modulo25519& r) -> void { } inline auto cswap(bool swap, Modulo25519& l, Modulo25519& r) -> void { - uint64_t mask = -swap, x; + u64 mask = -swap, x; x = mask & (l[0] ^ r[0]); l[0] ^= x; r[0] ^= x; x = mask & (l[1] ^ r[1]); l[1] ^= x; r[1] ^= x; x = mask & (l[2] ^ r[2]); l[2] ^= x; r[2] ^= x; @@ -88,7 +88,7 @@ inline auto cswap(bool swap, Modulo25519& l, Modulo25519& r) -> void { inline auto operator-(const Modulo25519& l) -> Modulo25519 { //P - l Modulo25519 o; - uint64_t c; + u64 c; o[0] = 0xfffffffffffda - l[0]; c = o[0] >> 51; o[0] &= Mask; o[1] = 0xffffffffffffe - l[1] + c; c = o[1] >> 51; o[1] &= Mask; o[2] = 0xffffffffffffe - l[2] + c; c = o[2] >> 51; o[2] &= Mask; @@ -100,7 +100,7 @@ inline auto operator-(const Modulo25519& l) -> Modulo25519 { //P - l inline auto operator+(const Modulo25519& l, const Modulo25519& r) -> Modulo25519 { Modulo25519 o; - uint64_t c; + u64 c; o[0] = l[0] + r[0]; c = o[0] >> 51; o[0] &= Mask; o[1] = l[1] + r[1] + c; c = o[1] >> 51; o[1] &= Mask; o[2] = l[2] + r[2] + c; c = o[2] >> 51; o[2] &= Mask; @@ -112,7 +112,7 @@ inline auto operator+(const Modulo25519& l, const Modulo25519& r) -> Modulo25519 inline auto operator-(const Modulo25519& l, const Modulo25519& r) -> Modulo25519 { Modulo25519 o; - uint64_t c; + u64 c; o[0] = l[0] + 0x1fffffffffffb4 - r[0]; c = o[0] >> 51; o[0] &= Mask; o[1] = l[1] + 0x1ffffffffffffc - r[1] + c; c = o[1] >> 51; o[1] &= Mask; o[2] = l[2] + 0x1ffffffffffffc - r[2] + c; c = o[2] >> 51; o[2] &= Mask; @@ -122,39 +122,39 @@ inline auto operator-(const Modulo25519& l, const Modulo25519& r) -> Modulo25519 return o; } -inline auto operator*(const Modulo25519& l, uint64_t scalar) -> Modulo25519 { +inline auto operator*(const Modulo25519& l, u64 scalar) -> Modulo25519 { Modulo25519 o; - uint128_t a; - a = (uint128_t)l[0] * scalar; o[0] = a & Mask; - a = (uint128_t)l[1] * scalar + (a >> 51 & Mask); o[1] = a & Mask; - a = (uint128_t)l[2] * scalar + (a >> 51 & Mask); o[2] = a & Mask; - a = (uint128_t)l[3] * scalar + (a >> 51 & Mask); o[3] = a & Mask; - a = (uint128_t)l[4] * scalar + (a >> 51 & Mask); o[4] = a & Mask; + u128 a; + a = (u128)l[0] * scalar; o[0] = a & Mask; + a = (u128)l[1] * scalar + (a >> 51 & Mask); o[1] = a & Mask; + a = (u128)l[2] * scalar + (a >> 51 & Mask); o[2] = a & Mask; + a = (u128)l[3] * scalar + (a >> 51 & Mask); o[3] = a & Mask; + a = (u128)l[4] * scalar + (a >> 51 & Mask); o[4] = a & Mask; o[0] += (a >> 51) * 19; return o; } inline auto operator*(const Modulo25519& l, Modulo25519 r) -> Modulo25519 { - uint128_t t[] = { - (uint128_t)r[0] * l[0], - (uint128_t)r[0] * l[1] + (uint128_t)r[1] * l[0], - (uint128_t)r[0] * l[2] + (uint128_t)r[1] * l[1] + (uint128_t)r[2] * l[0], - (uint128_t)r[0] * l[3] + (uint128_t)r[1] * l[2] + (uint128_t)r[2] * l[1] + (uint128_t)r[3] * l[0], - (uint128_t)r[0] * l[4] + (uint128_t)r[1] * l[3] + (uint128_t)r[2] * l[2] + (uint128_t)r[3] * l[1] + (uint128_t)r[4] * l[0] + u128 t[] = { + (u128)r[0] * l[0], + (u128)r[0] * l[1] + (u128)r[1] * l[0], + (u128)r[0] * l[2] + (u128)r[1] * l[1] + (u128)r[2] * l[0], + (u128)r[0] * l[3] + (u128)r[1] * l[2] + (u128)r[2] * l[1] + (u128)r[3] * l[0], + (u128)r[0] * l[4] + (u128)r[1] * l[3] + (u128)r[2] * l[2] + (u128)r[3] * l[1] + (u128)r[4] * l[0] }; r[1] *= 19, r[2] *= 19, r[3] *= 19, r[4] *= 19; - t[0] += (uint128_t)r[4] * l[1] + (uint128_t)r[3] * l[2] + (uint128_t)r[2] * l[3] + (uint128_t)r[1] * l[4]; - t[1] += (uint128_t)r[4] * l[2] + (uint128_t)r[3] * l[3] + (uint128_t)r[2] * l[4]; - t[2] += (uint128_t)r[4] * l[3] + (uint128_t)r[3] * l[4]; - t[3] += (uint128_t)r[4] * l[4]; + t[0] += (u128)r[4] * l[1] + (u128)r[3] * l[2] + (u128)r[2] * l[3] + (u128)r[1] * l[4]; + t[1] += (u128)r[4] * l[2] + (u128)r[3] * l[3] + (u128)r[2] * l[4]; + t[2] += (u128)r[4] * l[3] + (u128)r[3] * l[4]; + t[3] += (u128)r[4] * l[4]; - uint64_t c; r[0] = t[0] & Mask; c = (uint64_t)(t[0] >> 51); - t[1] += c; r[1] = t[1] & Mask; c = (uint64_t)(t[1] >> 51); - t[2] += c; r[2] = t[2] & Mask; c = (uint64_t)(t[2] >> 51); - t[3] += c; r[3] = t[3] & Mask; c = (uint64_t)(t[3] >> 51); - t[4] += c; r[4] = t[4] & Mask; c = (uint64_t)(t[4] >> 51); + u64 c; r[0] = t[0] & Mask; c = (u64)(t[0] >> 51); + t[1] += c; r[1] = t[1] & Mask; c = (u64)(t[1] >> 51); + t[2] += c; r[2] = t[2] & Mask; c = (u64)(t[2] >> 51); + t[3] += c; r[3] = t[3] & Mask; c = (u64)(t[3] >> 51); + t[4] += c; r[4] = t[4] & Mask; c = (u64)(t[4] >> 51); r[0] += c * 19; c = r[0] >> 51; r[0] &= Mask; r[1] += c; c = r[1] >> 51; r[1] &= Mask; @@ -162,7 +162,7 @@ inline auto operator*(const Modulo25519& l, Modulo25519 r) -> Modulo25519 { return r; } -inline auto operator&(const Modulo25519& lhs, uint256_t rhs) -> uint256_t { +inline auto operator&(const Modulo25519& lhs, u256 rhs) -> u256 { return lhs() & rhs; } @@ -170,18 +170,18 @@ inline auto square(const Modulo25519& lhs) -> Modulo25519 { Modulo25519 r{lhs}; Modulo25519 d{r[0] * 2, r[1] * 2, r[2] * 2 * 19, r[4] * 19, r[4] * 19 * 2}; - uint128_t t[5]; - t[0] = (uint128_t)r[0] * r[0] + (uint128_t)d[4] * r[1] + (uint128_t)d[2] * r[3]; - t[1] = (uint128_t)d[0] * r[1] + (uint128_t)d[4] * r[2] + (uint128_t)r[3] * r[3] * 19; - t[2] = (uint128_t)d[0] * r[2] + (uint128_t)r[1] * r[1] + (uint128_t)d[4] * r[3]; - t[3] = (uint128_t)d[0] * r[3] + (uint128_t)d[1] * r[2] + (uint128_t)r[4] * d[3]; - t[4] = (uint128_t)d[0] * r[4] + (uint128_t)d[1] * r[3] + (uint128_t)r[2] * r[2]; + u128 t[5]; + t[0] = (u128)r[0] * r[0] + (u128)d[4] * r[1] + (u128)d[2] * r[3]; + t[1] = (u128)d[0] * r[1] + (u128)d[4] * r[2] + (u128)r[3] * r[3] * 19; + t[2] = (u128)d[0] * r[2] + (u128)r[1] * r[1] + (u128)d[4] * r[3]; + t[3] = (u128)d[0] * r[3] + (u128)d[1] * r[2] + (u128)r[4] * d[3]; + t[4] = (u128)d[0] * r[4] + (u128)d[1] * r[3] + (u128)r[2] * r[2]; - uint64_t c; r[0] = t[0] & Mask; c = (uint64_t)(t[0] >> 51); - t[1] += c; r[1] = t[1] & Mask; c = (uint64_t)(t[1] >> 51); - t[2] += c; r[2] = t[2] & Mask; c = (uint64_t)(t[2] >> 51); - t[3] += c; r[3] = t[3] & Mask; c = (uint64_t)(t[3] >> 51); - t[4] += c; r[4] = t[4] & Mask; c = (uint64_t)(t[4] >> 51); + u64 c; r[0] = t[0] & Mask; c = (u64)(t[0] >> 51); + t[1] += c; r[1] = t[1] & Mask; c = (u64)(t[1] >> 51); + t[2] += c; r[2] = t[2] & Mask; c = (u64)(t[2] >> 51); + t[3] += c; r[3] = t[3] & Mask; c = (u64)(t[3] >> 51); + t[4] += c; r[4] = t[4] & Mask; c = (u64)(t[4] >> 51); r[0] += c * 19; c = r[0] >> 51; r[0] &= Mask; r[1] += c; c = r[1] >> 51; r[1] &= Mask; @@ -189,9 +189,9 @@ inline auto square(const Modulo25519& lhs) -> Modulo25519 { return r; } -inline auto exponentiate(const Modulo25519& lhs, uint256_t exponent) -> Modulo25519 { +inline auto exponentiate(const Modulo25519& lhs, u256 exponent) -> Modulo25519 { Modulo25519 x = 1, y; - for(uint bit : reverse(range(256))) { + for(u32 bit : reverse(range(256))) { x = square(x); y = x * lhs; cmove(exponent >> bit & 1, x, y); diff --git a/nall/elliptic-curve/modulo25519-reference.hpp b/nall/elliptic-curve/modulo25519-reference.hpp index 9565dabc08..5a8ee302db 100644 --- a/nall/elliptic-curve/modulo25519-reference.hpp +++ b/nall/elliptic-curve/modulo25519-reference.hpp @@ -7,17 +7,17 @@ namespace nall::EllipticCurve { -static const uint256_t P = (1_u256 << 255) - 19; +static const u256 P = (1_u256 << 255) - 19; struct Modulo25519 { Modulo25519() = default; Modulo25519(const Modulo25519& source) : value(source.value) {} template Modulo25519(const T& value) : value(value) {} explicit operator bool() const { return (bool)value; } - auto operator()() const -> uint256_t { return value; } + auto operator()() const -> u256 { return value; } private: - uint256_t value; + u256 value; }; inline auto operator-(const Modulo25519& lhs) -> Modulo25519 { @@ -25,36 +25,36 @@ inline auto operator-(const Modulo25519& lhs) -> Modulo25519 { } inline auto operator+(const Modulo25519& lhs, const Modulo25519& rhs) -> Modulo25519 { - uint512_t value = (uint512_t)lhs() + rhs(); + u512 value = (u512)lhs() + rhs(); if(value >= P) value -= P; return value; } inline auto operator-(const Modulo25519& lhs, const Modulo25519& rhs) -> Modulo25519 { - uint512_t value = (uint512_t)lhs(); + u512 value = (u512)lhs(); if(value < rhs()) value += P; - return uint256_t(value - rhs()); + return u256(value - rhs()); } inline auto operator*(const Modulo25519& lhs, const Modulo25519& rhs) -> Modulo25519 { static const BarrettReduction<256> P{EllipticCurve::P}; - uint256_t hi, lo; + u256 hi, lo; mul(lhs(), rhs(), hi, lo); - return uint512_t{hi, lo} % P; + return u512{hi, lo} % P; } -inline auto operator&(const Modulo25519& lhs, uint256_t rhs) -> uint256_t { +inline auto operator&(const Modulo25519& lhs, u256 rhs) -> u256 { return lhs() & rhs; } inline auto square(const Modulo25519& lhs) -> Modulo25519 { static const BarrettReduction<256> P{EllipticCurve::P}; - uint256_t hi, lo; + u256 hi, lo; square(lhs(), hi, lo); - return uint512_t{hi, lo} % P; + return u512{hi, lo} % P; } -inline auto exponentiate(const Modulo25519& lhs, uint256_t exponent) -> Modulo25519 { +inline auto exponentiate(const Modulo25519& lhs, u256 exponent) -> Modulo25519 { if(exponent == 0) return 1; Modulo25519 value = square(exponentiate(lhs, exponent >> 1)); if(exponent & 1) value = value * lhs; diff --git a/nall/emulation/21fx.hpp b/nall/emulation/21fx.hpp index 7a663df025..fd36ce26d4 100644 --- a/nall/emulation/21fx.hpp +++ b/nall/emulation/21fx.hpp @@ -4,33 +4,21 @@ #include using namespace nall; -using int8 = Integer< 8>; -using int16 = Integer<16>; -using int24 = Integer<24>; -using int32 = Integer<32>; -using int64 = Integer<64>; - -using uint8 = Natural< 8>; -using uint16 = Natural<16>; -using uint24 = Natural<24>; -using uint32 = Natural<32>; -using uint64 = Natural<64>; - struct FX { auto open(Arguments& arguments) -> bool; auto close() -> void; auto readable() -> bool; - auto read() -> uint8_t; + auto read() -> u8; auto writable() -> bool; - auto write(uint8_t data) -> void; + auto write(u8 data) -> void; - auto read(uint offset, uint length) -> vector; - auto write(uint offset, const void* buffer, uint length) -> void; - auto write(uint offset, const vector& buffer) -> void { write(offset, buffer.data(), buffer.size()); } - auto execute(uint offset) -> void; + auto read(u32 offset, u32 length) -> vector; + auto write(u32 offset, const void* buffer, u32 length) -> void; + auto write(u32 offset, const vector& buffer) -> void { write(offset, buffer.data(), buffer.size()); } + auto execute(u32 offset) -> void; - auto read(uint offset) -> uint8_t; - auto write(uint offset, uint8_t data) -> void; + auto read(u32 offset) -> u8; + auto write(u32 offset, u8 data) -> void; serial device; }; @@ -64,9 +52,9 @@ inline auto FX::readable() -> bool { } //1000ns delay avoids burning CPU core at 100%; does not slow down max transfer rate at all -inline auto FX::read() -> uint8_t { +inline auto FX::read() -> u8 { while(!readable()) usleep(1000); - uint8_t buffer[1] = {0}; + u8 buffer[1] = {0}; device.read(buffer, 1); return buffer[0]; } @@ -75,15 +63,15 @@ inline auto FX::writable() -> bool { return device.writable(); } -inline auto FX::write(uint8_t data) -> void { +inline auto FX::write(u8 data) -> void { while(!writable()) usleep(1000); - uint8_t buffer[1] = {data}; + u8 buffer[1] = {data}; device.write(buffer, 1); } // -inline auto FX::read(uint offset, uint length) -> vector { +inline auto FX::read(u32 offset, u32 length) -> vector { write(0x21); write(0x66); write(0x78); @@ -95,12 +83,12 @@ inline auto FX::read(uint offset, uint length) -> vector { write(length >> 0); write(0x00); - vector buffer; + vector buffer; while(length--) buffer.append(read()); return buffer; } -inline auto FX::write(uint offset, const void* data, uint length) -> void { +inline auto FX::write(u32 offset, const void* data, u32 length) -> void { write(0x21); write(0x66); write(0x78); @@ -112,12 +100,12 @@ inline auto FX::write(uint offset, const void* data, uint length) -> void { write(length >> 0); write(0x01); - auto buffer = (uint8_t*)data; + auto buffer = (u8*)data; for(auto n : range(length)) write(buffer[n]); write(0x00); } -inline auto FX::execute(uint offset) -> void { +inline auto FX::execute(u32 offset) -> void { write(0x21); write(0x66); write(0x78); @@ -129,12 +117,12 @@ inline auto FX::execute(uint offset) -> void { // -inline auto FX::read(uint offset) -> uint8_t { +inline auto FX::read(u32 offset) -> u8 { auto buffer = read(offset, 1); return buffer[0]; } -inline auto FX::write(uint offset, uint8_t data) -> void { - vector buffer = {data}; +inline auto FX::write(u32 offset, u8 data) -> void { + vector buffer = {data}; write(offset, buffer); } diff --git a/nall/encode/base.hpp b/nall/encode/base.hpp index ac55486ee6..295b0b2be5 100644 --- a/nall/encode/base.hpp +++ b/nall/encode/base.hpp @@ -9,7 +9,7 @@ namespace nall::Encode { -template inline auto Base(T value) -> string { +template inline auto Base(T value) -> string { static const string format = Bits == 2 ? "01" : Bits == 8 ? "01234567" @@ -23,7 +23,7 @@ template inline auto Base(T value) -> string { : Bits == 64 ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}" : Bits == 85 ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%()+,-.:;=@[]^_`{|}~" //\ "&'*/<>? : ""; - static const uint size = ceil(sizeof(T) * 8 / log2(Bits)); + static const u32 size = ceil(sizeof(T) * 8 / log2(Bits)); string result; result.resize(size); diff --git a/nall/encode/base64.hpp b/nall/encode/base64.hpp index a1d518cf99..eb8d314f17 100644 --- a/nall/encode/base64.hpp +++ b/nall/encode/base64.hpp @@ -2,14 +2,14 @@ namespace nall::Encode { -inline auto Base64(const void* vdata, uint size, const string& format = "MIME") -> string { +inline auto Base64(const void* vdata, u32 size, const string& format = "MIME") -> string { static bool initialized = false; - static char lookup[65] = {0}; + static char lookup[65] = {}; if(!initialized) { initialized = true; - for(uint n : range(26)) lookup[n + 0] = 'A' + n; - for(uint n : range(26)) lookup[n + 26] = 'a' + n; - for(uint n : range(10)) lookup[n + 52] = '0' + n; + for(u32 n : range(26)) lookup[n + 0] = 'A' + n; + for(u32 n : range(26)) lookup[n + 26] = 'a' + n; + for(u32 n : range(10)) lookup[n + 52] = '0' + n; } if(format == "MIME") { @@ -22,11 +22,11 @@ inline auto Base64(const void* vdata, uint size, const string& format = "MIME") lookup[64] = 0; } else return ""; - auto data = (const uint8_t*)vdata; - uint overflow = (3 - (size % 3)) % 3; //bytes to round to nearest multiple of 3 + auto data = (const u8*)vdata; + u32 overflow = (3 - (size % 3)) % 3; //bytes to round to nearest multiple of 3 string result; - uint8_t buffer; - for(uint n : range(size)) { + u8 buffer; + for(u32 n : range(size)) { switch(n % 3) { case 0: buffer = data[n] >> 2; @@ -57,7 +57,7 @@ inline auto Base64(const void* vdata, uint size, const string& format = "MIME") return result; } -inline auto Base64(const vector& buffer, const string& format = "MIME") -> string { +inline auto Base64(const vector& buffer, const string& format = "MIME") -> string { return Base64(buffer.data(), buffer.size(), format); } diff --git a/nall/encode/bmp.hpp b/nall/encode/bmp.hpp index 1ccc930470..87679b9995 100644 --- a/nall/encode/bmp.hpp +++ b/nall/encode/bmp.hpp @@ -3,16 +3,16 @@ namespace nall::Encode { struct BMP { - static auto create(const string& filename, const void* data, uint pitch, uint width, uint height, bool alpha) -> bool { + static auto create(const string& filename, const void* data, u32 pitch, u32 width, u32 height, bool alpha) -> bool { auto fp = file::open(filename, file::mode::write); if(!fp) return false; - uint bitsPerPixel = alpha ? 32 : 24; - uint bytesPerPixel = bitsPerPixel / 8; - uint alignedWidth = width * bytesPerPixel; - uint paddingLength = 0; - uint imageSize = alignedWidth * height; - uint fileSize = 0x36 + imageSize; + u32 bitsPerPixel = alpha ? 32 : 24; + u32 bytesPerPixel = bitsPerPixel / 8; + u32 alignedWidth = width * bytesPerPixel; + u32 paddingLength = 0; + u32 imageSize = alignedWidth * height; + u32 fileSize = 0x36 + imageSize; while(alignedWidth % 4) alignedWidth++, paddingLength++; fp.writel(0x4d42, 2); //signature @@ -35,7 +35,7 @@ struct BMP { pitch >>= 2; for(auto y : range(height)) { - auto p = (const uint32_t*)data + y * pitch; + auto p = (const u32*)data + y * pitch; for(auto x : range(width)) fp.writel(*p++, bytesPerPixel); if(paddingLength) fp.writel(0, paddingLength); } diff --git a/nall/encode/bwt.hpp b/nall/encode/bwt.hpp index 84e00d9c49..61cd69bda0 100644 --- a/nall/encode/bwt.hpp +++ b/nall/encode/bwt.hpp @@ -49,36 +49,36 @@ namespace nall::Encode { Although to be fair, BWT is inferior to the bijective BWT anyway, so it may not be worth the effort. */ -inline auto BWT(array_view input) -> vector { +inline auto BWT(array_view input) -> vector { auto size = input.size(); - vector output; + vector output; output.reserve(8 + 8 + size); - for(uint byte : range(8)) output.append(size >> byte * 8); - for(uint byte : range(8)) output.append(0x00); + for(u32 byte : range(8)) output.append(size >> byte * 8); + for(u32 byte : range(8)) output.append(0x00); - vector buffer; + vector buffer; buffer.reserve(2 * size); - for(uint offset : range(size)) buffer.append(input[offset]); - for(uint offset : range(size)) buffer.append(input[offset]); + for(u32 offset : range(size)) buffer.append(input[offset]); + for(u32 offset : range(size)) buffer.append(input[offset]); auto suffixes = SuffixArray(buffer); - vector prefixes; + vector prefixes; prefixes.reserve(size); - for(uint offset : range(2 * size + 1)) { - uint suffix = suffixes[offset]; + for(u32 offset : range(2 * size + 1)) { + u32 suffix = suffixes[offset]; if(suffix >= size) continue; //beyond the bounds of the original input string prefixes.append(suffix); } - uint64_t root = 0; - for(uint offset : range(size)) { - uint suffix = prefixes[offset]; + u64 root = 0; + for(u32 offset : range(size)) { + u32 suffix = prefixes[offset]; if(suffix == 0) root = offset, suffix = size; output.append(input[--suffix]); } - for(uint byte : range(8)) output[8 + byte] = root >> byte * 8; + for(u32 byte : range(8)) output[8 + byte] = root >> byte * 8; return output; } diff --git a/nall/encode/huffman.hpp b/nall/encode/huffman.hpp index 18aa25f186..ca547d1e7b 100644 --- a/nall/encode/huffman.hpp +++ b/nall/encode/huffman.hpp @@ -2,28 +2,28 @@ namespace nall::Encode { -inline auto Huffman(array_view input) -> vector { - vector output; - for(uint byte : range(8)) output.append(input.size() >> byte * 8); +inline auto Huffman(array_view input) -> vector { + vector output; + for(u32 byte : range(8)) output.append(input.size() >> byte * 8); struct Node { - uint frequency = 0; - uint parent = 0; - uint lhs = 0; - uint rhs = 0; + u32 frequency = 0; + u32 parent = 0; + u32 lhs = 0; + u32 rhs = 0; }; array nodes; - for(uint offset : range(input.size())) nodes[input[offset]].frequency++; + for(u32 offset : range(input.size())) nodes[input[offset]].frequency++; - uint count = 0; - for(uint offset : range(511)) { + u32 count = 0; + for(u32 offset : range(511)) { if(nodes[offset].frequency) count++; else nodes[offset].parent = 511; } auto minimum = [&] { - uint frequency = ~0, minimum = 511; - for(uint index : range(511)) { + u32 frequency = ~0, minimum = 511; + for(u32 index : range(511)) { if(!nodes[index].parent && nodes[index].frequency && nodes[index].frequency < frequency) { frequency = nodes[index].frequency; minimum = index; @@ -33,11 +33,11 @@ inline auto Huffman(array_view input) -> vector { }; //group the least two frequently used nodes until only one node remains - uint index = 256; - for(uint remaining = max(2, count); remaining >= 2; remaining--) { - uint lhs = minimum(); + u32 index = 256; + for(u32 remaining = max(2, count); remaining >= 2; remaining--) { + u32 lhs = minimum(); nodes[lhs].parent = index; - uint rhs = minimum(); + u32 rhs = minimum(); nodes[rhs].parent = index; if(remaining == 2) index = nodes[lhs].parent = nodes[rhs].parent = 511; nodes[index].lhs = lhs; @@ -47,7 +47,7 @@ inline auto Huffman(array_view input) -> vector { index++; } - uint byte = 0, bits = 0; + u32 byte = 0, bits = 0; auto write = [&](bool bit) { byte = byte << 1 | bit; if(++bits == 8) output.append(byte), bits = 0; @@ -55,24 +55,24 @@ inline auto Huffman(array_view input) -> vector { //only the upper half of the table is needed for decompression //the first 256 nodes are always treated as leaf nodes - for(uint offset : range(256)) { - for(uint index : reverse(range(9))) write(nodes[256 + offset].lhs >> index & 1); - for(uint index : reverse(range(9))) write(nodes[256 + offset].rhs >> index & 1); + for(u32 offset : range(256)) { + for(u32 index : reverse(range(9))) write(nodes[256 + offset].lhs >> index & 1); + for(u32 index : reverse(range(9))) write(nodes[256 + offset].rhs >> index & 1); } - for(uint byte : input) { - uint node = byte, length = 0; - uint256_t sequence = 0; + for(u32 byte : input) { + u32 node = byte, length = 0; + u256 sequence = 0; //traversing the array produces the bitstream in reverse order do { - uint parent = nodes[node].parent; + u32 parent = nodes[node].parent; bool bit = nodes[nodes[node].parent].rhs == node; sequence = sequence << 1 | bit; length++; node = parent; } while(node != 511); //output the generated bits in the correct order - for(uint index : range(length)) { + for(u32 index : range(length)) { write(sequence >> index & 1); } } diff --git a/nall/encode/lzsa.hpp b/nall/encode/lzsa.hpp index 2ca59b6eaf..b1394972d8 100644 --- a/nall/encode/lzsa.hpp +++ b/nall/encode/lzsa.hpp @@ -8,28 +8,28 @@ namespace nall::Encode { -inline auto LZSA(array_view input) -> vector { - vector output; - for(uint byte : range(8)) output.append(input.size() >> byte * 8); +inline auto LZSA(array_view input) -> vector { + vector output; + for(u32 byte : range(8)) output.append(input.size() >> byte * 8); auto suffixArray = SuffixArray(input).lpf(); - uint index = 0; - vector flags; - vector literals; - vector stringLengths; - vector stringOffsets; + u32 index = 0; + vector flags; + vector literals; + vector stringLengths; + vector stringOffsets; - uint byte = 0, bits = 0; + u32 byte = 0, bits = 0; auto flagWrite = [&](bool bit) { byte = byte << 1 | bit; if(++bits == 8) flags.append(byte), bits = 0; }; - auto literalWrite = [&](uint8_t literal) { + auto literalWrite = [&](u8 literal) { literals.append(literal); }; - auto lengthWrite = [&](uint64_t length) { + auto lengthWrite = [&](u64 length) { if(length < 1 << 7) length = length << 1 | 0b1; else if(length < 1 << 14) length = length << 2 | 0b10; else if(length < 1 << 21) length = length << 3 | 0b100; @@ -38,7 +38,7 @@ inline auto LZSA(array_view input) -> vector { while(length) stringLengths.append(length), length >>= 8; }; - auto offsetWrite = [&](uint offset) { + auto offsetWrite = [&](u32 offset) { stringOffsets.append(offset >> 0); if(index < 1 << 8) return; stringOffsets.append(offset >> 8); if(index < 1 << 16) return; stringOffsets.append(offset >> 16); if(index < 1 << 24) return; @@ -46,11 +46,11 @@ inline auto LZSA(array_view input) -> vector { }; while(index < input.size()) { - int length, offset; + s32 length, offset; suffixArray.previous(length, offset, index); -/* for(uint ahead = 1; ahead <= 2; ahead++) { - int aheadLength, aheadOffset; +/* for(u32 ahead = 1; ahead <= 2; ahead++) { + s32 aheadLength, aheadOffset; suffixArray.previous(aheadLength, aheadOffset, index + ahead); if(aheadLength > length && aheadOffset >= 0) { length = 0; @@ -70,8 +70,8 @@ inline auto LZSA(array_view input) -> vector { } while(bits) flagWrite(0); - auto save = [&](const vector& buffer) { - for(uint byte : range(8)) output.append(buffer.size() >> byte * 8); + auto save = [&](const vector& buffer) { + for(u32 byte : range(8)) output.append(buffer.size() >> byte * 8); output.append(buffer); }; diff --git a/nall/encode/mtf.hpp b/nall/encode/mtf.hpp index 42f24b1958..0525031bc6 100644 --- a/nall/encode/mtf.hpp +++ b/nall/encode/mtf.hpp @@ -4,17 +4,17 @@ namespace nall::Encode { -inline auto MTF(array_view input) -> vector { - vector output; +inline auto MTF(array_view input) -> vector { + vector output; output.resize(input.size()); - uint8_t order[256]; - for(uint n : range(256)) order[n] = n; + u8 order[256]; + for(u32 n : range(256)) order[n] = n; - for(uint offset : range(input.size())) { - uint data = input[offset]; - for(uint index : range(256)) { - uint value = order[index]; + for(u32 offset : range(input.size())) { + u32 data = input[offset]; + for(u32 index : range(256)) { + u32 value = order[index]; if(value == data) { output[offset] = index; memory::move(&order[1], &order[0], index); diff --git a/nall/encode/png.hpp b/nall/encode/png.hpp index 6f2233f942..6bf2d9c12c 100644 --- a/nall/encode/png.hpp +++ b/nall/encode/png.hpp @@ -11,8 +11,8 @@ namespace nall::Encode { //if nall gains a deflate implementation one day, then this can be improved to offer integrated compression. struct PNG { - static auto RGB8 (const string& filename, const void* data, uint pitch, uint width, uint height) -> bool; - static auto RGBA8(const string& filename, const void* data, uint pitch, uint width, uint height) -> bool; + static auto RGB8 (const string& filename, const void* data, u32 pitch, u32 width, u32 height) -> bool; + static auto RGBA8(const string& filename, const void* data, u32 pitch, u32 width, u32 height) -> bool; private: auto compress(const string& filename) -> bool; @@ -20,31 +20,31 @@ struct PNG { auto close() -> void; auto header() -> void; auto footer() -> void; - auto information(uint width, uint height, uint depth, uint type) -> void; - auto dataHeader(uint width, uint height, uint bitsPerPixel) -> void; + auto information(u32 width, u32 height, u32 depth, u32 type) -> void; + auto dataHeader(u32 width, u32 height, u32 bitsPerPixel) -> void; auto dataLine(bool lastLine) -> void; auto dataFooter() -> void; - auto write(uint8_t data) -> void; - auto adler(uint8_t data) -> void; + auto write(u8 data) -> void; + auto adler(u8 data) -> void; file_buffer fp; Hash::CRC32 crc32; - uint16_t adler1 = 1; - uint16_t adler2 = 0; - uint16_t bytesPerLine = 0; + u16 adler1 = 1; + u16 adler2 = 0; + u16 bytesPerLine = 0; }; -inline auto PNG::RGB8(const string& filename, const void* data, uint pitch, uint width, uint height) -> bool { +inline auto PNG::RGB8(const string& filename, const void* data, u32 pitch, u32 width, u32 height) -> bool { PNG png; if(!png.open(filename)) return false; png.header(); png.information(width, height, 8, 2); png.dataHeader(width, height, 24); - for(uint y : range(height)) { - const auto input = (const uint32_t*)data + y * (pitch >> 2); + for(u32 y : range(height)) { + const auto input = (const u32*)data + y * (pitch >> 2); png.dataLine(y == height - 1); - for(uint x : range(width)) { + for(u32 x : range(width)) { auto pixel = input[x]; //RGB png.adler(pixel >> 16); //R png.adler(pixel >> 8); //G @@ -58,17 +58,17 @@ inline auto PNG::RGB8(const string& filename, const void* data, uint pitch, uint return true; } -inline auto PNG::RGBA8(const string& filename, const void* data, uint pitch, uint width, uint height) -> bool { +inline auto PNG::RGBA8(const string& filename, const void* data, u32 pitch, u32 width, u32 height) -> bool { PNG png; if(!png.open(filename)) return false; png.header(); png.information(width, height, 8, 6); png.dataHeader(width, height, 32); - for(uint y : range(height)) { - const auto input = (const uint32_t*)data + y * (pitch >> 2); + for(u32 y : range(height)) { + const auto input = (const u32*)data + y * (pitch >> 2); png.dataLine(y == height - 1); - for(uint x : range(width)) { + for(u32 x : range(width)) { auto pixel = input[x]; //ARGB png.adler(pixel >> 16); //R png.adler(pixel >> 8); //G @@ -122,7 +122,7 @@ inline auto PNG::footer() -> void { fp.writem(crc32.value(), 4L); } -inline auto PNG::information(uint width, uint height, uint depth, uint type) -> void { +inline auto PNG::information(u32 width, u32 height, u32 depth, u32 type) -> void { fp.writem(13, 4L); crc32.reset(); write('I'); @@ -145,9 +145,9 @@ inline auto PNG::information(uint width, uint height, uint depth, uint type) -> fp.writem(crc32.value(), 4L); } -inline auto PNG::dataHeader(uint width, uint height, uint bitsPerPixel) -> void { +inline auto PNG::dataHeader(u32 width, u32 height, u32 bitsPerPixel) -> void { bytesPerLine = 1 + width * (bitsPerPixel / 8); - uint idatSize = 2 + height * (5 + bytesPerLine) + 4; + u32 idatSize = 2 + height * (5 + bytesPerLine) + 4; fp.writem(idatSize, 4L); crc32.reset(); write('I'); @@ -175,12 +175,12 @@ inline auto PNG::dataFooter() -> void { fp.writem(crc32.value(), 4L); } -inline auto PNG::write(uint8_t data) -> void { +inline auto PNG::write(u8 data) -> void { fp.write(data); crc32.input(data); } -inline auto PNG::adler(uint8_t data) -> void { +inline auto PNG::adler(u8 data) -> void { write(data); adler1 = (adler1 + data ) % 65521; adler2 = (adler2 + adler1) % 65521; diff --git a/nall/encode/rle.hpp b/nall/encode/rle.hpp index da88fff978..71ce5273a4 100644 --- a/nall/encode/rle.hpp +++ b/nall/encode/rle.hpp @@ -2,26 +2,26 @@ namespace nall::Encode { -template //S = word size; M = match length -inline auto RLE(array_view input) -> vector { - vector output; - for(uint byte : range(8)) output.append(input.size() >> byte * 8); +template //S = word size; M = match length +inline auto RLE(array_view input) -> vector { + vector output; + for(u32 byte : range(8)) output.append(input.size() >> byte * 8); - uint base = 0; - uint skip = 0; + u32 base = 0; + u32 skip = 0; - auto load = [&](uint offset) -> uint8_t { + auto load = [&](u32 offset) -> u8 { return input(offset); }; - auto read = [&](uint offset) -> uint64_t { - uint64_t value = 0; - for(uint byte : range(S)) value |= load(offset + byte) << byte * 8; + auto read = [&](u32 offset) -> u64 { + u64 value = 0; + for(u32 byte : range(S)) value |= load(offset + byte) << byte * 8; return value; }; - auto write = [&](uint64_t value) -> void { - for(uint byte : range(S)) output.append(value >> byte * 8); + auto write = [&](u64 value) -> void { + for(u32 byte : range(S)) output.append(value >> byte * 8); }; auto flush = [&] { @@ -33,8 +33,8 @@ inline auto RLE(array_view input) -> vector { }; while(base + S * skip < input.size()) { - uint same = 1; - for(uint offset = base + S * (skip + 1); offset < input.size(); offset += S) { + u32 same = 1; + for(u32 offset = base + S * (skip + 1); offset < input.size(); offset += S) { if(read(offset) != read(base + S * skip)) break; if(++same == 127 + M) break; } diff --git a/nall/encode/url.hpp b/nall/encode/url.hpp index 1f422e5d22..55ee2bf92f 100644 --- a/nall/encode/url.hpp +++ b/nall/encode/url.hpp @@ -15,8 +15,8 @@ inline auto URL(string_view input) -> string { if(c == ' ') { output.append('+'); continue; } //reserved characters - uint hi = (c >> 4) & 15; - uint lo = (c >> 0) & 15; + u32 hi = (c >> 4) & 15; + u32 lo = (c >> 0) & 15; output.append('%'); output.append((char)(hi < 10 ? ('0' + hi) : ('a' + hi - 10))); output.append((char)(lo < 10 ? ('0' + lo) : ('a' + lo - 10))); diff --git a/nall/encode/wav.hpp b/nall/encode/wav.hpp index 1b42485576..cbee9e6d6a 100644 --- a/nall/encode/wav.hpp +++ b/nall/encode/wav.hpp @@ -3,11 +3,11 @@ namespace nall::Encode { struct WAV { - static auto stereo_16bit(const string& filename, array_view left, array_view right, uint frequency) -> bool { + static auto stereo_16bit(const string& filename, array_view left, array_view right, u32 frequency) -> bool { if(left.size() != right.size()) return false; - static uint channels = 2; - static uint bits = 16; - static uint samples = left.size(); + static u32 channels = 2; + static u32 bits = 16; + static u32 samples = left.size(); file_buffer fp; if(!fp.open(filename, file::mode::write)) return false; @@ -40,7 +40,7 @@ struct WAV { fp.write('t'); fp.write('a'); fp.writel(samples * 4, 4); - for(uint sample : range(samples)) { + for(u32 sample : range(samples)) { fp.writel(left[sample], 2); fp.writel(right[sample], 2); } diff --git a/nall/encode/zip.hpp b/nall/encode/zip.hpp index b98376d76c..f23cfa740e 100644 --- a/nall/encode/zip.hpp +++ b/nall/encode/zip.hpp @@ -15,11 +15,11 @@ struct ZIP { //append path: append("path/"); //append file: append("path/file", data, size); - auto append(string filename, const uint8_t* data = nullptr, uint size = 0u, time_t timestamp = 0) -> void { + auto append(string filename, const u8* data = nullptr, u32 size = 0u, time_t timestamp = 0) -> void { filename.transform("\\", "/"); if(!timestamp) timestamp = this->timestamp; - uint32_t checksum = Hash::CRC32({data, size}).digest().hex(); - directory.append({filename, timestamp, checksum, size, (uint32_t)fp.offset()}); + u32 checksum = Hash::CRC32({data, size}).digest().hex(); + directory.append({filename, timestamp, checksum, size, (u32)fp.offset()}); fp.writel(0x04034b50, 4); //signature fp.writel(0x0014, 2); //minimum version (2.0) @@ -39,7 +39,7 @@ struct ZIP { ~ZIP() { //central directory - uint baseOffset = fp.offset(); + u32 baseOffset = fp.offset(); for(auto& entry : directory) { fp.writel(0x02014b50, 4); //signature fp.writel(0x0014, 2); //version made by (2.0) @@ -60,7 +60,7 @@ struct ZIP { fp.writel(entry.offset, 4); //relative offset of file header fp.print(entry.filename); } - uint finishOffset = fp.offset(); + u32 finishOffset = fp.offset(); //end of central directory fp.writel(0x06054b50, 4); //signature @@ -76,12 +76,12 @@ struct ZIP { } protected: - auto makeTime(time_t timestamp) -> uint16_t { + auto makeTime(time_t timestamp) -> u16 { tm* info = localtime(×tamp); return (info->tm_hour << 11) | (info->tm_min << 5) | (info->tm_sec >> 1); } - auto makeDate(time_t timestamp) -> uint16_t { + auto makeDate(time_t timestamp) -> u16 { tm* info = localtime(×tamp); return ((info->tm_year - 80) << 9) | ((1 + info->tm_mon) << 5) + (info->tm_mday); } @@ -91,9 +91,9 @@ struct ZIP { struct entry_t { string filename; time_t timestamp; - uint32_t checksum; - uint32_t size; - uint32_t offset; + u32 checksum; + u32 size; + u32 offset; }; vector directory; }; diff --git a/nall/file-buffer.hpp b/nall/file-buffer.hpp index 1ee6b52822..8a9efceefc 100644 --- a/nall/file-buffer.hpp +++ b/nall/file-buffer.hpp @@ -20,14 +20,14 @@ namespace nall { //this speeds up Windows substantially, without harming performance elsewhere much struct file_buffer { - struct mode { enum : uint { read, write, modify, append }; }; - struct index { enum : uint { absolute, relative }; }; + struct mode { enum : u32 { read, write, modify, append }; }; + struct index { enum : u32 { absolute, relative }; }; file_buffer(const file_buffer&) = delete; auto operator=(const file_buffer&) -> file_buffer& = delete; file_buffer() = default; - file_buffer(const string& filename, uint mode) { open(filename, mode); } + file_buffer(const string& filename, u32 mode) { open(filename, mode); } file_buffer(file_buffer&& source) { operator=(move(source)); } @@ -56,22 +56,22 @@ struct file_buffer { return (bool)fileHandle; } - auto read() -> uint8_t { + auto read() -> u8 { if(!fileHandle) return 0; //file not open if(fileOffset >= fileSize) return 0; //cannot read past end of file bufferSynchronize(); return buffer[fileOffset++ & buffer.size() - 1]; } - template auto readl(uint length = 1) -> T { + template auto readl(u32 length = 1) -> T { T data = 0; - for(uint n : range(length)) { + for(u32 n : range(length)) { data |= (T)read() << n * 8; } return data; } - template auto readm(uint length = 1) -> T { + template auto readm(u32 length = 1) -> T { T data = 0; while(length--) { data <<= 8; @@ -80,18 +80,18 @@ struct file_buffer { return data; } - auto reads(uint length) -> string { + auto reads(u32 length) -> string { string result; result.resize(length); for(auto& byte : result) byte = read(); return result; } - auto read(array_span memory) -> void { + auto read(array_span memory) -> void { for(auto& byte : memory) byte = read(); } - auto write(uint8_t data) -> void { + auto write(u8 data) -> void { if(!fileHandle) return; //file not open if(fileMode == mode::read) return; //writes not permitted bufferSynchronize(); @@ -100,16 +100,16 @@ struct file_buffer { if(fileOffset > fileSize) fileSize = fileOffset; } - template auto writel(T data, uint length = 1) -> void { + template auto writel(T data, u32 length = 1) -> void { while(length--) { - write(uint8_t(data)); + write(u8(data)); data >>= 8; } } - template auto writem(T data, uint length = 1) -> void { - for(uint n : reverse(range(length))) { - write(uint8_t(data >> n * 8)); + template auto writem(T data, u32 length = 1) -> void { + for(u32 n : reverse(range(length))) { + write(u8(data >> n * 8)); } } @@ -117,7 +117,7 @@ struct file_buffer { for(auto& byte : s) write(byte); } - auto write(array_view memory) -> void { + auto write(array_view memory) -> void { for(auto& byte : memory) write(byte); } @@ -131,11 +131,11 @@ struct file_buffer { fflush(fileHandle); } - auto seek(int64_t offset, uint index_ = index::absolute) -> void { + auto seek(s64 offset, u32 index_ = index::absolute) -> void { if(!fileHandle) return; bufferFlush(); - int64_t seekOffset = fileOffset; + s64 seekOffset = fileOffset; switch(index_) { case index::absolute: seekOffset = offset; break; case index::relative: seekOffset += offset; break; @@ -154,17 +154,17 @@ struct file_buffer { fileOffset = seekOffset; } - auto offset() const -> uint64_t { + auto offset() const -> u64 { if(!fileHandle) return 0; return fileOffset; } - auto size() const -> uint64_t { + auto size() const -> u64 { if(!fileHandle) return 0; return fileSize; } - auto truncate(uint64_t size) -> bool { + auto truncate(u64 size) -> bool { if(!fileHandle) return false; #if defined(API_POSIX) return ftruncate(fileno(fileHandle), size) == 0; @@ -178,7 +178,7 @@ struct file_buffer { return fileOffset >= fileSize; } - auto open(const string& filename, uint mode_) -> bool { + auto open(const string& filename, u32 mode_) -> bool { close(); switch(fileMode = mode_) { @@ -186,12 +186,12 @@ struct file_buffer { case mode::read: fileHandle = fopen(filename, "rb" ); break; case mode::write: fileHandle = fopen(filename, "wb+"); break; //need read permission for buffering case mode::modify: fileHandle = fopen(filename, "rb+"); break; - case mode::append: fileHandle = fopen(filename, "wb+"); break; + case mode::append: fileHandle = fopen(filename, "ab+"); break; #elif defined(API_WINDOWS) case mode::read: fileHandle = _wfopen(utf16_t(filename), L"rb" ); break; case mode::write: fileHandle = _wfopen(utf16_t(filename), L"wb+"); break; case mode::modify: fileHandle = _wfopen(utf16_t(filename), L"rb+"); break; - case mode::append: fileHandle = _wfopen(utf16_t(filename), L"wb+"); break; + case mode::append: fileHandle = _wfopen(utf16_t(filename), L"ab+"); break; #endif } if(!fileHandle) return false; @@ -212,13 +212,13 @@ struct file_buffer { } private: - array buffer; - int bufferOffset = -1; + array buffer; + s32 bufferOffset = -1; bool bufferDirty = false; FILE* fileHandle = nullptr; - uint64_t fileOffset = 0; - uint64_t fileSize = 0; - uint fileMode = mode::read; + u64 fileOffset = 0; + u64 fileSize = 0; + u32 fileMode = mode::read; auto bufferSynchronize() -> void { if(!fileHandle) return; @@ -227,7 +227,7 @@ struct file_buffer { bufferFlush(); bufferOffset = fileOffset & ~(buffer.size() - 1); fseek(fileHandle, bufferOffset, SEEK_SET); - uint64_t length = bufferOffset + buffer.size() <= fileSize ? buffer.size() : fileSize & buffer.size() - 1; + u64 length = bufferOffset + buffer.size() <= fileSize ? buffer.size() : fileSize & buffer.size() - 1; if(length) (void)fread(buffer.data(), 1, length, fileHandle); } @@ -238,7 +238,7 @@ struct file_buffer { if(!bufferDirty) return; //buffer unmodified since read fseek(fileHandle, bufferOffset, SEEK_SET); - uint64_t length = bufferOffset + buffer.size() <= fileSize ? buffer.size() : fileSize & buffer.size() - 1; + u64 length = bufferOffset + buffer.size() <= fileSize ? buffer.size() : fileSize & buffer.size() - 1; if(length) (void)fwrite(buffer.data(), 1, length, fileHandle); bufferOffset = -1; bufferDirty = false; diff --git a/nall/file-map.hpp b/nall/file-map.hpp index 647a823be6..1c7d79221d 100644 --- a/nall/file-map.hpp +++ b/nall/file-map.hpp @@ -23,30 +23,30 @@ namespace nall { struct file_map { - struct mode { enum : uint { read, write, modify, append }; }; + struct mode { enum : u32 { read, write, modify, append }; }; file_map(const file_map&) = delete; auto operator=(const file_map&) = delete; file_map() = default; file_map(file_map&& source) { operator=(move(source)); } - file_map(const string& filename, uint mode) { open(filename, mode); } + file_map(const string& filename, u32 mode) { open(filename, mode); } ~file_map() { close(); } explicit operator bool() const { return _open; } - auto size() const -> uint64_t { return _size; } - auto data() -> uint8_t* { return _data; } - auto data() const -> const uint8_t* { return _data; } + auto size() const -> u64 { return _size; } + auto data() -> u8* { return _data; } + auto data() const -> const u8* { return _data; } //auto operator=(file_map&& source) -> file_map&; -//auto open(const string& filename, uint mode) -> bool; +//auto open(const string& filename, u32 mode) -> bool; //auto close() -> void; private: bool _open = false; //zero-byte files return _data = nullptr, _size = 0 - uint8_t* _data = nullptr; - uint64_t _size = 0; + u8* _data = nullptr; + u64 _size = 0; #if defined(API_WINDOWS) @@ -70,11 +70,11 @@ struct file_map { return *this; } - auto open(const string& filename, uint mode_) -> bool { + auto open(const string& filename, u32 mode_) -> bool { close(); if(file::exists(filename) && file::size(filename) == 0) return _open = true; - int desiredAccess, creationDisposition, protection, mapAccess; + s32 desiredAccess, creationDisposition, protection, mapAccess; switch(mode_) { default: return false; @@ -118,7 +118,7 @@ struct file_map { return false; } - _data = (uint8_t*)MapViewOfFile(_map, mapAccess, 0, 0, _size); + _data = (u8*)MapViewOfFile(_map, mapAccess, 0, 0, _size); return _open = true; } @@ -143,7 +143,7 @@ struct file_map { #else - int _fd = -1; + s32 _fd = -1; public: auto operator=(file_map&& source) -> file_map& { @@ -160,12 +160,12 @@ struct file_map { return *this; } - auto open(const string& filename, uint mode_) -> bool { + auto open(const string& filename, u32 mode_) -> bool { close(); if(file::exists(filename) && file::size(filename) == 0) return _open = true; - int openFlags = 0; - int mmapFlags = 0; + s32 openFlags = 0; + s32 mmapFlags = 0; switch(mode_) { default: return false; @@ -194,7 +194,7 @@ struct file_map { fstat(_fd, &_stat); _size = _stat.st_size; - _data = (uint8_t*)mmap(nullptr, _size, mmapFlags, MAP_SHARED | MAP_NORESERVE, _fd, 0); + _data = (u8*)mmap(nullptr, _size, mmapFlags, MAP_SHARED | MAP_NORESERVE, _fd, 0); if(_data == MAP_FAILED) { _data = nullptr; ::close(_fd); diff --git a/nall/file.hpp b/nall/file.hpp index 307952f0ca..a4bec188ba 100644 --- a/nall/file.hpp +++ b/nall/file.hpp @@ -5,12 +5,12 @@ namespace nall { struct file : inode { - struct mode { enum : uint { read, write, modify, append }; }; - struct index { enum : uint { absolute, relative }; }; + struct mode { enum : u32 { read, write, modify, append }; }; + struct index { enum : u32 { absolute, relative }; }; file() = delete; - static auto open(const string& filename, uint mode) -> file_buffer { + static auto open(const string& filename, u32 mode) -> file_buffer { return file_buffer{filename, mode}; } @@ -18,7 +18,7 @@ struct file : inode { if(sourcename == targetname) return true; if(auto reader = file::open(sourcename, mode::read)) { if(auto writer = file::open(targetname, mode::write)) { - for(uint64_t n : range(reader.size())) writer.write(reader.read()); + for(u64 n : range(reader.size())) writer.write(reader.read()); return true; } } @@ -35,7 +35,7 @@ struct file : inode { return false; } - static auto truncate(const string& filename, uint64_t size) -> bool { + static auto truncate(const string& filename, u64 size) -> bool { #if defined(API_POSIX) return ::truncate(filename, size) == 0; #elif defined(API_WINDOWS) @@ -60,7 +60,7 @@ struct file : inode { return !(data.st_mode & S_IFDIR); } - static auto size(const string& filename) -> uint64_t { + static auto size(const string& filename) -> u64 { #if defined(API_POSIX) struct stat data; stat(filename, &data); @@ -71,8 +71,8 @@ struct file : inode { return S_ISREG(data.st_mode) ? data.st_size : 0u; } - static auto read(const string& filename) -> vector { - vector memory; + static auto read(const string& filename) -> vector { + vector memory; if(auto fp = file::open(filename, mode::read)) { memory.resize(fp.size()); fp.read(memory); @@ -80,12 +80,12 @@ struct file : inode { return memory; } - static auto read(const string& filename, array_span memory) -> bool { + static auto read(const string& filename, array_span memory) -> bool { if(auto fp = file::open(filename, mode::read)) return fp.read(memory), true; return false; } - static auto write(const string& filename, array_view memory) -> bool { + static auto write(const string& filename, array_view memory) -> bool { if(auto fp = file::open(filename, mode::write)) return fp.write(memory), true; return false; } diff --git a/nall/galois-field.hpp b/nall/galois-field.hpp index 38f226979f..38f3bc5c63 100644 --- a/nall/galois-field.hpp +++ b/nall/galois-field.hpp @@ -5,11 +5,11 @@ namespace nall { -template +template struct GaloisField { using type = GaloisField; - GaloisField(uint x = 0) : x(x) {} + GaloisField(u32 x = 0) : x(x) {} operator field() const { return x; } auto operator^(field y) const -> type { return x ^ y; } @@ -28,16 +28,16 @@ struct GaloisField { auto pow(field y) const -> type { return exp(log(x) * y); } auto inv() const -> type { return exp(Elements - log(x)); } // 1/x - static auto log(uint x) -> uint { - enum : uint { Size = bit::round(Elements), Mask = Size - 1 }; + static auto log(u32 x) -> u32 { + enum : u32 { Size = bit::round(Elements), Mask = Size - 1 }; static array log = [] { - uint shift = 0, polynomial = Polynomial; + u32 shift = 0, polynomial = Polynomial; while(polynomial >>= 1) shift++; shift--; array log; field x = 1; - for(uint n : range(Elements)) { + for(u32 n : range(Elements)) { log[x] = n; x = x << 1 ^ (x >> shift ? Polynomial : 0); } @@ -47,15 +47,15 @@ struct GaloisField { return log[x & Mask]; } - static auto exp(uint x) -> uint { + static auto exp(u32 x) -> u32 { static array exp = [] { - uint shift = 0, polynomial = Polynomial; + u32 shift = 0, polynomial = Polynomial; while(polynomial >>= 1) shift++; shift--; array exp; field x = 1; - for(uint n : range(Elements)) { + for(u32 n : range(Elements)) { exp[n] = x; x = x << 1 ^ (x >> shift ? Polynomial : 0); } diff --git a/nall/hash/crc16.hpp b/nall/hash/crc16.hpp index 8058a40bac..ba041c4860 100644 --- a/nall/hash/crc16.hpp +++ b/nall/hash/crc16.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct CRC16 : Hash { using Hash::input; - CRC16(array_view buffer = {}) { + CRC16(array_view buffer = {}) { reset(); input(buffer); } @@ -16,29 +16,29 @@ struct CRC16 : Hash { checksum = ~0; } - auto input(uint8_t value) -> void override { + auto input(u8 value) -> void override { checksum = (checksum >> 8) ^ table(checksum ^ value); } - auto output() const -> vector override { - vector result; + auto output() const -> vector override { + vector result; for(auto n : reverse(range(2))) result.append(~checksum >> n * 8); return result; } - auto value() const -> uint16_t { + auto value() const -> u16 { return ~checksum; } private: - static auto table(uint8_t index) -> uint16_t { - static uint16_t table[256] = {0}; + static auto table(u8 index) -> u16 { + static u16 table[256] = {}; static bool initialized = false; if(!initialized) { initialized = true; for(auto index : range(256)) { - uint16_t crc = index; + u16 crc = index; for(auto bit : range(8)) { crc = (crc >> 1) ^ (crc & 1 ? 0x8408 : 0); } @@ -49,7 +49,7 @@ struct CRC16 : Hash { return table[index]; } - uint16_t checksum = 0; + u16 checksum = 0; }; } diff --git a/nall/hash/crc32.hpp b/nall/hash/crc32.hpp index 39318713d6..1b100ecbf5 100644 --- a/nall/hash/crc32.hpp +++ b/nall/hash/crc32.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct CRC32 : Hash { using Hash::input; - CRC32(array_view buffer = {}) { + CRC32(array_view buffer = {}) { reset(); input(buffer); } @@ -16,29 +16,29 @@ struct CRC32 : Hash { checksum = ~0; } - auto input(uint8_t value) -> void override { + auto input(u8 value) -> void override { checksum = (checksum >> 8) ^ table(checksum ^ value); } - auto output() const -> vector { - vector result; + auto output() const -> vector override { + vector result; for(auto n : reverse(range(4))) result.append(~checksum >> n * 8); return result; } - auto value() const -> uint32_t { + auto value() const -> u32 { return ~checksum; } private: - static auto table(uint8_t index) -> uint32_t { - static uint32_t table[256] = {0}; + static auto table(u8 index) -> u32 { + static u32 table[256] = {}; static bool initialized = false; if(!initialized) { initialized = true; for(auto index : range(256)) { - uint32_t crc = index; + u32 crc = index; for(auto bit : range(8)) { crc = (crc >> 1) ^ (crc & 1 ? 0xedb8'8320 : 0); } @@ -49,7 +49,7 @@ struct CRC32 : Hash { return table[index]; } - uint32_t checksum = 0; + u32 checksum = 0; }; } diff --git a/nall/hash/crc64.hpp b/nall/hash/crc64.hpp index 7364b0d8db..f065b07a7d 100644 --- a/nall/hash/crc64.hpp +++ b/nall/hash/crc64.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct CRC64 : Hash { using Hash::input; - CRC64(array_view buffer = {}) { + CRC64(array_view buffer = {}) { reset(); input(buffer); } @@ -16,29 +16,29 @@ struct CRC64 : Hash { checksum = ~0; } - auto input(uint8_t value) -> void override { + auto input(u8 value) -> void override { checksum = (checksum >> 8) ^ table(checksum ^ value); } - auto output() const -> vector { - vector result; + auto output() const -> vector override { + vector result; for(auto n : reverse(range(8))) result.append(~checksum >> n * 8); return result; } - auto value() const -> uint64_t { + auto value() const -> u64 { return ~checksum; } private: - static auto table(uint8_t index) -> uint64_t { - static uint64_t table[256] = {0}; + static auto table(u8 index) -> u64 { + static u64 table[256] = {}; static bool initialized = false; if(!initialized) { initialized = true; for(auto index : range(256)) { - uint64_t crc = index; + u64 crc = index; for(auto bit : range(8)) { crc = (crc >> 1) ^ (crc & 1 ? 0xc96c'5795'd787'0f42 : 0); } @@ -49,7 +49,7 @@ struct CRC64 : Hash { return table[index]; } - uint64_t checksum = 0; + u64 checksum = 0; }; } diff --git a/nall/hash/hash.hpp b/nall/hash/hash.hpp index 4565fe3d53..5c1b3f0d3e 100644 --- a/nall/hash/hash.hpp +++ b/nall/hash/hash.hpp @@ -8,8 +8,8 @@ //instead, define a macro to reduce boilerplate code in every Hash subclass #define nallHash(Name) \ Name() { reset(); } \ - Name(const void* data, uint64_t size) : Name() { input(data, size); } \ - Name(const vector& data) : Name() { input(data); } \ + Name(const void* data, u64 size) : Name() { input(data, size); } \ + Name(const vector& data) : Name() { input(data); } \ Name(const string& data) : Name() { input(data); } \ using Hash::input; \ @@ -17,19 +17,19 @@ namespace nall::Hash { struct Hash { virtual auto reset() -> void = 0; - virtual auto input(uint8_t data) -> void = 0; - virtual auto output() const -> vector = 0; + virtual auto input(u8 data) -> void = 0; + virtual auto output() const -> vector = 0; - auto input(array_view data) -> void { + auto input(array_view data) -> void { for(auto byte : data) input(byte); } - auto input(const void* data, uint64_t size) -> void { - auto p = (const uint8_t*)data; + auto input(const void* data, u64 size) -> void { + auto p = (const u8*)data; while(size--) input(*p++); } - auto input(const vector& data) -> void { + auto input(const vector& data) -> void { for(auto byte : data) input(byte); } diff --git a/nall/hash/sha224.hpp b/nall/hash/sha224.hpp index 6bcf7858ad..ed56e651d9 100644 --- a/nall/hash/sha224.hpp +++ b/nall/hash/sha224.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct SHA224 : Hash { using Hash::input; - SHA224(array_view buffer = {}) { + SHA224(array_view buffer = {}) { reset(); input(buffer); } @@ -19,30 +19,30 @@ struct SHA224 : Hash { queued = length = 0; } - auto input(uint8_t value) -> void override { + auto input(u8 value) -> void override { byte(value); length++; } - auto output() const -> vector override { + auto output() const -> vector override { SHA224 self(*this); self.finish(); - vector result; + vector result; for(auto h : range(7)) { for(auto n : reverse(range(4))) result.append(self.h[h] >> n * 8); } return result; } - auto value() const -> uint256_t { - uint256_t value = 0; + auto value() const -> u256 { + u256 value = 0; for(auto byte : output()) value = value << 8 | byte; return value; } private: - auto byte(uint8_t value) -> void { - uint32_t shift = (3 - (queued & 3)) * 8; + auto byte(u8 value) -> void { + u32 shift = (3 - (queued & 3)) * 8; queue[queued >> 2] &= ~(0xff << shift); queue[queued >> 2] |= (value << shift); if(++queued == 64) block(), queued = 0; @@ -51,18 +51,18 @@ struct SHA224 : Hash { auto block() -> void { for(auto n : range(16)) w[n] = queue[n]; for(auto n : range(16, 64)) { - uint32_t a = ror(w[n - 15], 7) ^ ror(w[n - 15], 18) ^ (w[n - 15] >> 3); - uint32_t b = ror(w[n - 2], 17) ^ ror(w[n - 2], 19) ^ (w[n - 2] >> 10); + u32 a = ror(w[n - 15], 7) ^ ror(w[n - 15], 18) ^ (w[n - 15] >> 3); + u32 b = ror(w[n - 2], 17) ^ ror(w[n - 2], 19) ^ (w[n - 2] >> 10); w[n] = w[n - 16] + w[n - 7] + a + b; } - uint32_t t[8]; + u32 t[8]; for(auto n : range(8)) t[n] = h[n]; for(auto n : range(64)) { - uint32_t a = ror(t[0], 2) ^ ror(t[0], 13) ^ ror(t[0], 22); - uint32_t b = ror(t[4], 6) ^ ror(t[4], 11) ^ ror(t[4], 25); - uint32_t c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); - uint32_t d = (t[4] & t[5]) ^ (~t[4] & t[6]); - uint32_t e = t[7] + w[n] + cube(n) + b + d; + u32 a = ror(t[0], 2) ^ ror(t[0], 13) ^ ror(t[0], 22); + u32 b = ror(t[4], 6) ^ ror(t[4], 11) ^ ror(t[4], 25); + u32 c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); + u32 d = (t[4] & t[5]) ^ (~t[4] & t[6]); + u32 e = t[7] + w[n] + cube(n) + b + d; t[7] = t[6]; t[6] = t[5]; t[5] = t[4]; t[4] = t[3] + e; t[3] = t[2]; t[2] = t[1]; t[1] = t[0]; t[0] = a + c + e; } @@ -75,15 +75,15 @@ struct SHA224 : Hash { for(auto n : range(8)) byte(length * 8 >> (7 - n) * 8); } - auto square(uint n) -> uint32_t { - static const uint32_t value[8] = { + auto square(u32 n) -> u32 { + static const u32 value[8] = { 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, }; return value[n]; } - auto cube(uint n) -> uint32_t { - static const uint32_t value[64] = { + auto cube(u32 n) -> u32 { + static const u32 value[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, @@ -96,11 +96,11 @@ struct SHA224 : Hash { return value[n]; } - uint32_t queue[16] = {0}; - uint32_t w[64] = {0}; - uint32_t h[8] = {0}; - uint32_t queued = 0; - uint64_t length = 0; + u32 queue[16] = {}; + u32 w[64] = {}; + u32 h[8] = {}; + u32 queued = 0; + u64 length = 0; }; } diff --git a/nall/hash/sha256.hpp b/nall/hash/sha256.hpp index 27f42a0479..4899ea54e7 100644 --- a/nall/hash/sha256.hpp +++ b/nall/hash/sha256.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct SHA256 : Hash { using Hash::input; - SHA256(array_view buffer = {}) { + SHA256(array_view buffer = {}) { reset(); input(buffer); } @@ -19,30 +19,30 @@ struct SHA256 : Hash { queued = length = 0; } - auto input(uint8_t value) -> void override { + auto input(u8 value) -> void override { byte(value); length++; } - auto output() const -> vector override { + auto output() const -> vector override { SHA256 self(*this); self.finish(); - vector result; + vector result; for(auto h : self.h) { for(auto n : reverse(range(4))) result.append(h >> n * 8); } return result; } - auto value() const -> uint256_t { - uint256_t value = 0; + auto value() const -> u256 { + u256 value = 0; for(auto byte : output()) value = value << 8 | byte; return value; } private: - auto byte(uint8_t value) -> void { - uint32_t shift = (3 - (queued & 3)) * 8; + auto byte(u8 value) -> void { + u32 shift = (3 - (queued & 3)) * 8; queue[queued >> 2] &= ~(0xff << shift); queue[queued >> 2] |= (value << shift); if(++queued == 64) block(), queued = 0; @@ -51,18 +51,18 @@ struct SHA256 : Hash { auto block() -> void { for(auto n : range(16)) w[n] = queue[n]; for(auto n : range(16, 64)) { - uint32_t a = ror(w[n - 15], 7) ^ ror(w[n - 15], 18) ^ (w[n - 15] >> 3); - uint32_t b = ror(w[n - 2], 17) ^ ror(w[n - 2], 19) ^ (w[n - 2] >> 10); + u32 a = ror(w[n - 15], 7) ^ ror(w[n - 15], 18) ^ (w[n - 15] >> 3); + u32 b = ror(w[n - 2], 17) ^ ror(w[n - 2], 19) ^ (w[n - 2] >> 10); w[n] = w[n - 16] + w[n - 7] + a + b; } - uint32_t t[8]; + u32 t[8]; for(auto n : range(8)) t[n] = h[n]; for(auto n : range(64)) { - uint32_t a = ror(t[0], 2) ^ ror(t[0], 13) ^ ror(t[0], 22); - uint32_t b = ror(t[4], 6) ^ ror(t[4], 11) ^ ror(t[4], 25); - uint32_t c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); - uint32_t d = (t[4] & t[5]) ^ (~t[4] & t[6]); - uint32_t e = t[7] + w[n] + cube(n) + b + d; + u32 a = ror(t[0], 2) ^ ror(t[0], 13) ^ ror(t[0], 22); + u32 b = ror(t[4], 6) ^ ror(t[4], 11) ^ ror(t[4], 25); + u32 c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); + u32 d = (t[4] & t[5]) ^ (~t[4] & t[6]); + u32 e = t[7] + w[n] + cube(n) + b + d; t[7] = t[6]; t[6] = t[5]; t[5] = t[4]; t[4] = t[3] + e; t[3] = t[2]; t[2] = t[1]; t[1] = t[0]; t[0] = a + c + e; } @@ -75,15 +75,15 @@ struct SHA256 : Hash { for(auto n : range(8)) byte(length * 8 >> (7 - n) * 8); } - auto square(uint n) -> uint32_t { - static const uint32_t value[8] = { + auto square(u32 n) -> u32 { + static const u32 value[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, }; return value[n]; } - auto cube(uint n) -> uint32_t { - static const uint32_t value[64] = { + auto cube(u32 n) -> u32 { + static const u32 value[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, @@ -96,11 +96,11 @@ struct SHA256 : Hash { return value[n]; } - uint32_t queue[16] = {0}; - uint32_t w[64] = {0}; - uint32_t h[8] = {0}; - uint32_t queued = 0; - uint64_t length = 0; + u32 queue[16] = {}; + u32 w[64] = {}; + u32 h[8] = {}; + u32 queued = 0; + u64 length = 0; }; } diff --git a/nall/hash/sha384.hpp b/nall/hash/sha384.hpp index 09dbbdb181..5d32485d7c 100644 --- a/nall/hash/sha384.hpp +++ b/nall/hash/sha384.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct SHA384 : Hash { using Hash::input; - SHA384(array_view buffer = {}) { + SHA384(array_view buffer = {}) { reset(); input(buffer); } @@ -19,50 +19,50 @@ struct SHA384 : Hash { queued = length = 0; } - auto input(uint8_t data) -> void override { + auto input(u8 data) -> void override { byte(data); length++; } - auto output() const -> vector override { + auto output() const -> vector override { SHA384 self(*this); self.finish(); - vector result; + vector result; for(auto h : range(6)) { for(auto n : reverse(range(8))) result.append(self.h[h] >> n * 8); } return result; } - auto value() const -> uint512_t { - uint512_t value = 0; + auto value() const -> u512 { + u512 value = 0; for(auto byte : output()) value = value << 8 | byte; return value; } private: - auto byte(uint8_t data) -> void { - uint64_t shift = (7 - (queued & 7)) * 8; - queue[queued >> 3] &=~((uint64_t)0xff << shift); - queue[queued >> 3] |= ((uint64_t)data << shift); + auto byte(u8 data) -> void { + u64 shift = (7 - (queued & 7)) * 8; + queue[queued >> 3] &=~((u64)0xff << shift); + queue[queued >> 3] |= ((u64)data << shift); if(++queued == 128) block(), queued = 0; } auto block() -> void { for(auto n : range(16)) w[n] = queue[n]; for(auto n : range(16, 80)) { - uint64_t a = ror(w[n - 15], 1) ^ ror(w[n - 15], 8) ^ (w[n - 15] >> 7); - uint64_t b = ror(w[n - 2], 19) ^ ror(w[n - 2], 61) ^ (w[n - 2] >> 6); + u64 a = ror(w[n - 15], 1) ^ ror(w[n - 15], 8) ^ (w[n - 15] >> 7); + u64 b = ror(w[n - 2], 19) ^ ror(w[n - 2], 61) ^ (w[n - 2] >> 6); w[n] = w[n - 16] + w[n - 7] + a + b; } - uint64_t t[8]; + u64 t[8]; for(auto n : range(8)) t[n] = h[n]; for(auto n : range(80)) { - uint64_t a = ror(t[0], 28) ^ ror(t[0], 34) ^ ror(t[0], 39); - uint64_t b = ror(t[4], 14) ^ ror(t[4], 18) ^ ror(t[4], 41); - uint64_t c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); - uint64_t d = (t[4] & t[5]) ^ (~t[4] & t[6]); - uint64_t e = t[7] + w[n] + cube(n) + b + d; + u64 a = ror(t[0], 28) ^ ror(t[0], 34) ^ ror(t[0], 39); + u64 b = ror(t[4], 14) ^ ror(t[4], 18) ^ ror(t[4], 41); + u64 c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); + u64 d = (t[4] & t[5]) ^ (~t[4] & t[6]); + u64 e = t[7] + w[n] + cube(n) + b + d; t[7] = t[6]; t[6] = t[5]; t[5] = t[4]; t[4] = t[3] + e; t[3] = t[2]; t[2] = t[1]; t[1] = t[0]; t[0] = a + c + e; } @@ -75,16 +75,16 @@ struct SHA384 : Hash { for(auto n : range(16)) byte(length * 8 >> (15 - n) * 8); } - auto square(uint n) -> uint64_t { - static const uint64_t data[8] = { + auto square(u32 n) -> u64 { + static const u64 data[8] = { 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939, 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4, }; return data[n]; } - auto cube(uint n) -> uint64_t { - static const uint64_t data[80] = { + auto cube(u32 n) -> u64 { + static const u64 data[80] = { 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, @@ -109,11 +109,11 @@ struct SHA384 : Hash { return data[n]; } - uint64_t queue[16] = {0}; - uint64_t w[80] = {0}; - uint64_t h[8] = {0}; - uint64_t queued = 0; - uint128_t length = 0; + u64 queue[16] = {}; + u64 w[80] = {}; + u64 h[8] = {}; + u64 queued = 0; + u128 length = 0; }; } diff --git a/nall/hash/sha512.hpp b/nall/hash/sha512.hpp index f76d2d52bd..eeda189e37 100644 --- a/nall/hash/sha512.hpp +++ b/nall/hash/sha512.hpp @@ -7,7 +7,7 @@ namespace nall::Hash { struct SHA512 : Hash { using Hash::input; - SHA512(array_view buffer = {}) { + SHA512(array_view buffer = {}) { reset(); input(buffer); } @@ -19,50 +19,50 @@ struct SHA512 : Hash { queued = length = 0; } - auto input(uint8_t data) -> void override { + auto input(u8 data) -> void override { byte(data); length++; } - auto output() const -> vector override { + auto output() const -> vector override { SHA512 self(*this); self.finish(); - vector result; + vector result; for(auto h : self.h) { for(auto n : reverse(range(8))) result.append(h >> n * 8); } return result; } - auto value() const -> uint512_t { - uint512_t value = 0; + auto value() const -> u512 { + u512 value = 0; for(auto byte : output()) value = value << 8 | byte; return value; } private: - auto byte(uint8_t data) -> void { - uint64_t shift = (7 - (queued & 7)) * 8; - queue[queued >> 3] &=~((uint64_t)0xff << shift); - queue[queued >> 3] |= ((uint64_t)data << shift); + auto byte(u8 data) -> void { + u64 shift = (7 - (queued & 7)) * 8; + queue[queued >> 3] &=~((u64)0xff << shift); + queue[queued >> 3] |= ((u64)data << shift); if(++queued == 128) block(), queued = 0; } auto block() -> void { for(auto n : range(16)) w[n] = queue[n]; for(auto n : range(16, 80)) { - uint64_t a = ror(w[n - 15], 1) ^ ror(w[n - 15], 8) ^ (w[n - 15] >> 7); - uint64_t b = ror(w[n - 2], 19) ^ ror(w[n - 2], 61) ^ (w[n - 2] >> 6); + u64 a = ror(w[n - 15], 1) ^ ror(w[n - 15], 8) ^ (w[n - 15] >> 7); + u64 b = ror(w[n - 2], 19) ^ ror(w[n - 2], 61) ^ (w[n - 2] >> 6); w[n] = w[n - 16] + w[n - 7] + a + b; } - uint64_t t[8]; + u64 t[8]; for(auto n : range(8)) t[n] = h[n]; for(auto n : range(80)) { - uint64_t a = ror(t[0], 28) ^ ror(t[0], 34) ^ ror(t[0], 39); - uint64_t b = ror(t[4], 14) ^ ror(t[4], 18) ^ ror(t[4], 41); - uint64_t c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); - uint64_t d = (t[4] & t[5]) ^ (~t[4] & t[6]); - uint64_t e = t[7] + w[n] + cube(n) + b + d; + u64 a = ror(t[0], 28) ^ ror(t[0], 34) ^ ror(t[0], 39); + u64 b = ror(t[4], 14) ^ ror(t[4], 18) ^ ror(t[4], 41); + u64 c = (t[0] & t[1]) ^ (t[0] & t[2]) ^ (t[1] & t[2]); + u64 d = (t[4] & t[5]) ^ (~t[4] & t[6]); + u64 e = t[7] + w[n] + cube(n) + b + d; t[7] = t[6]; t[6] = t[5]; t[5] = t[4]; t[4] = t[3] + e; t[3] = t[2]; t[2] = t[1]; t[1] = t[0]; t[0] = a + c + e; } @@ -75,16 +75,16 @@ struct SHA512 : Hash { for(auto n : range(16)) byte(length * 8 >> (15 - n) * 8); } - auto square(uint n) -> uint64_t { - static const uint64_t data[8] = { + auto square(u32 n) -> u64 { + static const u64 data[8] = { 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179, }; return data[n]; } - auto cube(uint n) -> uint64_t { - static const uint64_t data[80] = { + auto cube(u32 n) -> u64 { + static const u64 data[80] = { 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, @@ -109,11 +109,11 @@ struct SHA512 : Hash { return data[n]; } - uint64_t queue[16] = {0}; - uint64_t w[80] = {0}; - uint64_t h[8] = {0}; - uint64_t queued = 0; - uint128_t length = 0; + u64 queue[16] = {}; + u64 w[80] = {}; + u64 h[8] = {}; + u64 queued = 0; + u128 length = 0; }; } diff --git a/nall/hashset.hpp b/nall/hashset.hpp index 6812eafc2d..8da76fec8b 100644 --- a/nall/hashset.hpp +++ b/nall/hashset.hpp @@ -7,7 +7,7 @@ //remove: O(1) average; O(n) worst // //requirements: -// auto T::hash() const -> uint; +// auto T::hash() const -> u32; // auto T::operator==(const T&) const -> bool; namespace nall { @@ -15,7 +15,7 @@ namespace nall { template struct hashset { hashset() = default; - hashset(uint length) : length(bit::round(length)) {} + hashset(u32 length) : length(bit::round(length)) {} hashset(const hashset& source) { operator=(source); } hashset(hashset&& source) { operator=(move(source)); } ~hashset() { reset(); } @@ -23,7 +23,7 @@ struct hashset { auto operator=(const hashset& source) -> hashset& { reset(); if(source.pool) { - for(uint n : range(source.count)) { + for(u32 n : range(source.count)) { insert(*source.pool[n]); } } @@ -42,12 +42,12 @@ struct hashset { } explicit operator bool() const { return count; } - auto capacity() const -> uint { return length; } - auto size() const -> uint { return count; } + auto capacity() const -> u32 { return length; } + auto size() const -> u32 { return count; } auto reset() -> void { if(pool) { - for(uint n : range(length)) { + for(u32 n : range(length)) { if(pool[n]) { delete pool[n]; pool[n] = nullptr; @@ -60,15 +60,15 @@ struct hashset { count = 0; } - auto reserve(uint size) -> void { + auto reserve(u32 size) -> void { //ensure all items will fit into pool (with <= 50% load) and amortize growth size = bit::round(max(size, count << 1)); T** copy = new T*[size](); if(pool) { - for(uint n : range(length)) { + for(u32 n : range(length)) { if(pool[n]) { - uint hash = (*pool[n]).hash() & (size - 1); + u32 hash = (*pool[n]).hash() & (size - 1); while(copy[hash]) if(++hash >= size) hash = 0; copy[hash] = pool[n]; pool[n] = nullptr; @@ -84,7 +84,7 @@ struct hashset { auto find(const T& value) -> maybe { if(!pool) return nothing; - uint hash = value.hash() & (length - 1); + u32 hash = value.hash() & (length - 1); while(pool[hash]) { if(value == *pool[hash]) return *pool[hash]; if(++hash >= length) hash = 0; @@ -100,7 +100,7 @@ struct hashset { if(count >= (length >> 1)) reserve(length << 1); count++; - uint hash = value.hash() & (length - 1); + u32 hash = value.hash() & (length - 1); while(pool[hash]) if(++hash >= length) hash = 0; pool[hash] = new T(value); @@ -110,7 +110,7 @@ struct hashset { auto remove(const T& value) -> bool { if(!pool) return false; - uint hash = value.hash() & (length - 1); + u32 hash = value.hash() & (length - 1); while(pool[hash]) { if(value == *pool[hash]) { delete pool[hash]; @@ -126,8 +126,8 @@ struct hashset { protected: T** pool = nullptr; - uint length = 8; //length of pool - uint count = 0; //number of objects inside of the pool + u32 length = 8; //length of pool + u32 count = 0; //number of objects inside of the pool }; } diff --git a/nall/hid.hpp b/nall/hid.hpp index 0f22ad2b84..cc8e7f120d 100644 --- a/nall/hid.hpp +++ b/nall/hid.hpp @@ -11,12 +11,12 @@ struct Input { Input(const string& name) : _name(name) {} auto name() const -> string { return _name; } - auto value() const -> int16_t { return _value; } - auto setValue(int16_t value) -> void { _value = value; } + auto value() const -> s16 { return _value; } + auto setValue(s16 value) -> void { _value = value; } private: string _name; - int16_t _value = 0; + s16 _value = 0; friend class Group; }; @@ -24,10 +24,10 @@ struct Group : vector { Group(const string& name) : _name(name) {} auto name() const -> string { return _name; } - auto input(uint id) -> Input& { return operator[](id); } + auto input(u32 id) -> Input& { return operator[](id); } auto append(const string& name) -> void { vector::append(Input{name}); } - auto find(const string& name) const -> maybe { + auto find(const string& name) const -> maybe { for(auto id : range(size())) { if(operator[](id)._name == name) return id; } @@ -44,13 +44,13 @@ struct Device : vector { virtual ~Device() = default; //id => {pathID}-{vendorID}-{productID} - auto pathID() const -> uint32_t { return (uint32_t)(_id >> 32); } //32-63 - auto vendorID() const -> uint16_t { return (uint16_t)(_id >> 16); } //16-31 - auto productID() const -> uint16_t { return (uint16_t)(_id >> 0); } // 0-15 + auto pathID() const -> u32 { return (u32)(_id >> 32); } //32-63 + auto vendorID() const -> u16 { return (u16)(_id >> 16); } //16-31 + auto productID() const -> u16 { return (u16)(_id >> 0); } // 0-15 - auto setPathID (uint32_t pathID ) -> void { _id = (uint64_t)pathID << 32 | vendorID() << 16 | productID() << 0; } - auto setVendorID (uint16_t vendorID ) -> void { _id = (uint64_t)pathID() << 32 | vendorID << 16 | productID() << 0; } - auto setProductID(uint16_t productID) -> void { _id = (uint64_t)pathID() << 32 | vendorID() << 16 | productID << 0; } + auto setPathID (u32 pathID ) -> void { _id = (u64)pathID << 32 | vendorID() << 16 | productID() << 0; } + auto setVendorID (u16 vendorID ) -> void { _id = (u64)pathID() << 32 | vendorID << 16 | productID() << 0; } + auto setProductID(u16 productID) -> void { _id = (u64)pathID() << 32 | vendorID() << 16 | productID << 0; } virtual auto isNull() const -> bool { return false; } virtual auto isKeyboard() const -> bool { return false; } @@ -58,12 +58,12 @@ struct Device : vector { virtual auto isJoypad() const -> bool { return false; } auto name() const -> string { return _name; } - auto id() const -> uint64_t { return _id; } - auto setID(uint64_t id) -> void { _id = id; } - auto group(uint id) -> Group& { return operator[](id); } + auto id() const -> u64 { return _id; } + auto setID(u64 id) -> void { _id = id; } + auto group(u32 id) -> Group& { return operator[](id); } auto append(const string& name) -> void { vector::append(Group{name}); } - auto find(const string& name) const -> maybe { + auto find(const string& name) const -> maybe { for(auto id : range(size())) { if(operator[](id)._name == name) return id; } @@ -72,19 +72,19 @@ struct Device : vector { private: string _name; - uint64_t _id = 0; + u64 _id = 0; }; struct Null : Device { - enum : uint16_t { GenericVendorID = 0x0000, GenericProductID = 0x0000 }; + enum : u16 { GenericVendorID = 0x0000, GenericProductID = 0x0000 }; Null() : Device("Null") {} auto isNull() const -> bool { return true; } }; struct Keyboard : Device { - enum : uint16_t { GenericVendorID = 0x0000, GenericProductID = 0x0001 }; - enum GroupID : uint { Button }; + enum : u16 { GenericVendorID = 0x0000, GenericProductID = 0x0001 }; + enum GroupID : u32 { Button }; Keyboard() : Device("Keyboard") { append("Button"); } auto isKeyboard() const -> bool { return true; } @@ -92,8 +92,8 @@ struct Keyboard : Device { }; struct Mouse : Device { - enum : uint16_t { GenericVendorID = 0x0000, GenericProductID = 0x0002 }; - enum GroupID : uint { Axis, Button }; + enum : u16 { GenericVendorID = 0x0000, GenericProductID = 0x0002 }; + enum GroupID : u32 { Axis, Button }; Mouse() : Device("Mouse") { append("Axis"), append("Button"); } auto isMouse() const -> bool { return true; } @@ -102,8 +102,8 @@ struct Mouse : Device { }; struct Joypad : Device { - enum : uint16_t { GenericVendorID = 0x0000, GenericProductID = 0x0003 }; - enum GroupID : uint { Axis, Hat, Trigger, Button }; + enum : u16 { GenericVendorID = 0x0000, GenericProductID = 0x0003 }; + enum GroupID : u32 { Axis, Hat, Trigger, Button }; Joypad() : Device("Joypad") { append("Axis"), append("Hat"), append("Trigger"), append("Button"); } auto isJoypad() const -> bool { return true; } diff --git a/nall/http/client.hpp b/nall/http/client.hpp index cc0eca9464..1fbf54a04b 100644 --- a/nall/http/client.hpp +++ b/nall/http/client.hpp @@ -5,19 +5,19 @@ namespace nall::HTTP { struct Client : Role { - auto open(const string& hostname, uint port = 80) -> bool; + auto open(const string& hostname, u16 port = 80) -> bool; auto upload(const Request& request) -> bool; auto download(const Request& request) -> Response; auto close() -> void; ~Client() { close(); } private: - int fd = -1; + s32 fd = -1; addrinfo* info = nullptr; }; -inline auto Client::open(const string& hostname, uint port) -> bool { - addrinfo hint = {0}; +inline auto Client::open(const string& hostname, u16 port) -> bool { + addrinfo hint = {}; hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_STREAM; hint.ai_flags = AI_ADDRCONFIG; diff --git a/nall/http/message.hpp b/nall/http/message.hpp index e4c543d10a..373ccae7d4 100644 --- a/nall/http/message.hpp +++ b/nall/http/message.hpp @@ -88,10 +88,10 @@ struct Variables { struct Message { using type = Message; - virtual auto head(const function& callback) const -> bool = 0; + virtual auto head(const function& callback) const -> bool = 0; virtual auto setHead() -> bool = 0; - virtual auto body(const function& callback) const -> bool = 0; + virtual auto body(const function& callback) const -> bool = 0; virtual auto setBody() -> bool = 0; Variables header; diff --git a/nall/http/request.hpp b/nall/http/request.hpp index ff1c615eb3..c30c282f9d 100644 --- a/nall/http/request.hpp +++ b/nall/http/request.hpp @@ -9,14 +9,14 @@ namespace nall::HTTP { struct Request : Message { using type = Request; - enum class RequestType : uint { None, Head, Get, Post }; + enum class RequestType : u32 { None, Head, Get, Post }; explicit operator bool() const { return requestType() != RequestType::None; } - auto head(const function& callback) const -> bool override; + auto head(const function& callback) const -> bool override; auto setHead() -> bool override; - auto body(const function& callback) const -> bool override; + auto body(const function& callback) const -> bool override; auto setBody() -> bool override; auto ipv4() const -> bool { return _ipv6 == false; } @@ -40,7 +40,7 @@ struct Request : Message { string _path; }; -inline auto Request::head(const function& callback) const -> bool { +inline auto Request::head(const function& callback) const -> bool { if(!callback) return false; string output; @@ -65,7 +65,7 @@ inline auto Request::head(const function& callback) } output.append("\r\n"); - return callback(output.data(), output.size()); + return callback(output.data(), output.size()); } inline auto Request::setHead() -> bool { @@ -122,11 +122,11 @@ inline auto Request::setHead() -> bool { return true; } -inline auto Request::body(const function& callback) const -> bool { +inline auto Request::body(const function& callback) const -> bool { if(!callback) return false; if(_body) { - return callback(_body.data(), _body.size()); + return callback(_body.data(), _body.size()); } return true; diff --git a/nall/http/response.hpp b/nall/http/response.hpp index 6aa3e34708..93a3b7a7b5 100644 --- a/nall/http/response.hpp +++ b/nall/http/response.hpp @@ -11,23 +11,23 @@ struct Response : Message { Response(const Request& request) { setRequest(request); } explicit operator bool() const { return responseType() != 0; } - auto operator()(uint responseType) -> type& { return setResponseType(responseType); } + auto operator()(u32 responseType) -> type& { return setResponseType(responseType); } - auto head(const function& callback) const -> bool override; + auto head(const function& callback) const -> bool override; auto setHead() -> bool override; - auto body(const function& callback) const -> bool override; + auto body(const function& callback) const -> bool override; auto setBody() -> bool override; auto request() const -> const Request* { return _request; } auto setRequest(const Request& value) -> type& { _request = &value; return *this; } - auto responseType() const -> uint { return _responseType; } - auto setResponseType(uint value) -> type& { _responseType = value; return *this; } + auto responseType() const -> u32 { return _responseType; } + auto setResponseType(u32 value) -> type& { _responseType = value; return *this; } auto hasData() const -> bool { return (bool)_data; } - auto data() const -> const vector& { return _data; } - auto setData(const vector& value) -> type&; + auto data() const -> const vector& { return _data; } + auto setData(const vector& value) -> type&; auto hasFile() const -> bool { return (bool)_file; } auto file() const -> const string& { return _file; } @@ -38,7 +38,7 @@ struct Response : Message { auto setText(const string& value) -> type&; auto hasBody() const -> bool; - auto findContentLength() const -> uint; + auto findContentLength() const -> u32; auto findContentType() const -> string; auto findContentType(const string& suffix) const -> string; auto findResponseType() const -> string; @@ -46,13 +46,13 @@ struct Response : Message { auto setFileETag() -> void; const Request* _request = nullptr; - uint _responseType = 0; - vector _data; + u32 _responseType = 0; + vector _data; string _file; string _text; }; -inline auto Response::head(const function& callback) const -> bool { +inline auto Response::head(const function& callback) const -> bool { if(!callback) return false; string output; @@ -62,7 +62,7 @@ inline auto Response::head(const function& callback output.append("HTTP/1.1 304 Not Modified\r\n"); output.append("Connection: close\r\n"); output.append("\r\n"); - return callback(output.data(), output.size()); + return callback(output.data(), output.size()); } } } @@ -84,7 +84,7 @@ inline auto Response::head(const function& callback } output.append("\r\n"); - return callback(output.data(), output.size()); + return callback(output.data(), output.size()); } inline auto Response::setHead() -> bool { @@ -107,33 +107,33 @@ inline auto Response::setHead() -> bool { return true; } -inline auto Response::body(const function& callback) const -> bool { +inline auto Response::body(const function& callback) const -> bool { if(!callback) return false; if(!hasBody()) return true; bool chunked = header["Transfer-Encoding"].value() == "chunked"; if(chunked) { string prefix = {hex(findContentLength()), "\r\n"}; - if(!callback(prefix.data(), prefix.size())) return false; + if(!callback(prefix.data(), prefix.size())) return false; } if(_body) { - if(!callback(_body.data(), _body.size())) return false; + if(!callback(_body.data(), _body.size())) return false; } else if(hasData()) { if(!callback(data().data(), data().size())) return false; } else if(hasFile()) { file_map map(file(), file_map::mode::read); if(!callback(map.data(), map.size())) return false; } else if(hasText()) { - if(!callback(text().data(), text().size())) return false; + if(!callback(text().data(), text().size())) return false; } else { string response = findResponseType(); - if(!callback(response.data(), response.size())) return false; + if(!callback(response.data(), response.size())) return false; } if(chunked) { string suffix = {"\r\n0\r\n\r\n"}; - if(!callback(suffix.data(), suffix.size())) return false; + if(!callback(suffix.data(), suffix.size())) return false; } return true; @@ -155,7 +155,7 @@ inline auto Response::hasBody() const -> bool { return true; } -inline auto Response::findContentLength() const -> uint { +inline auto Response::findContentLength() const -> u32 { if(auto contentLength = header["Content-Length"]) return contentLength.value().natural(); if(_body) return _body.size(); if(hasData()) return data().size(); @@ -240,7 +240,7 @@ inline auto Response::findResponseTypeVerbose() const -> string { return findResponseType(); //fallback for uncommon responses } -inline auto Response::setData(const vector& value) -> type& { +inline auto Response::setData(const vector& value) -> type& { _data = value; header.assign("Content-Length", value.size()); return *this; @@ -249,7 +249,7 @@ inline auto Response::setData(const vector& value) -> type& { inline auto Response::setFile(const string& value) -> type& { //block path escalation exploits ("../" and "..\" in the file location) bool valid = true; - for(uint n : range(value.size())) { + for(u32 n : range(value.size())) { if(value(n + 0, '\0') != '.') continue; if(value(n + 1, '\0') != '.') continue; if(value(n + 2, '\0') != '/' && value(n + 2, '\0') != '\\') continue; @@ -260,7 +260,7 @@ inline auto Response::setFile(const string& value) -> type& { //cache images for seven days auto suffix = Location::suffix(value); - uint maxAge = 0; + u32 maxAge = 0; if(suffix == ".svg" || suffix == ".ico" || suffix == ".png" diff --git a/nall/http/role.hpp b/nall/http/role.hpp index ecdf0dbf8d..4978f9c96a 100644 --- a/nall/http/role.hpp +++ b/nall/http/role.hpp @@ -10,18 +10,18 @@ namespace nall::HTTP { struct Role { struct Settings { - int connectionLimit = 1 * 1024; //server - int headSizeLimit = 16 * 1024; //client, server - int bodySizeLimit = 65536 * 1024; //client, server - int chunkSize = 32 * 1024; //client, server - int threadStackSize = 128 * 1024; //server - int timeoutReceive = 15 * 1000; //server - int timeoutSend = 15 * 1000; //server + s32 connectionLimit = 1 * 1024; //server + s32 headSizeLimit = 16 * 1024; //client, server + s32 bodySizeLimit = 65536 * 1024; //client, server + s32 chunkSize = 32 * 1024; //client, server + s32 threadStackSize = 128 * 1024; //server + s32 timeoutReceive = 15 * 1000; //server + s32 timeoutSend = 15 * 1000; //server } settings; auto configure(const string& parameters) -> bool; - auto download(int fd, Message& message) -> bool; - auto upload(int fd, const Message& message) -> bool; + auto download(s32 fd, Message& message) -> bool; + auto upload(s32 fd, const Message& message) -> bool; }; inline auto Role::configure(const string& parameters) -> bool { @@ -42,11 +42,11 @@ inline auto Role::configure(const string& parameters) -> bool { return true; } -inline auto Role::download(int fd, Message& message) -> bool { +inline auto Role::download(s32 fd, Message& message) -> bool { auto& head = message._head; auto& body = message._body; string chunk; - uint8_t packet[settings.chunkSize], *p = nullptr; + u8 packet[settings.chunkSize], *p = nullptr; head.reset(), head.reserve(4095); body.reset(), body.reserve(4095); @@ -55,9 +55,9 @@ inline auto Role::download(int fd, Message& message) -> bool { bool chunked = false; bool chunkReceived = false; bool chunkFooterReceived = true; - int length = 0; - int chunkLength = 0; - int contentLength = 0; + s32 length = 0; + s32 chunkLength = 0; + s32 contentLength = 0; while(true) { if(auto limit = settings.headSizeLimit) if(head.size() >= limit) return false; @@ -116,7 +116,7 @@ inline auto Role::download(int fd, Message& message) -> bool { p += length; length = 0; } else { - int transferLength = min(length, chunkLength); + s32 transferLength = min(length, chunkLength); body.resize(body.size() + transferLength); memory::copy(body.get() + body.size() - transferLength, p, transferLength); @@ -135,10 +135,10 @@ inline auto Role::download(int fd, Message& message) -> bool { return true; } -inline auto Role::upload(int fd, const Message& message) -> bool { - auto transfer = [&](const uint8_t* data, uint size) -> bool { +inline auto Role::upload(s32 fd, const Message& message) -> bool { + auto transfer = [&](const u8* data, u32 size) -> bool { while(size) { - int length = send(fd, data, min(size, settings.chunkSize), MSG_NOSIGNAL); + s32 length = send(fd, data, min(size, settings.chunkSize), MSG_NOSIGNAL); if(length < 0) return false; data += length; size -= length; @@ -146,8 +146,8 @@ inline auto Role::upload(int fd, const Message& message) -> bool { return true; }; - if(message.head([&](const uint8_t* data, uint size) -> bool { return transfer(data, size); })) { - if(message.body([&](const uint8_t* data, uint size) -> bool { return transfer(data, size); })) { + if(message.head([&](const u8* data, u32 size) -> bool { return transfer(data, size); })) { + if(message.body([&](const u8* data, u32 size) -> bool { return transfer(data, size); })) { return true; } } diff --git a/nall/http/server.hpp b/nall/http/server.hpp index 13c8ec0f2d..5560fec27e 100644 --- a/nall/http/server.hpp +++ b/nall/http/server.hpp @@ -6,7 +6,7 @@ namespace nall::HTTP { struct Server : Role, service { - auto open(uint port = 8080, const string& serviceName = "", const string& command = "") -> bool; + auto open(u16 port = 8080, const string& serviceName = "", const string& command = "") -> bool; auto main(const function& function = {}) -> void; auto scan() -> string; auto close() -> void; @@ -14,10 +14,10 @@ struct Server : Role, service { private: function callback; - std::atomic connections{0}; + std::atomic connections{0}; - int fd4 = -1; - int fd6 = -1; + s32 fd4 = -1; + s32 fd6 = -1; struct sockaddr_in addrin4 = {0}; struct sockaddr_in6 addrin6 = {0}; @@ -31,7 +31,7 @@ struct Server : Role, service { auto ipv6_scan() -> bool; }; -inline auto Server::open(uint port, const string& serviceName, const string& command) -> bool { +inline auto Server::open(u16 port, const string& serviceName, const string& command) -> bool { if(serviceName) { if(!service::command(serviceName, command)) return false; } @@ -62,21 +62,21 @@ inline auto Server::open(uint port, const string& serviceName, const string& com #endif #if defined(SO_NOSIGPIPE) //BSD, OSX - int nosigpipe = 1; - if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(int)); - if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(int)); + s32 nosigpipe = 1; + if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(s32)); + if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(s32)); #endif #if defined(SO_REUSEADDR) //BSD, Linux, OSX - int reuseaddr = 1; - if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)); - if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)); + s32 reuseaddr = 1; + if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(s32)); + if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(s32)); #endif #if defined(SO_REUSEPORT) //BSD, OSX - int reuseport = 1; - if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(int)); - if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(int)); + s32 reuseport = 1; + if(ipv4()) setsockopt(fd4, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(s32)); + if(ipv6()) setsockopt(fd6, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(s32)); #endif } @@ -117,22 +117,22 @@ inline auto Server::ipv4_scan() -> bool { thread::create([&](uintptr) { thread::detach(); - int clientfd = -1; + s32 clientfd = -1; struct sockaddr_in settings = {0}; socklen_t socklen = sizeof(sockaddr_in); clientfd = accept(fd4, (struct sockaddr*)&settings, &socklen); if(clientfd < 0) return; - uint32_t ip = ntohl(settings.sin_addr.s_addr); + u32 ip = ntohl(settings.sin_addr.s_addr); Request request; request._ipv6 = false; request._ip = { - (uint8_t)(ip >> 24), ".", - (uint8_t)(ip >> 16), ".", - (uint8_t)(ip >> 8), ".", - (uint8_t)(ip >> 0) + (u8)(ip >> 24), ".", + (u8)(ip >> 16), ".", + (u8)(ip >> 8), ".", + (u8)(ip >> 0) }; if(download(clientfd, request) && callback) { @@ -164,25 +164,25 @@ inline auto Server::ipv6_scan() -> bool { thread::create([&](uintptr) { thread::detach(); - int clientfd = -1; + s32 clientfd = -1; struct sockaddr_in6 settings = {0}; socklen_t socklen = sizeof(sockaddr_in6); clientfd = accept(fd6, (struct sockaddr*)&settings, &socklen); if(clientfd < 0) return; - uint8_t* ip = settings.sin6_addr.s6_addr; - uint16_t ipSegment[8]; + u8* ip = settings.sin6_addr.s6_addr; + u16 ipSegment[8]; for(auto n : range(8)) ipSegment[n] = ip[n * 2 + 0] * 256 + ip[n * 2 + 1]; Request request; request._ipv6 = true; //RFC5952 IPv6 encoding: the first longest 2+ consecutive zero-sequence is compressed to "::" - int zeroOffset = -1; - int zeroLength = 0; - int zeroCounter = 0; + s32 zeroOffset = -1; + s32 zeroLength = 0; + s32 zeroCounter = 0; for(auto n : range(8)) { - uint16_t value = ipSegment[n]; + u16 value = ipSegment[n]; if(value == 0) zeroCounter++; if(zeroCounter > zeroLength) { zeroLength = zeroCounter; @@ -191,12 +191,12 @@ inline auto Server::ipv6_scan() -> bool { if(value != 0) zeroCounter = 0; } if(zeroLength == 1) zeroOffset = -1; - for(uint n = 0; n < 8;) { + for(u32 n = 0; n < 8;) { if(n == zeroOffset) { request._ip.append(n == 0 ? "::" : ":"); n += zeroLength; } else { - uint16_t value = ipSegment[n]; + u16 value = ipSegment[n]; request._ip.append(hex(value), n++ != 7 ? ":" : ""); } } diff --git a/nall/image.hpp b/nall/image.hpp index b94a9d2c09..01651b779c 100644 --- a/nall/image.hpp +++ b/nall/image.hpp @@ -11,7 +11,7 @@ namespace nall { struct image { - enum class blend : uint { + enum class blend : u32 { add, sourceAlpha, //color = sourceColor * sourceAlpha + targetColor * (1 - sourceAlpha) sourceColor, //color = sourceColor @@ -20,7 +20,7 @@ struct image { }; struct channel { - channel(uint64_t mask, uint depth, uint shift) : _mask(mask), _depth(depth), _shift(shift) { + channel(u64 mask, u32 depth, u32 shift) : _mask(mask), _depth(depth), _shift(shift) { } auto operator==(const channel& source) const -> bool { @@ -36,19 +36,19 @@ struct image { auto shift() const { return _shift; } private: - uint64_t _mask; - uint _depth; - uint _shift; + u64 _mask; + u32 _depth; + u32 _shift; }; //core.hpp image(const image& source); image(image&& source); - image(bool endian, uint depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask); + image(bool endian, u32 depth, u64 alphaMask, u64 redMask, u64 greenMask, u64 blueMask); image(const string& filename); - image(const void* data, uint size); - image(const vector& buffer); - template image(const uint8_t (&Name)[Size]); + image(const void* data, u32 size); + image(const vector& buffer); + template image(const u8 (&Name)[Size]); image(); ~image(); @@ -59,44 +59,44 @@ struct image { auto operator==(const image& source) const -> bool; auto operator!=(const image& source) const -> bool; - auto read(const uint8_t* data) const -> uint64_t; - auto write(uint8_t* data, uint64_t value) const -> void; + auto read(const u8* data) const -> u64; + auto write(u8* data, u64 value) const -> void; auto free() -> void; auto load(const string& filename) -> bool; - auto copy(const void* data, uint pitch, uint width, uint height) -> void; - auto allocate(uint width, uint height) -> void; + auto copy(const void* data, u32 pitch, u32 width, u32 height) -> void; + auto allocate(u32 width, u32 height) -> void; //fill.hpp - auto fill(uint64_t color = 0) -> void; - auto gradient(uint64_t a, uint64_t b, uint64_t c, uint64_t d) -> void; - auto gradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY, function callback) -> void; - auto crossGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto diamondGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto horizontalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto radialGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto sphericalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto squareGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; - auto verticalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void; + auto fill(u64 color = 0) -> void; + auto gradient(u64 a, u64 b, u64 c, u64 d) -> void; + auto gradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY, function callback) -> void; + auto crossGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto diamondGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto horizontalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto radialGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto sphericalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto squareGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; + auto verticalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void; //scale.hpp - auto scale(uint width, uint height, bool linear = true) -> void; + auto scale(u32 width, u32 height, bool linear = true) -> void; //blend.hpp - auto impose(blend mode, uint targetX, uint targetY, image source, uint x, uint y, uint width, uint height) -> void; + auto impose(blend mode, u32 targetX, u32 targetY, image source, u32 x, u32 y, u32 width, u32 height) -> void; //utility.hpp - auto shrink(uint64_t transparentColor = 0) -> void; - auto crop(uint x, uint y, uint width, uint height) -> bool; - auto alphaBlend(uint64_t alphaColor) -> void; + auto shrink(u64 transparentColor = 0) -> void; + auto crop(u32 x, u32 y, u32 width, u32 height) -> bool; + auto alphaBlend(u64 alphaColor) -> void; auto alphaMultiply() -> void; auto transform(const image& source = {}) -> void; - auto transform(bool endian, uint depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask) -> void; + auto transform(bool endian, u32 depth, u64 alphaMask, u64 redMask, u64 greenMask, u64 blueMask) -> void; //static.hpp - static auto bitDepth(uint64_t color) -> uint; - static auto bitShift(uint64_t color) -> uint; - static auto normalize(uint64_t color, uint sourceDepth, uint targetDepth) -> uint64_t; + static auto bitDepth(u64 color) -> u32; + static auto bitShift(u64 color) -> u32; + static auto normalize(u64 color, u32 sourceDepth, u32 targetDepth) -> u64; //access auto data() { return _data; } @@ -118,38 +118,38 @@ struct image { private: //core.hpp - auto allocate(uint width, uint height, uint stride) -> uint8_t*; + auto allocate(u32 width, u32 height, u32 stride) -> u8*; //scale.hpp - auto scaleLinearWidth(uint width) -> void; - auto scaleLinearHeight(uint height) -> void; - auto scaleLinear(uint width, uint height) -> void; - auto scaleNearest(uint width, uint height) -> void; + auto scaleLinearWidth(u32 width) -> void; + auto scaleLinearHeight(u32 height) -> void; + auto scaleLinear(u32 width, u32 height) -> void; + auto scaleNearest(u32 width, u32 height) -> void; //load.hpp auto loadBMP(const string& filename) -> bool; - auto loadBMP(const uint8_t* data, uint size) -> bool; + auto loadBMP(const u8* data, u32 size) -> bool; auto loadPNG(const string& filename) -> bool; - auto loadPNG(const uint8_t* data, uint size) -> bool; + auto loadPNG(const u8* data, u32 size) -> bool; //interpolation.hpp - auto isplit(uint64_t* component, uint64_t color) -> void; - auto imerge(const uint64_t* component) -> uint64_t; - auto interpolate1f(uint64_t a, uint64_t b, double x) -> uint64_t; - auto interpolate1f(uint64_t a, uint64_t b, uint64_t c, uint64_t d, double x, double y) -> uint64_t; - auto interpolate1i(int64_t a, int64_t b, uint32_t x) -> uint64_t; - auto interpolate1i(int64_t a, int64_t b, int64_t c, int64_t d, uint32_t x, uint32_t y) -> uint64_t; - auto interpolate4f(uint64_t a, uint64_t b, double x) -> uint64_t; - auto interpolate4f(uint64_t a, uint64_t b, uint64_t c, uint64_t d, double x, double y) -> uint64_t; - auto interpolate4i(uint64_t a, uint64_t b, uint32_t x) -> uint64_t; - auto interpolate4i(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint32_t x, uint32_t y) -> uint64_t; - - uint8_t* _data = nullptr; - uint _width = 0; - uint _height = 0; + auto isplit(u64* component, u64 color) -> void; + auto imerge(const u64* component) -> u64; + auto interpolate1f(u64 a, u64 b, f64 x) -> u64; + auto interpolate1f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64; + auto interpolate1i(s64 a, s64 b, u32 x) -> u64; + auto interpolate1i(s64 a, s64 b, s64 c, s64 d, u32 x, u32 y) -> u64; + auto interpolate4f(u64 a, u64 b, f64 x) -> u64; + auto interpolate4f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64; + auto interpolate4i(u64 a, u64 b, u32 x) -> u64; + auto interpolate4i(u64 a, u64 b, u64 c, u64 d, u32 x, u32 y) -> u64; + + u8* _data = nullptr; + u32 _width = 0; + u32 _height = 0; bool _endian = 0; //0 = lsb, 1 = msb - uint _depth = 32; + u32 _depth = 32; channel _alpha{255u << 24, 8, 24}; channel _red {255u << 16, 8, 16}; diff --git a/nall/image/blend.hpp b/nall/image/blend.hpp index 2898fceb88..721952cedb 100644 --- a/nall/image/blend.hpp +++ b/nall/image/blend.hpp @@ -2,27 +2,27 @@ namespace nall { -inline auto image::impose(blend mode, uint targetX, uint targetY, image source, uint sourceX, uint sourceY, uint sourceWidth, uint sourceHeight) -> void { +inline auto image::impose(blend mode, u32 targetX, u32 targetY, image source, u32 sourceX, u32 sourceY, u32 sourceWidth, u32 sourceHeight) -> void { source.transform(_endian, _depth, _alpha.mask(), _red.mask(), _green.mask(), _blue.mask()); - for(uint y = 0; y < sourceHeight; y++) { - const uint8_t* sp = source._data + source.pitch() * (sourceY + y) + source.stride() * sourceX; - uint8_t* dp = _data + pitch() * (targetY + y) + stride() * targetX; - for(uint x = 0; x < sourceWidth; x++) { - uint64_t sourceColor = source.read(sp); - uint64_t targetColor = read(dp); + for(u32 y = 0; y < sourceHeight; y++) { + const u8* sp = source._data + source.pitch() * (sourceY + y) + source.stride() * sourceX; + u8* dp = _data + pitch() * (targetY + y) + stride() * targetX; + for(u32 x = 0; x < sourceWidth; x++) { + u64 sourceColor = source.read(sp); + u64 targetColor = read(dp); - int64_t sa = (sourceColor & _alpha.mask()) >> _alpha.shift(); - int64_t sr = (sourceColor & _red.mask() ) >> _red.shift(); - int64_t sg = (sourceColor & _green.mask()) >> _green.shift(); - int64_t sb = (sourceColor & _blue.mask() ) >> _blue.shift(); + s64 sa = (sourceColor & _alpha.mask()) >> _alpha.shift(); + s64 sr = (sourceColor & _red.mask() ) >> _red.shift(); + s64 sg = (sourceColor & _green.mask()) >> _green.shift(); + s64 sb = (sourceColor & _blue.mask() ) >> _blue.shift(); - int64_t da = (targetColor & _alpha.mask()) >> _alpha.shift(); - int64_t dr = (targetColor & _red.mask() ) >> _red.shift(); - int64_t dg = (targetColor & _green.mask()) >> _green.shift(); - int64_t db = (targetColor & _blue.mask() ) >> _blue.shift(); + s64 da = (targetColor & _alpha.mask()) >> _alpha.shift(); + s64 dr = (targetColor & _red.mask() ) >> _red.shift(); + s64 dg = (targetColor & _green.mask()) >> _green.shift(); + s64 db = (targetColor & _blue.mask() ) >> _blue.shift(); - uint64_t a, r, g, b; + u64 a, r, g, b; switch(mode) { case blend::add: diff --git a/nall/image/core.hpp b/nall/image/core.hpp index 1fd38ff66b..34e7b25bd8 100644 --- a/nall/image/core.hpp +++ b/nall/image/core.hpp @@ -10,7 +10,7 @@ inline image::image(image&& source) { operator=(forward(source)); } -inline image::image(bool endian, uint depth, uint64_t alphaMask, uint64_t redMask, uint64_t greenMask, uint64_t blueMask) { +inline image::image(bool endian, u32 depth, u64 alphaMask, u64 redMask, u64 greenMask, u64 blueMask) { _endian = endian; _depth = depth; @@ -24,17 +24,17 @@ inline image::image(const string& filename) { load(filename); } -inline image::image(const void* data_, uint size) { - auto data = (const uint8_t*)data_; +inline image::image(const void* data_, u32 size) { + auto data = (const u8*)data_; if(size < 4); else if(data[0] == 'B' && data[1] == 'M') loadBMP(data, size); else if(data[1] == 'P' && data[2] == 'N' && data[3] == 'G') loadPNG(data, size); } -inline image::image(const vector& buffer) : image(buffer.data(), buffer.size()) { +inline image::image(const vector& buffer) : image(buffer.data(), buffer.size()) { } -template inline image::image(const uint8_t (&Name)[Size]) : image(Name, Size) { +template inline image::image(const u8 (&Name)[Size]) : image(Name, Size) { } inline image::image() { @@ -107,24 +107,24 @@ inline auto image::operator!=(const image& source) const -> bool { return !operator==(source); } -inline auto image::read(const uint8_t* data) const -> uint64_t { - uint64_t result = 0; +inline auto image::read(const u8* data) const -> u64 { + u64 result = 0; if(_endian == 0) { - for(int n = stride() - 1; n >= 0; n--) result = (result << 8) | data[n]; + for(s32 n = stride() - 1; n >= 0; n--) result = (result << 8) | data[n]; } else { - for(int n = 0; n < stride(); n++) result = (result << 8) | data[n]; + for(s32 n = 0; n < stride(); n++) result = (result << 8) | data[n]; } return result; } -inline auto image::write(uint8_t* data, uint64_t value) const -> void { +inline auto image::write(u8* data, u64 value) const -> void { if(_endian == 0) { - for(int n = 0; n < stride(); n++) { + for(s32 n = 0; n < stride(); n++) { data[n] = value; value >>= 8; } } else { - for(int n = stride() - 1; n >= 0; n--) { + for(s32 n = stride() - 1; n >= 0; n--) { data[n] = value; value >>= 8; } @@ -143,16 +143,16 @@ inline auto image::load(const string& filename) -> bool { } //assumes image and data are in the same format; pitch is adapted to image -inline auto image::copy(const void* data, uint pitch, uint width, uint height) -> void { +inline auto image::copy(const void* data, u32 pitch, u32 width, u32 height) -> void { allocate(width, height); - for(uint y : range(height)) { - auto input = (const uint8_t*)data + y * pitch; - auto output = (uint8_t*)_data + y * this->pitch(); + for(u32 y : range(height)) { + auto input = (const u8*)data + y * pitch; + auto output = (u8*)_data + y * this->pitch(); memory::copy(output, input, width * stride()); } } -inline auto image::allocate(uint width, uint height) -> void { +inline auto image::allocate(u32 width, u32 height) -> void { if(_data && _width == width && _height == height) return; free(); _width = width; @@ -161,11 +161,11 @@ inline auto image::allocate(uint width, uint height) -> void { } //private -inline auto image::allocate(uint width, uint height, uint stride) -> uint8_t* { +inline auto image::allocate(u32 width, u32 height, u32 stride) -> u8* { //allocate 1x1 larger than requested; so that linear interpolation does not require bounds-checking - uint size = width * height * stride; - uint padding = width * stride + stride; - auto data = new uint8_t[size + padding]; + u32 size = width * height * stride; + u32 padding = width * stride + stride; + auto data = new u8[size + padding]; memory::fill(data + size, padding); return data; } diff --git a/nall/image/fill.hpp b/nall/image/fill.hpp index a2ba2a74d9..ee3b6aeea6 100644 --- a/nall/image/fill.hpp +++ b/nall/image/fill.hpp @@ -2,35 +2,35 @@ namespace nall { -inline auto image::fill(uint64_t color) -> void { - for(uint y = 0; y < _height; y++) { - uint8_t* dp = _data + pitch() * y; - for(uint x = 0; x < _width; x++) { +inline auto image::fill(u64 color) -> void { + for(u32 y = 0; y < _height; y++) { + u8* dp = _data + pitch() * y; + for(u32 x = 0; x < _width; x++) { write(dp, color); dp += stride(); } } } -inline auto image::gradient(uint64_t a, uint64_t b, uint64_t c, uint64_t d) -> void { - for(uint y = 0; y < _height; y++) { - uint8_t* dp = _data + pitch() * y; - double muY = (double)y / (double)_height; - for(uint x = 0; x < _width; x++) { - double muX = (double)x / (double)_width; +inline auto image::gradient(u64 a, u64 b, u64 c, u64 d) -> void { + for(u32 y = 0; y < _height; y++) { + u8* dp = _data + pitch() * y; + f64 muY = (f64)y / (f64)_height; + for(u32 x = 0; x < _width; x++) { + f64 muX = (f64)x / (f64)_width; write(dp, interpolate4f(a, b, c, d, muX, muY)); dp += stride(); } } } -inline auto image::gradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY, function callback) -> void { - for(int y = 0; y < _height; y++) { - uint8_t* dp = _data + pitch() * y; - double py = max(-radiusY, min(+radiusY, y - centerY)) * 1.0 / radiusY; - for(int x = 0; x < _width; x++) { - double px = max(-radiusX, min(+radiusX, x - centerX)) * 1.0 / radiusX; - double mu = max(0.0, min(1.0, callback(px, py))); +inline auto image::gradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY, function callback) -> void { + for(s32 y = 0; y < _height; y++) { + u8* dp = _data + pitch() * y; + f64 py = max(-radiusY, min(+radiusY, y - centerY)) * 1.0 / radiusY; + for(s32 x = 0; x < _width; x++) { + f64 px = max(-radiusX, min(+radiusX, x - centerX)) * 1.0 / radiusX; + f64 mu = max(0.0, min(1.0, callback(px, py))); if(mu != mu) mu = 1.0; //NaN write(dp, interpolate4f(a, b, mu)); dp += stride(); @@ -38,45 +38,45 @@ inline auto image::gradient(uint64_t a, uint64_t b, int radiusX, int radiusY, in } } -inline auto image::crossGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::crossGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { x = fabs(x), y = fabs(y); return min(x, y) * min(x, y); }); } -inline auto image::diamondGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::diamondGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return fabs(x) + fabs(y); }); } -inline auto image::horizontalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::horizontalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return fabs(x); }); } -inline auto image::radialGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::radialGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return sqrt(x * x + y * y); }); } -inline auto image::sphericalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::sphericalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return x * x + y * y; }); } -inline auto image::squareGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::squareGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return max(fabs(x), fabs(y)); }); } -inline auto image::verticalGradient(uint64_t a, uint64_t b, int radiusX, int radiusY, int centerX, int centerY) -> void { - return gradient(a, b, radiusX, radiusY, centerX, centerY, [](double x, double y) -> double { +inline auto image::verticalGradient(u64 a, u64 b, s32 radiusX, s32 radiusY, s32 centerX, s32 centerY) -> void { + return gradient(a, b, radiusX, radiusY, centerX, centerY, [](f64 x, f64 y) -> f64 { return fabs(y); }); } diff --git a/nall/image/interpolation.hpp b/nall/image/interpolation.hpp index a88e6c21d1..1512d4aa6e 100644 --- a/nall/image/interpolation.hpp +++ b/nall/image/interpolation.hpp @@ -2,60 +2,60 @@ namespace nall { -inline auto image::isplit(uint64_t* c, uint64_t color) -> void { +inline auto image::isplit(u64 c[4], u64 color) -> void { c[0] = (color & _alpha.mask()) >> _alpha.shift(); c[1] = (color & _red.mask() ) >> _red.shift(); c[2] = (color & _green.mask()) >> _green.shift(); c[3] = (color & _blue.mask() ) >> _blue.shift(); } -inline auto image::imerge(const uint64_t* c) -> uint64_t { +inline auto image::imerge(const u64 c[4]) -> u64 { return c[0] << _alpha.shift() | c[1] << _red.shift() | c[2] << _green.shift() | c[3] << _blue.shift(); } -inline auto image::interpolate1f(uint64_t a, uint64_t b, double x) -> uint64_t { +inline auto image::interpolate1f(u64 a, u64 b, f64 x) -> u64 { return a * (1.0 - x) + b * x; } -inline auto image::interpolate1f(uint64_t a, uint64_t b, uint64_t c, uint64_t d, double x, double y) -> uint64_t { +inline auto image::interpolate1f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64 { return a * (1.0 - x) * (1.0 - y) + b * x * (1.0 - y) + c * (1.0 - x) * y + d * x * y; } -inline auto image::interpolate1i(int64_t a, int64_t b, uint32_t x) -> uint64_t { +inline auto image::interpolate1i(s64 a, s64 b, u32 x) -> u64 { return a + (((b - a) * x) >> 32); //a + (b - a) * x } -inline auto image::interpolate1i(int64_t a, int64_t b, int64_t c, int64_t d, uint32_t x, uint32_t y) -> uint64_t { +inline auto image::interpolate1i(s64 a, s64 b, s64 c, s64 d, u32 x, u32 y) -> u64 { a = a + (((b - a) * x) >> 32); //a + (b - a) * x c = c + (((d - c) * x) >> 32); //c + (d - c) * x return a + (((c - a) * y) >> 32); //a + (c - a) * y } -inline auto image::interpolate4f(uint64_t a, uint64_t b, double x) -> uint64_t { - uint64_t o[4], pa[4], pb[4]; +inline auto image::interpolate4f(u64 a, u64 b, f64 x) -> u64 { + u64 o[4], pa[4], pb[4]; isplit(pa, a), isplit(pb, b); - for(uint n = 0; n < 4; n++) o[n] = interpolate1f(pa[n], pb[n], x); + for(u32 n = 0; n < 4; n++) o[n] = interpolate1f(pa[n], pb[n], x); return imerge(o); } -inline auto image::interpolate4f(uint64_t a, uint64_t b, uint64_t c, uint64_t d, double x, double y) -> uint64_t { - uint64_t o[4], pa[4], pb[4], pc[4], pd[4]; +inline auto image::interpolate4f(u64 a, u64 b, u64 c, u64 d, f64 x, f64 y) -> u64 { + u64 o[4], pa[4], pb[4], pc[4], pd[4]; isplit(pa, a), isplit(pb, b), isplit(pc, c), isplit(pd, d); - for(uint n = 0; n < 4; n++) o[n] = interpolate1f(pa[n], pb[n], pc[n], pd[n], x, y); + for(u32 n = 0; n < 4; n++) o[n] = interpolate1f(pa[n], pb[n], pc[n], pd[n], x, y); return imerge(o); } -inline auto image::interpolate4i(uint64_t a, uint64_t b, uint32_t x) -> uint64_t { - uint64_t o[4], pa[4], pb[4]; +inline auto image::interpolate4i(u64 a, u64 b, u32 x) -> u64 { + u64 o[4], pa[4], pb[4]; isplit(pa, a), isplit(pb, b); - for(uint n = 0; n < 4; n++) o[n] = interpolate1i(pa[n], pb[n], x); + for(u32 n = 0; n < 4; n++) o[n] = interpolate1i(pa[n], pb[n], x); return imerge(o); } -inline auto image::interpolate4i(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint32_t x, uint32_t y) -> uint64_t { - uint64_t o[4], pa[4], pb[4], pc[4], pd[4]; +inline auto image::interpolate4i(u64 a, u64 b, u64 c, u64 d, u32 x, u32 y) -> u64 { + u64 o[4], pa[4], pb[4], pc[4], pd[4]; isplit(pa, a), isplit(pb, b), isplit(pc, c), isplit(pd, d); - for(uint n = 0; n < 4; n++) o[n] = interpolate1i(pa[n], pb[n], pc[n], pd[n], x, y); + for(u32 n = 0; n < 4; n++) o[n] = interpolate1i(pa[n], pb[n], pc[n], pd[n], x, y); return imerge(o); } diff --git a/nall/image/load.hpp b/nall/image/load.hpp index 8733dac25c..13541bf3d9 100644 --- a/nall/image/load.hpp +++ b/nall/image/load.hpp @@ -8,21 +8,21 @@ inline auto image::loadBMP(const string& filename) -> bool { return loadBMP(buffer.data(), buffer.size()); } -inline auto image::loadBMP(const uint8_t* bmpData, uint bmpSize) -> bool { +inline auto image::loadBMP(const u8* bmpData, u32 bmpSize) -> bool { Decode::BMP source; if(!source.load(bmpData, bmpSize)) return false; allocate(source.width(), source.height()); - const uint32_t* sp = source.data(); - uint8_t* dp = _data; - - for(uint y = 0; y < _height; y++) { - for(uint x = 0; x < _width; x++) { - uint32_t color = *sp++; - uint64_t a = normalize((uint8_t)(color >> 24), 8, _alpha.depth()); - uint64_t r = normalize((uint8_t)(color >> 16), 8, _red.depth()); - uint64_t g = normalize((uint8_t)(color >> 8), 8, _green.depth()); - uint64_t b = normalize((uint8_t)(color >> 0), 8, _blue.depth()); + const u32* sp = source.data(); + u8* dp = _data; + + for(u32 y = 0; y < _height; y++) { + for(u32 x = 0; x < _width; x++) { + u32 color = *sp++; + u64 a = normalize((u8)(color >> 24), 8, _alpha.depth()); + u64 r = normalize((u8)(color >> 16), 8, _red.depth()); + u64 g = normalize((u8)(color >> 8), 8, _green.depth()); + u64 b = normalize((u8)(color >> 0), 8, _blue.depth()); write(dp, (a << _alpha.shift()) | (r << _red.shift()) | (g << _green.shift()) | (b << _blue.shift())); dp += stride(); } @@ -37,16 +37,16 @@ inline auto image::loadPNG(const string& filename) -> bool { return loadPNG(buffer.data(), buffer.size()); } -inline auto image::loadPNG(const uint8_t* pngData, uint pngSize) -> bool { +inline auto image::loadPNG(const u8* pngData, u32 pngSize) -> bool { Decode::PNG source; if(!source.load(pngData, pngSize)) return false; allocate(source.info.width, source.info.height); - const uint8_t* sp = source.data; - uint8_t* dp = _data; + const u8* sp = source.data; + u8* dp = _data; - auto decode = [&]() -> uint64_t { - uint64_t p, r, g, b, a; + auto decode = [&]() -> u64 { + u64 p, r, g, b, a; switch(source.info.colorType) { case 0: //L @@ -86,8 +86,8 @@ inline auto image::loadPNG(const uint8_t* pngData, uint pngSize) -> bool { return (a << _alpha.shift()) | (r << _red.shift()) | (g << _green.shift()) | (b << _blue.shift()); }; - for(uint y = 0; y < _height; y++) { - for(uint x = 0; x < _width; x++) { + for(u32 y = 0; y < _height; y++) { + for(u32 x = 0; x < _width; x++) { write(dp, decode()); dp += stride(); } diff --git a/nall/image/scale.hpp b/nall/image/scale.hpp index 21a461c961..66bb4a7d4d 100644 --- a/nall/image/scale.hpp +++ b/nall/image/scale.hpp @@ -2,7 +2,7 @@ namespace nall { -inline auto image::scale(uint outputWidth, uint outputHeight, bool linear) -> void { +inline auto image::scale(u32 outputWidth, u32 outputHeight, bool linear) -> void { if(!_data) return; if(_width == outputWidth && _height == outputHeight) return; //no scaling necessary if(linear == false) return scaleNearest(outputWidth, outputHeight); @@ -13,31 +13,31 @@ inline auto image::scale(uint outputWidth, uint outputHeight, bool linear) -> vo //find fastest scaling method, based on number of interpolation operations required //magnification usually benefits from two-pass linear interpolation //minification usually benefits from one-pass bilinear interpolation - uint d1wh = ((_width * outputWidth ) + (outputWidth * outputHeight)) * 1; - uint d1hw = ((_height * outputHeight) + (outputWidth * outputHeight)) * 1; - uint d2wh = (outputWidth * outputHeight) * 3; + u32 d1wh = ((_width * outputWidth ) + (outputWidth * outputHeight)) * 1; + u32 d1hw = ((_height * outputHeight) + (outputWidth * outputHeight)) * 1; + u32 d2wh = (outputWidth * outputHeight) * 3; if(d1wh <= d1hw && d1wh <= d2wh) return scaleLinearWidth(outputWidth), scaleLinearHeight(outputHeight); if(d1hw <= d2wh) return scaleLinearHeight(outputHeight), scaleLinearWidth(outputWidth); return scaleLinear(outputWidth, outputHeight); } -inline auto image::scaleLinearWidth(uint outputWidth) -> void { - uint8_t* outputData = allocate(outputWidth, _height, stride()); - uint outputPitch = outputWidth * stride(); - uint64_t xstride = ((uint64_t)(_width - 1) << 32) / max(1u, outputWidth - 1); +inline auto image::scaleLinearWidth(u32 outputWidth) -> void { + u8* outputData = allocate(outputWidth, _height, stride()); + u32 outputPitch = outputWidth * stride(); + u64 xstride = ((u64)(_width - 1) << 32) / max(1u, outputWidth - 1); - for(uint y = 0; y < _height; y++) { - uint64_t xfraction = 0; + for(u32 y = 0; y < _height; y++) { + u64 xfraction = 0; - const uint8_t* sp = _data + pitch() * y; - uint8_t* dp = outputData + outputPitch * y; + const u8* sp = _data + pitch() * y; + u8* dp = outputData + outputPitch * y; - uint64_t a = read(sp); - uint64_t b = read(sp + stride()); + u64 a = read(sp); + u64 b = read(sp + stride()); sp += stride(); - uint x = 0; + u32 x = 0; while(true) { while(xfraction < 0x100000000 && x++ < outputWidth) { write(dp, interpolate4i(a, b, xfraction)); @@ -58,21 +58,21 @@ inline auto image::scaleLinearWidth(uint outputWidth) -> void { _width = outputWidth; } -inline auto image::scaleLinearHeight(uint outputHeight) -> void { - uint8_t* outputData = allocate(_width, outputHeight, stride()); - uint64_t ystride = ((uint64_t)(_height - 1) << 32) / max(1u, outputHeight - 1); +inline auto image::scaleLinearHeight(u32 outputHeight) -> void { + u8* outputData = allocate(_width, outputHeight, stride()); + u64 ystride = ((u64)(_height - 1) << 32) / max(1u, outputHeight - 1); - for(uint x = 0; x < _width; x++) { - uint64_t yfraction = 0; + for(u32 x = 0; x < _width; x++) { + u64 yfraction = 0; - const uint8_t* sp = _data + stride() * x; - uint8_t* dp = outputData + stride() * x; + const u8* sp = _data + stride() * x; + u8* dp = outputData + stride() * x; - uint64_t a = read(sp); - uint64_t b = read(sp + pitch()); + u64 a = read(sp); + u64 b = read(sp + pitch()); sp += pitch(); - uint y = 0; + u32 y = 0; while(true) { while(yfraction < 0x100000000 && y++ < outputHeight) { write(dp, interpolate4i(a, b, yfraction)); @@ -93,27 +93,27 @@ inline auto image::scaleLinearHeight(uint outputHeight) -> void { _height = outputHeight; } -inline auto image::scaleLinear(uint outputWidth, uint outputHeight) -> void { - uint8_t* outputData = allocate(outputWidth, outputHeight, stride()); - uint outputPitch = outputWidth * stride(); +inline auto image::scaleLinear(u32 outputWidth, u32 outputHeight) -> void { + u8* outputData = allocate(outputWidth, outputHeight, stride()); + u32 outputPitch = outputWidth * stride(); - uint64_t xstride = ((uint64_t)(_width - 1) << 32) / max(1u, outputWidth - 1); - uint64_t ystride = ((uint64_t)(_height - 1) << 32) / max(1u, outputHeight - 1); + u64 xstride = ((u64)(_width - 1) << 32) / max(1u, outputWidth - 1); + u64 ystride = ((u64)(_height - 1) << 32) / max(1u, outputHeight - 1); - for(uint y = 0; y < outputHeight; y++) { - uint64_t yfraction = ystride * y; - uint64_t xfraction = 0; + for(u32 y = 0; y < outputHeight; y++) { + u64 yfraction = ystride * y; + u64 xfraction = 0; - const uint8_t* sp = _data + pitch() * (yfraction >> 32); - uint8_t* dp = outputData + outputPitch * y; + const u8* sp = _data + pitch() * (yfraction >> 32); + u8* dp = outputData + outputPitch * y; - uint64_t a = read(sp); - uint64_t b = read(sp + stride()); - uint64_t c = read(sp + pitch()); - uint64_t d = read(sp + pitch() + stride()); + u64 a = read(sp); + u64 b = read(sp + stride()); + u64 c = read(sp + pitch()); + u64 d = read(sp + pitch() + stride()); sp += stride(); - uint x = 0; + u32 x = 0; while(true) { while(xfraction < 0x100000000 && x++ < outputWidth) { write(dp, interpolate4i(a, b, c, d, xfraction, yfraction)); @@ -137,23 +137,23 @@ inline auto image::scaleLinear(uint outputWidth, uint outputHeight) -> void { _height = outputHeight; } -inline auto image::scaleNearest(uint outputWidth, uint outputHeight) -> void { - uint8_t* outputData = allocate(outputWidth, outputHeight, stride()); - uint outputPitch = outputWidth * stride(); +inline auto image::scaleNearest(u32 outputWidth, u32 outputHeight) -> void { + u8* outputData = allocate(outputWidth, outputHeight, stride()); + u32 outputPitch = outputWidth * stride(); - uint64_t xstride = ((uint64_t)_width << 32) / outputWidth; - uint64_t ystride = ((uint64_t)_height << 32) / outputHeight; + u64 xstride = ((u64)_width << 32) / outputWidth; + u64 ystride = ((u64)_height << 32) / outputHeight; - for(uint y = 0; y < outputHeight; y++) { - uint64_t yfraction = ystride * y; - uint64_t xfraction = 0; + for(u32 y = 0; y < outputHeight; y++) { + u64 yfraction = ystride * y; + u64 xfraction = 0; - const uint8_t* sp = _data + pitch() * (yfraction >> 32); - uint8_t* dp = outputData + outputPitch * y; + const u8* sp = _data + pitch() * (yfraction >> 32); + u8* dp = outputData + outputPitch * y; - uint64_t a = read(sp); + u64 a = read(sp); - uint x = 0; + u32 x = 0; while(true) { while(xfraction < 0x100000000 && x++ < outputWidth) { write(dp, a); diff --git a/nall/image/static.hpp b/nall/image/static.hpp index 5bd2ded4b1..7108aced5f 100644 --- a/nall/image/static.hpp +++ b/nall/image/static.hpp @@ -2,20 +2,20 @@ namespace nall { -inline auto image::bitDepth(uint64_t color) -> uint { - uint depth = 0; +inline auto image::bitDepth(u64 color) -> u32 { + u32 depth = 0; if(color) while((color & 1) == 0) color >>= 1; while((color & 1) == 1) { color >>= 1; depth++; } return depth; } -inline auto image::bitShift(uint64_t color) -> uint { - uint shift = 0; +inline auto image::bitShift(u64 color) -> u32 { + u32 shift = 0; if(color) while((color & 1) == 0) { color >>= 1; shift++; } return shift; } -inline auto image::normalize(uint64_t color, uint sourceDepth, uint targetDepth) -> uint64_t { +inline auto image::normalize(u64 color, u32 sourceDepth, u32 targetDepth) -> u64 { if(sourceDepth == 0 || targetDepth == 0) return 0; while(sourceDepth < targetDepth) { color = (color << sourceDepth) | color; diff --git a/nall/image/utility.hpp b/nall/image/utility.hpp index a7b0151dc4..5bda69e5e1 100644 --- a/nall/image/utility.hpp +++ b/nall/image/utility.hpp @@ -5,13 +5,13 @@ namespace nall { //scan all four sides of the image for fully transparent pixels, and then crop them //imagine an icon centered on a transparent background: this function removes the bordering //this certainly won't win any speed awards, but nall::image is meant to be correct and simple, not fast -inline auto image::shrink(uint64_t transparentColor) -> void { +inline auto image::shrink(u64 transparentColor) -> void { //top - { uint padding = 0; - for(uint y : range(_height)) { - const uint8_t* sp = _data + pitch() * y; + { u32 padding = 0; + for(u32 y : range(_height)) { + const u8* sp = _data + pitch() * y; bool found = false; - for(uint x : range(_width)) { + for(u32 x : range(_width)) { if(read(sp) != transparentColor) { found = true; break; } sp += stride(); } @@ -22,11 +22,11 @@ inline auto image::shrink(uint64_t transparentColor) -> void { } //bottom - { uint padding = 0; - for(uint y : reverse(range(_height))) { - const uint8_t* sp = _data + pitch() * y; + { u32 padding = 0; + for(u32 y : reverse(range(_height))) { + const u8* sp = _data + pitch() * y; bool found = false; - for(uint x : range(_width)) { + for(u32 x : range(_width)) { if(read(sp) != transparentColor) { found = true; break; } sp += stride(); } @@ -37,11 +37,11 @@ inline auto image::shrink(uint64_t transparentColor) -> void { } //left - { uint padding = 0; - for(uint x : range(_width)) { - const uint8_t* sp = _data + stride() * x; + { u32 padding = 0; + for(u32 x : range(_width)) { + const u8* sp = _data + stride() * x; bool found = false; - for(uint y : range(_height)) { + for(u32 y : range(_height)) { if(read(sp) != transparentColor) { found = true; break; } sp += pitch(); } @@ -52,11 +52,11 @@ inline auto image::shrink(uint64_t transparentColor) -> void { } //right - { uint padding = 0; - for(uint x : reverse(range(_width))) { - const uint8_t* sp = _data + stride() * x; + { u32 padding = 0; + for(u32 x : reverse(range(_width))) { + const u8* sp = _data + stride() * x; bool found = false; - for(uint y : range(_height)) { + for(u32 y : range(_height)) { if(read(sp) != transparentColor) { found = true; break; } sp += pitch(); } @@ -67,17 +67,17 @@ inline auto image::shrink(uint64_t transparentColor) -> void { } } -inline auto image::crop(uint outputX, uint outputY, uint outputWidth, uint outputHeight) -> bool { +inline auto image::crop(u32 outputX, u32 outputY, u32 outputWidth, u32 outputHeight) -> bool { if(outputX + outputWidth > _width) return false; if(outputY + outputHeight > _height) return false; - uint8_t* outputData = allocate(outputWidth, outputHeight, stride()); - uint outputPitch = outputWidth * stride(); + u8* outputData = allocate(outputWidth, outputHeight, stride()); + u32 outputPitch = outputWidth * stride(); - for(uint y = 0; y < outputHeight; y++) { - const uint8_t* sp = _data + pitch() * (outputY + y) + stride() * outputX; - uint8_t* dp = outputData + outputPitch * y; - for(uint x = 0; x < outputWidth; x++) { + for(u32 y = 0; y < outputHeight; y++) { + const u8* sp = _data + pitch() * (outputY + y) + stride() * outputX; + u8* dp = outputData + outputPitch * y; + for(u32 x = 0; x < outputWidth; x++) { write(dp, read(sp)); sp += stride(); dp += stride(); @@ -91,21 +91,21 @@ inline auto image::crop(uint outputX, uint outputY, uint outputWidth, uint outpu return true; } -inline auto image::alphaBlend(uint64_t alphaColor) -> void { - uint64_t alphaR = (alphaColor & _red.mask() ) >> _red.shift(); - uint64_t alphaG = (alphaColor & _green.mask()) >> _green.shift(); - uint64_t alphaB = (alphaColor & _blue.mask() ) >> _blue.shift(); +inline auto image::alphaBlend(u64 alphaColor) -> void { + u64 alphaR = (alphaColor & _red.mask() ) >> _red.shift(); + u64 alphaG = (alphaColor & _green.mask()) >> _green.shift(); + u64 alphaB = (alphaColor & _blue.mask() ) >> _blue.shift(); - for(uint y = 0; y < _height; y++) { - uint8_t* dp = _data + pitch() * y; - for(uint x = 0; x < _width; x++) { - uint64_t color = read(dp); + for(u32 y = 0; y < _height; y++) { + u8* dp = _data + pitch() * y; + for(u32 x = 0; x < _width; x++) { + u64 color = read(dp); - uint64_t colorA = (color & _alpha.mask()) >> _alpha.shift(); - uint64_t colorR = (color & _red.mask() ) >> _red.shift(); - uint64_t colorG = (color & _green.mask()) >> _green.shift(); - uint64_t colorB = (color & _blue.mask() ) >> _blue.shift(); - double alphaScale = (double)colorA / (double)((1 << _alpha.depth()) - 1); + u64 colorA = (color & _alpha.mask()) >> _alpha.shift(); + u64 colorR = (color & _red.mask() ) >> _red.shift(); + u64 colorG = (color & _green.mask()) >> _green.shift(); + u64 colorB = (color & _blue.mask() ) >> _blue.shift(); + f64 alphaScale = (f64)colorA / (f64)((1 << _alpha.depth()) - 1); colorA = (1 << _alpha.depth()) - 1; colorR = (colorR * alphaScale) + (alphaR * (1.0 - alphaScale)); @@ -119,17 +119,17 @@ inline auto image::alphaBlend(uint64_t alphaColor) -> void { } inline auto image::alphaMultiply() -> void { - uint divisor = (1 << _alpha.depth()) - 1; + u32 divisor = (1 << _alpha.depth()) - 1; - for(uint y = 0; y < _height; y++) { - uint8_t* dp = _data + pitch() * y; - for(uint x = 0; x < _width; x++) { - uint64_t color = read(dp); + for(u32 y = 0; y < _height; y++) { + u8* dp = _data + pitch() * y; + for(u32 x = 0; x < _width; x++) { + u64 color = read(dp); - uint64_t colorA = (color & _alpha.mask()) >> _alpha.shift(); - uint64_t colorR = (color & _red.mask() ) >> _red.shift(); - uint64_t colorG = (color & _green.mask()) >> _green.shift(); - uint64_t colorB = (color & _blue.mask() ) >> _blue.shift(); + u64 colorA = (color & _alpha.mask()) >> _alpha.shift(); + u64 colorR = (color & _red.mask() ) >> _red.shift(); + u64 colorG = (color & _green.mask()) >> _green.shift(); + u64 colorB = (color & _blue.mask() ) >> _blue.shift(); colorR = (colorR * colorA) / divisor; colorG = (colorG * colorA) / divisor; @@ -145,23 +145,23 @@ inline auto image::transform(const image& source) -> void { return transform(source._endian, source._depth, source._alpha.mask(), source._red.mask(), source._green.mask(), source._blue.mask()); } -inline auto image::transform(bool outputEndian, uint outputDepth, uint64_t outputAlphaMask, uint64_t outputRedMask, uint64_t outputGreenMask, uint64_t outputBlueMask) -> void { +inline auto image::transform(bool outputEndian, u32 outputDepth, u64 outputAlphaMask, u64 outputRedMask, u64 outputGreenMask, u64 outputBlueMask) -> void { if(_endian == outputEndian && _depth == outputDepth && _alpha.mask() == outputAlphaMask && _red.mask() == outputRedMask && _green.mask() == outputGreenMask && _blue.mask() == outputBlueMask) return; image output(outputEndian, outputDepth, outputAlphaMask, outputRedMask, outputGreenMask, outputBlueMask); output.allocate(_width, _height); - for(uint y = 0; y < _height; y++) { - const uint8_t* sp = _data + pitch() * y; - uint8_t* dp = output._data + output.pitch() * y; - for(uint x = 0; x < _width; x++) { - uint64_t color = read(sp); + for(u32 y = 0; y < _height; y++) { + const u8* sp = _data + pitch() * y; + u8* dp = output._data + output.pitch() * y; + for(u32 x = 0; x < _width; x++) { + u64 color = read(sp); sp += stride(); - uint64_t a = (color & _alpha.mask()) >> _alpha.shift(); - uint64_t r = (color & _red.mask() ) >> _red.shift(); - uint64_t g = (color & _green.mask()) >> _green.shift(); - uint64_t b = (color & _blue.mask() ) >> _blue.shift(); + u64 a = (color & _alpha.mask()) >> _alpha.shift(); + u64 r = (color & _red.mask() ) >> _red.shift(); + u64 g = (color & _green.mask()) >> _green.shift(); + u64 b = (color & _blue.mask() ) >> _blue.shift(); a = normalize(a, _alpha.depth(), output._alpha.depth()); r = normalize(r, _red.depth(), output._red.depth()); diff --git a/nall/induced-sort.hpp b/nall/induced-sort.hpp index c544a89353..0df42c3ef2 100644 --- a/nall/induced-sort.hpp +++ b/nall/induced-sort.hpp @@ -10,17 +10,17 @@ namespace nall { //where the first character is the empty suffix, equal to size template -inline auto induced_sort(array_view data, const uint characters = 256) -> vector { - const uint size = data.size(); - if(size == 0) return vector{0}; //required to avoid out-of-bounds accesses - if(size == 1) return vector{1, 0}; //not strictly necessary; but more performant +inline auto induced_sort(array_view data, const u32 characters = 256) -> vector { + const u32 size = data.size(); + if(size == 0) return vector{0}; //required to avoid out-of-bounds accesses + if(size == 1) return vector{1, 0}; //not strictly necessary; but more performant vector types; //0 = S-suffix (sort before next suffix), 1 = L-suffix (sort after next suffix) types.resize(size + 1); types[size - 0] = 0; //empty suffix is always S-suffix types[size - 1] = 1; //last suffix is always L-suffix compared to empty suffix - for(uint n : reverse(range(size - 1))) { + for(u32 n : reverse(range(size - 1))) { if(data[n] < data[n + 1]) { types[n] = 0; //this suffix is smaller than the one after it } else if(data[n] > data[n + 1]) { @@ -31,16 +31,16 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec } //left-most S-suffix - auto isLMS = [&](int n) -> bool { + auto isLMS = [&](s32 n) -> bool { if(n == 0) return 0; //no character to the left of the first suffix return !types[n] && types[n - 1]; //true if this is the start of a new S-suffix }; //test if two LMS-substrings are equal - auto isEqual = [&](int lhs, int rhs) -> bool { + auto isEqual = [&](s32 lhs, s32 rhs) -> bool { if(lhs == size || rhs == size) return false; //no other suffix can be equal to the empty suffix - for(uint n = 0;; n++) { + for(u32 n = 0;; n++) { bool lhsLMS = isLMS(lhs + n); bool rhsLMS = isLMS(rhs + n); if(n && lhsLMS && rhsLMS) return true; //substrings are identical @@ -50,42 +50,42 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec }; //determine the sizes of each bucket: one bucket per character - vector counts; + vector counts; counts.resize(characters); - for(uint n : range(size)) counts[data[n]]++; + for(u32 n : range(size)) counts[data[n]]++; //bucket sorting start offsets - vector heads; + vector heads; heads.resize(characters); - uint headOffset; + u32 headOffset; auto getHeads = [&] { headOffset = 1; - for(uint n : range(characters)) { + for(u32 n : range(characters)) { heads[n] = headOffset; headOffset += counts[n]; } }; //bucket sorting end offsets - vector tails; + vector tails; tails.resize(characters); - uint tailOffset; + u32 tailOffset; auto getTails = [&] { tailOffset = 1; - for(uint n : range(characters)) { + for(u32 n : range(characters)) { tailOffset += counts[n]; tails[n] = tailOffset - 1; } }; //inaccurate LMS bucket sort - vector suffixes; - suffixes.resize(size + 1, (int)-1); + vector suffixes; + suffixes.resize(size + 1, (s32)-1); getTails(); - for(uint n : range(size)) { + for(u32 n : range(size)) { if(!isLMS(n)) continue; //skip non-LMS-suffixes suffixes[tails[data[n]]--] = n; //advance from the tail of the bucket } @@ -95,7 +95,7 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec //sort all L-suffixes to the left of LMS-suffixes auto sortL = [&] { getHeads(); - for(uint n : range(size + 1)) { + for(u32 n : range(size + 1)) { if(suffixes[n] == -1) continue; //offsets may not be known yet here ... auto l = suffixes[n] - 1; if(l < 0 || !types[l]) continue; //skip S-suffixes @@ -105,7 +105,7 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec auto sortS = [&] { getTails(); - for(uint n : reverse(range(size + 1))) { + for(u32 n : reverse(range(size + 1))) { auto l = suffixes[n] - 1; if(l < 0 || types[l]) continue; //skip L-suffixes suffixes[tails[data[l]]--] = l; //advance from the tail of the bucket @@ -116,14 +116,14 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec sortS(); //analyze data for the summary suffix array - vector names; - names.resize(size + 1, (int)-1); + vector names; + names.resize(size + 1, (s32)-1); - uint currentName = 0; //keep a count to tag each unique LMS-substring with unique IDs + u32 currentName = 0; //keep a count to tag each unique LMS-substring with unique IDs auto lastLMSOffset = suffixes[0]; //location in the original data of the last checked LMS suffix names[lastLMSOffset] = currentName; //the first LMS-substring is always the empty suffix entry, at position 0 - for(uint n : range(1, size + 1)) { + for(u32 n : range(1, size + 1)) { auto offset = suffixes[n]; if(!isLMS(offset)) continue; //only LMS suffixes are important @@ -133,35 +133,35 @@ inline auto induced_sort(array_view data, const uint characters = 256) -> vec names[lastLMSOffset] = currentName; //store the LMS suffix name where the suffix appears at in the original data } - vector summaryOffsets; - vector summaryData; - for(uint n : range(size + 1)) { + vector summaryOffsets; + vector summaryData; + for(u32 n : range(size + 1)) { if(names[n] == -1) continue; summaryOffsets.append(n); summaryData.append(names[n]); } - uint summaryCharacters = currentName + 1; //zero-indexed, so the total unique characters is currentName + 1 + u32 summaryCharacters = currentName + 1; //zero-indexed, so the total unique characters is currentName + 1 //make the summary suffix array - vector summaries; + vector summaries; if(summaryData.size() == summaryCharacters) { //simple bucket sort when every character in summaryData appears only once - summaries.resize(summaryData.size() + 1, (int)-1); + summaries.resize(summaryData.size() + 1, (s32)-1); summaries[0] = summaryData.size(); //always include the empty suffix at the beginning - for(int x : range(summaryData.size())) { - int y = summaryData[x]; + for(s32 x : range(summaryData.size())) { + s32 y = summaryData[x]; summaries[y + 1] = x; } } else { //recurse until every character in summaryData is unique ... - summaries = induced_sort({summaryData.data(), summaryData.size()}, summaryCharacters); + summaries = induced_sort({summaryData.data(), summaryData.size()}, summaryCharacters); } suffixes.fill(-1); //reuse existing buffer for accurate sort //accurate LMS sort getTails(); - for(uint n : reverse(range(2, summaries.size()))) { + for(u32 n : reverse(range(2, summaries.size()))) { auto index = summaryOffsets[summaries[n]]; suffixes[tails[data[index]]--] = index; //advance from the tail of the bucket } diff --git a/nall/inode.hpp b/nall/inode.hpp index 89bebb249a..491fdd1612 100644 --- a/nall/inode.hpp +++ b/nall/inode.hpp @@ -9,7 +9,7 @@ namespace nall { struct inode { - enum class time : uint { create, modify, access }; + enum class time : u32 { create, modify, access }; inode() = delete; inode(const inode&) = delete; @@ -41,19 +41,19 @@ struct inode { #endif } - static auto mode(const string& name) -> uint { + static auto mode(const string& name) -> u32 { struct stat data{}; stat(name, &data); return data.st_mode; } - static auto uid(const string& name) -> uint { + static auto uid(const string& name) -> u32 { struct stat data{}; stat(name, &data); return data.st_uid; } - static auto gid(const string& name) -> uint { + static auto gid(const string& name) -> u32 { struct stat data{}; stat(name, &data); return data.st_gid; @@ -75,7 +75,7 @@ struct inode { return {}; } - static auto timestamp(const string& name, time mode = time::modify) -> uint64_t { + static auto timestamp(const string& name, time mode = time::modify) -> u64 { struct stat data{}; stat(name, &data); switch(mode) { @@ -85,7 +85,7 @@ struct inode { #elif defined(PLATFORM_BSD) || defined(PLATFORM_MACOS) //st_birthtime may return -1 or st_atime if it is not supported by the file system //the best that can be done in this case is to return st_mtime if it's older - case time::create: return min((uint)data.st_birthtime, (uint)data.st_mtime); + case time::create: return min((u32)data.st_birthtime, (u32)data.st_mtime); #else //Linux simply doesn't support file creation time at all //this is also our fallback case for unsupported operating systems @@ -94,12 +94,12 @@ struct inode { case time::modify: return data.st_mtime; //for performance reasons, last access time is usually not enabled on various filesystems //ensure that the last access time is not older than the last modify time (eg for NTFS) - case time::access: return max((uint)data.st_atime, data.st_mtime); + case time::access: return max((u32)data.st_atime, data.st_mtime); } return 0; } - static auto setMode(const string& name, uint mode) -> bool { + static auto setMode(const string& name, u32 mode) -> bool { #if !defined(PLATFORM_WINDOWS) return chmod(name, mode) == 0; #else @@ -127,7 +127,7 @@ struct inode { #endif } - static auto setTimestamp(const string& name, uint64_t value, time mode = time::modify) -> bool { + static auto setTimestamp(const string& name, u64 value, time mode = time::modify) -> bool { struct utimbuf timeBuffer; timeBuffer.modtime = mode == time::modify ? value : inode::timestamp(name, time::modify); timeBuffer.actime = mode == time::access ? value : inode::timestamp(name, time::access); @@ -135,10 +135,10 @@ struct inode { } //returns true if 'name' already exists - static auto create(const string& name, uint permissions = 0755) -> bool { + static auto create(const string& name, u32 permissions = 0755) -> bool { if(exists(name)) return true; if(name.endsWith("/")) return mkdir(name, permissions) == 0; - int fd = open(name, O_CREAT | O_EXCL, permissions); + s32 fd = open(name, O_CREAT | O_EXCL, permissions); if(fd < 0) return false; return close(fd), true; } diff --git a/nall/interpolation.hpp b/nall/interpolation.hpp index 007f2ec206..dc753b2891 100644 --- a/nall/interpolation.hpp +++ b/nall/interpolation.hpp @@ -3,38 +3,38 @@ namespace nall { struct Interpolation { - static inline auto Nearest(double mu, double a, double b, double c, double d) -> double { + static inline auto Nearest(f64 mu, f64 a, f64 b, f64 c, f64 d) -> f64 { return (mu <= 0.5 ? b : c); } - static inline auto Sublinear(double mu, double a, double b, double c, double d) -> double { + static inline auto Sublinear(f64 mu, f64 a, f64 b, f64 c, f64 d) -> f64 { mu = ((mu - 0.5) * 2.0) + 0.5; if(mu < 0) mu = 0; if(mu > 1) mu = 1; return b * (1.0 - mu) + c * mu; } - static inline auto Linear(double mu, double a, double b, double c, double d) -> double { + static inline auto Linear(f64 mu, f64 a, f64 b, f64 c, f64 d) -> f64 { return b * (1.0 - mu) + c * mu; } - static inline auto Cosine(double mu, double a, double b, double c, double d) -> double { + static inline auto Cosine(f64 mu, f64 a, f64 b, f64 c, f64 d) -> f64 { mu = (1.0 - cos(mu * Math::Pi)) / 2.0; return b * (1.0 - mu) + c * mu; } - static inline auto Cubic(double mu, double a, double b, double c, double d) -> double { - double A = d - c - a + b; - double B = a - b - A; - double C = c - a; - double D = b; + static inline auto Cubic(f64 mu, f64 a, f64 b, f64 c, f64 d) -> f64 { + f64 A = d - c - a + b; + f64 B = a - b - A; + f64 C = c - a; + f64 D = b; return A * (mu * mu * mu) + B * (mu * mu) + C * mu + D; } - static inline auto Hermite(double mu1, double a, double b, double c, double d) -> double { - const double tension = 0.0; //-1 = low, 0 = normal, +1 = high - const double bias = 0.0; //-1 = left, 0 = even, +1 = right - double mu2, mu3, m0, m1, a0, a1, a2, a3; + static inline auto Hermite(f64 mu1, f64 a, f64 b, f64 c, f64 d) -> f64 { + const f64 tension = 0.0; //-1 = low, 0 = normal, +1 = high + const f64 bias = 0.0; //-1 = left, 0 = even, +1 = right + f64 mu2, mu3, m0, m1, a0, a1, a2, a3; mu2 = mu1 * mu1; mu3 = mu2 * mu1; diff --git a/nall/intrinsics.hpp b/nall/intrinsics.hpp index 67a4da2238..46a3b63fc1 100644 --- a/nall/intrinsics.hpp +++ b/nall/intrinsics.hpp @@ -1,15 +1,15 @@ #pragma once namespace nall { - using uint = unsigned; + using u32 = unsigned int; - enum class Compiler : uint { Clang, GCC, Microsoft, Unknown }; - enum class Platform : uint { Windows, MacOS, Linux, BSD, Android, Unknown }; - enum class API : uint { Windows, Posix, Unknown }; - enum class DisplayServer : uint { Windows, Quartz, Xorg, Unknown }; - enum class Architecture : uint { x86, amd64, ARM32, ARM64, PPC32, PPC64, Unknown }; - enum class Endian : uint { LSB, MSB, Unknown }; - enum class Build : uint { Debug, Stable, Minified, Release, Optimized }; + enum class Compiler : u32 { Clang, GCC, Microsoft, Unknown }; + enum class Platform : u32 { Windows, MacOS, Linux, BSD, Android, Unknown }; + enum class API : u32 { Windows, Posix, Unknown }; + enum class DisplayServer : u32 { Windows, Quartz, Xorg, Unknown }; + enum class Architecture : u32 { x86, amd64, ARM32, ARM64, PPC32, PPC64, Unknown }; + enum class Endian : u32 { LSB, MSB, Unknown }; + enum class Build : u32 { Debug, Stable, Minified, Release, Optimized }; static inline constexpr auto compiler() -> Compiler; static inline constexpr auto platform() -> Platform; @@ -27,7 +27,6 @@ namespace nall { #if defined(__clang__) #define COMPILER_CLANG constexpr auto compiler() -> Compiler { return Compiler::Clang; } - #pragma clang diagnostic warning "-Wreturn-type" #pragma clang diagnostic ignored "-Wunused-result" #pragma clang diagnostic ignored "-Wunknown-pragmas" @@ -39,24 +38,20 @@ namespace nall { #pragma clang diagnostic ignored "-Wabsolute-value" #pragma clang diagnostic ignored "-Wshift-count-overflow" #pragma clang diagnostic ignored "-Wtrigraphs" - - //temporary - #pragma clang diagnostic ignored "-Winconsistent-missing-override" -//#pragma clang diagnostic error "-Wdeprecated-declarations" + #pragma clang diagnostic ignored "-Wnarrowing" #elif defined(__GNUC__) #define COMPILER_GCC constexpr auto compiler() -> Compiler { return Compiler::GCC; } - #pragma GCC diagnostic warning "-Wreturn-type" #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wswitch-bool" #pragma GCC diagnostic ignored "-Wtrigraphs" + #pragma GCC diagnostic ignored "-Wnarrowing" #elif defined(_MSC_VER) #define COMPILER_MICROSOFT constexpr auto compiler() -> Compiler { return Compiler::Microsoft; } - #pragma warning(disable:4996) //libc "deprecation" warnings #else #warning "unable to detect compiler" diff --git a/nall/iterator.hpp b/nall/iterator.hpp index 6c2625e9e2..3e45917694 100644 --- a/nall/iterator.hpp +++ b/nall/iterator.hpp @@ -3,57 +3,57 @@ namespace nall { template struct iterator { - iterator(T* self, uint64_t offset) : _self(self), _offset(offset) {} + iterator(T* self, u64 offset) : _self(self), _offset(offset) {} auto operator*() -> T& { return _self[_offset]; } auto operator!=(const iterator& source) const -> bool { return _offset != source._offset; } auto operator++() -> iterator& { return _offset++, *this; } - auto offset() const -> uint64_t { return _offset; } + auto offset() const -> u64 { return _offset; } private: T* _self; - uint64_t _offset; + u64 _offset; }; template struct iterator_const { - iterator_const(const T* self, uint64_t offset) : _self(self), _offset(offset) {} + iterator_const(const T* self, u64 offset) : _self(self), _offset(offset) {} auto operator*() -> const T& { return _self[_offset]; } auto operator!=(const iterator_const& source) const -> bool { return _offset != source._offset; } auto operator++() -> iterator_const& { return _offset++, *this; } - auto offset() const -> uint64_t { return _offset; } + auto offset() const -> u64 { return _offset; } private: const T* _self; - uint64_t _offset; + u64 _offset; }; template struct reverse_iterator { - reverse_iterator(T* self, uint64_t offset) : _self(self), _offset(offset) {} + reverse_iterator(T* self, u64 offset) : _self(self), _offset(offset) {} auto operator*() -> T& { return _self[_offset]; } auto operator!=(const reverse_iterator& source) const -> bool { return _offset != source._offset; } auto operator++() -> reverse_iterator& { return _offset--, *this; } - auto offset() const -> uint64_t { return _offset; } + auto offset() const -> u64 { return _offset; } private: T* _self; - uint64_t _offset; + u64 _offset; }; template struct reverse_iterator_const { - reverse_iterator_const(const T* self, uint64_t offset) : _self(self), _offset(offset) {} + reverse_iterator_const(const T* self, u64 offset) : _self(self), _offset(offset) {} auto operator*() -> const T& { return _self[_offset]; } auto operator!=(const reverse_iterator_const& source) const -> bool { return _offset != source._offset; } auto operator++() -> reverse_iterator_const& { return _offset--, *this; } - auto offset() const -> uint64_t { return _offset; } + auto offset() const -> u64 { return _offset; } private: const T* _self; - uint64_t _offset; + u64 _offset; }; //std::rbegin(), std::rend() is missing from GCC 4.9; which I still target -template auto rbegin(T (&array)[Size]) { return reverse_iterator{array, Size - 1}; } -template auto rend(T (&array)[Size]) { return reverse_iterator{array, (uint64_t)-1}; } +template auto rbegin(T (&array)[Size]) { return reverse_iterator{array, Size - 1}; } +template auto rend(T (&array)[Size]) { return reverse_iterator{array, (u64)-1}; } template auto rbegin(T& self) { return self.rbegin(); } template auto rend(T& self) { return self.rend(); } diff --git a/nall/locale.hpp b/nall/locale.hpp index 6fb9f173e8..7d8ca73ea2 100644 --- a/nall/locale.hpp +++ b/nall/locale.hpp @@ -55,7 +55,7 @@ struct Locale { } } } - for(uint index : range(arguments.size())) { + for(u32 index : range(arguments.size())) { input.replace({"{", index, "}"}, arguments[index]); } return input; diff --git a/nall/location.hpp b/nall/location.hpp index 7aeb8b07db..b525620955 100644 --- a/nall/location.hpp +++ b/nall/location.hpp @@ -8,7 +8,7 @@ namespace nall::Location { // (/parent/child.type/)name.type inline auto path(string_view self) -> string { const char* p = self.data() + self.size() - 1; - for(int offset = self.size() - 1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1; offset >= 0; offset--, p--) { if(*p == '/') return slice(self, 0, offset + 1); } return ""; //no path found @@ -18,7 +18,7 @@ inline auto path(string_view self) -> string { // /parent/child.type/(name.type) inline auto file(string_view self) -> string { const char* p = self.data() + self.size() - 1; - for(int offset = self.size() - 1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1; offset >= 0; offset--, p--) { if(*p == '/') return slice(self, offset + 1); } return self; //no path found @@ -28,7 +28,7 @@ inline auto file(string_view self) -> string { // (/parent/child.type/)name.type inline auto dir(string_view self) -> string { const char* p = self.data() + self.size() - 1, *last = p; - for(int offset = self.size() - 1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1; offset >= 0; offset--, p--) { if(*p == '/' && p == last) continue; if(*p == '/') return slice(self, 0, offset + 1); } @@ -39,7 +39,7 @@ inline auto dir(string_view self) -> string { // /parent/child.type/(name.type) inline auto base(string_view self) -> string { const char* p = self.data() + self.size() - 1, *last = p; - for(int offset = self.size() - 1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1; offset >= 0; offset--, p--) { if(*p == '/' && p == last) continue; if(*p == '/') return slice(self, offset + 1); } @@ -50,7 +50,7 @@ inline auto base(string_view self) -> string { // /parent/child.type/(name).type inline auto prefix(string_view self) -> string { const char* p = self.data() + self.size() - 1, *last = p; - for(int offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) { if(*p == '/' && p == last) continue; if(*p == '/') return slice(self, offset + 1, (suffix >= 0 ? suffix : self.size()) - offset - 1).trimRight("/"); if(*p == '.' && suffix == -1) { suffix = offset; continue; } @@ -63,7 +63,7 @@ inline auto prefix(string_view self) -> string { // /parent/child.type/name(.type) inline auto suffix(string_view self) -> string { const char* p = self.data() + self.size() - 1, *last = p; - for(int offset = self.size() - 1; offset >= 0; offset--, p--) { + for(s32 offset = self.size() - 1; offset >= 0; offset--, p--) { if(*p == '/' && p == last) continue; if(*p == '/') break; if(*p == '.') return slice(self, offset).trimRight("/"); diff --git a/nall/mac/poly1305.hpp b/nall/mac/poly1305.hpp index befbf46e7c..fca21c2591 100644 --- a/nall/mac/poly1305.hpp +++ b/nall/mac/poly1305.hpp @@ -5,15 +5,15 @@ namespace nall::MAC { struct Poly1305 { - auto authenticate(array_view memory, uint256_t nonce) -> uint128_t { + auto authenticate(array_view memory, u256 nonce) -> u128 { initialize(nonce); process(memory.data(), memory.size()); return finish(); } - auto initialize(uint256_t key) -> void { - uint64_t t0 = key >> 0; - uint64_t t1 = key >> 64; + auto initialize(u256 key) -> void { + u64 t0 = key >> 0; + u64 t1 = key >> 64; pad[0] = key >> 128; pad[1] = key >> 192; @@ -25,7 +25,7 @@ struct Poly1305 { offset = 0; } - auto process(const uint8_t* data, uint64_t size) -> void { + auto process(const u8* data, u64 size) -> void { while(size--) { buffer[offset++] = *data++; if(offset >= 16) { @@ -35,16 +35,16 @@ struct Poly1305 { } } - auto finish() -> uint128_t { + auto finish() -> u128 { if(offset) { buffer[offset++] = 1; while(offset < 16) buffer[offset++] = 0; block(true); } - uint64_t h0 = h[0], h1 = h[1], h2 = h[2]; + u64 h0 = h[0], h1 = h[1], h2 = h[2]; - uint64_t c = h1 >> 44; h1 &= 0xfffffffffff; + u64 c = h1 >> 44; h1 &= 0xfffffffffff; h2 += c; c = h2 >> 42; h2 &= 0x3ffffffffff; h0 += c * 5; c = h0 >> 44; h0 &= 0xfffffffffff; h1 += c; c = h1 >> 44; h1 &= 0xfffffffffff; @@ -52,9 +52,9 @@ struct Poly1305 { h0 += c * 5; c = h0 >> 44; h0 &= 0xfffffffffff; h1 += c; - uint64_t g0 = h0 + 5; c = g0 >> 44; g0 &= 0xfffffffffff; - uint64_t g1 = h1 + c; c = g1 >> 44; g1 &= 0xfffffffffff; - uint64_t g2 = h2 + c - (1ull << 42); + u64 g0 = h0 + 5; c = g0 >> 44; g0 &= 0xfffffffffff; + u64 g1 = h1 + c; c = g1 >> 44; g1 &= 0xfffffffffff; + u64 g2 = h2 + c - (1ull << 42); c = (g2 >> 63) - 1; g0 &= c, g1 &= c, g2 &= c; @@ -63,7 +63,7 @@ struct Poly1305 { h1 = (h1 & c) | g1; h2 = (h2 & c) | g2; - uint64_t t0 = pad[0], t1 = pad[1]; + u64 t0 = pad[0], t1 = pad[1]; h0 += ((t0 ) & 0xfffffffffff) ; c = h0 >> 44; h0 &= 0xfffffffffff; h1 += ((t0 >> 44 | t1 << 20) & 0xfffffffffff) + c; c = h1 >> 44; h1 &= 0xfffffffffff; @@ -78,32 +78,32 @@ struct Poly1305 { memory::fill(buffer, sizeof(buffer)); offset = 0; - return uint128_t(h1) << 64 | h0; + return u128(h1) << 64 | h0; } private: auto block(bool last = false) -> void { - uint64_t r0 = r[0], r1 = r[1], r2 = r[2]; - uint64_t h0 = h[0], h1 = h[1], h2 = h[2]; + u64 r0 = r[0], r1 = r[1], r2 = r[2]; + u64 h0 = h[0], h1 = h[1], h2 = h[2]; - uint64_t s1 = r1 * 20; - uint64_t s2 = r2 * 20; + u64 s1 = r1 * 20; + u64 s2 = r2 * 20; - uint64_t t0 = memory::readl<8>(buffer + 0); - uint64_t t1 = memory::readl<8>(buffer + 8); + u64 t0 = memory::readl<8>(buffer + 0); + u64 t1 = memory::readl<8>(buffer + 8); h0 += ((t0 ) & 0xfffffffffff); h1 += ((t0 >> 44 | t1 << 20) & 0xfffffffffff); h2 += (( t1 >> 24) & 0x3ffffffffff) | (last ? 0 : 1ull << 40); - uint128_t d, d0, d1, d2; - d0 = (uint128_t)h0 * r0; d = (uint128_t)h1 * s2; d0 += d; d = (uint128_t)h2 * s1; d0 += d; - d1 = (uint128_t)h0 * r1; d = (uint128_t)h1 * r0; d1 += d; d = (uint128_t)h2 * s2; d1 += d; - d2 = (uint128_t)h0 * r2; d = (uint128_t)h1 * r1; d2 += d; d = (uint128_t)h2 * r0; d2 += d; + u128 d, d0, d1, d2; + d0 = (u128)h0 * r0; d = (u128)h1 * s2; d0 += d; d = (u128)h2 * s1; d0 += d; + d1 = (u128)h0 * r1; d = (u128)h1 * r0; d1 += d; d = (u128)h2 * s2; d1 += d; + d2 = (u128)h0 * r2; d = (u128)h1 * r1; d2 += d; d = (u128)h2 * r0; d2 += d; - uint64_t c = (uint64_t)(d0 >> 44); h0 = (uint64_t)d0 & 0xfffffffffff; - d1 += c; c = (uint64_t)(d1 >> 44); h1 = (uint64_t)d1 & 0xfffffffffff; - d2 += c; c = (uint64_t)(d2 >> 42); h2 = (uint64_t)d2 & 0x3ffffffffff; + u64 c = (u64)(d0 >> 44); h0 = (u64)d0 & 0xfffffffffff; + d1 += c; c = (u64)(d1 >> 44); h1 = (u64)d1 & 0xfffffffffff; + d2 += c; c = (u64)(d2 >> 42); h2 = (u64)d2 & 0x3ffffffffff; h0 += c * 5; c = h0 >> 44; h0 &= 0xfffffffffff; h1 += c; @@ -111,12 +111,12 @@ struct Poly1305 { h[0] = h0, h[1] = h1, h[2] = h2; } - uint64_t r[3]; - uint64_t h[3]; - uint64_t pad[2]; + u64 r[3]; + u64 h[3]; + u64 pad[2]; - uint8_t buffer[16]; - uint offset; + u8 buffer[16]; + u32 offset; }; } diff --git a/nall/matrix-multiply.hpp b/nall/matrix-multiply.hpp index a82d8ea2cc..9568bb9355 100644 --- a/nall/matrix-multiply.hpp +++ b/nall/matrix-multiply.hpp @@ -7,15 +7,15 @@ namespace nall { template inline auto MatrixMultiply( T* output, -const T* xdata, uint xrows, uint xcols, -const T* ydata, uint yrows, uint ycols +const T* xdata, u32 xrows, u32 xcols, +const T* ydata, u32 yrows, u32 ycols ) -> void { if(xcols != yrows) return; - for(uint y : range(xrows)) { - for(uint x : range(ycols)) { + for(u32 y : range(xrows)) { + for(u32 x : range(ycols)) { T sum = 0; - for(uint z : range(xcols)) { + for(u32 z : range(xcols)) { sum += xdata[y * xcols + z] * ydata[z * ycols + x]; } *output++ = sum; @@ -24,8 +24,8 @@ const T* ydata, uint yrows, uint ycols } template inline auto MatrixMultiply( -const T* xdata, uint xrows, uint xcols, -const T* ydata, uint yrows, uint ycols +const T* xdata, u32 xrows, u32 xcols, +const T* ydata, u32 yrows, u32 ycols ) -> vector { vector output; output.resize(xrows * ycols); diff --git a/nall/matrix.hpp b/nall/matrix.hpp index e266df6a63..3923f2d835 100644 --- a/nall/matrix.hpp +++ b/nall/matrix.hpp @@ -2,14 +2,14 @@ namespace nall { -template +template struct Matrix { static_assert(Rows > 0 && Cols > 0); Matrix() = default; Matrix(const Matrix&) = default; Matrix(const initializer_list& source) { - uint index = 0; + u32 index = 0; for(auto& value : source) { if(index >= Rows * Cols) break; values[index / Cols][index % Cols] = value; @@ -20,18 +20,18 @@ struct Matrix { operator array_view() const { return {values, Rows * Cols}; } //1D matrices (for polynomials, etc) - auto operator[](uint row) -> T& { return values[row][0]; } - auto operator[](uint row) const -> T { return values[row][0]; } + auto operator[](u32 row) -> T& { return values[row][0]; } + auto operator[](u32 row) const -> T { return values[row][0]; } //2D matrices - auto operator()(uint row, uint col) -> T& { return values[row][col]; } - auto operator()(uint row, uint col) const -> T { return values[row][col]; } + auto operator()(u32 row, u32 col) -> T& { return values[row][col]; } + auto operator()(u32 row, u32 col) const -> T { return values[row][col]; } //operators auto operator+() const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = +target(row, col); } } @@ -40,8 +40,8 @@ struct Matrix { auto operator-() const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = -target(row, col); } } @@ -50,8 +50,8 @@ struct Matrix { auto operator+(const Matrix& source) const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = target(row, col) + source(row, col); } } @@ -60,8 +60,8 @@ struct Matrix { auto operator-(const Matrix& source) const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = target(row, col) - source(row, col); } } @@ -70,8 +70,8 @@ struct Matrix { auto operator*(T source) const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = target(row, col) * source; } } @@ -80,8 +80,8 @@ struct Matrix { auto operator/(T source) const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = target(row, col) / source; } } @@ -89,14 +89,14 @@ struct Matrix { } //warning: matrix multiplication is not commutative! - template + template auto operator*(const Matrix& source) const -> Matrix { static_assert(Cols == SourceRows); Matrix result; - for(uint y : range(Rows)) { - for(uint x : range(SourceCols)) { + for(u32 y : range(Rows)) { + for(u32 x : range(SourceCols)) { T sum{}; - for(uint z : range(Cols)) { + for(u32 z : range(Cols)) { sum += target(y, z) * source(z, x); } result(y, x) = sum; @@ -105,7 +105,7 @@ struct Matrix { return result; } - template + template auto operator/(const Matrix& source) const -> maybe> { static_assert(Cols == SourceRows && SourceRows == SourceCols); if(auto inverted = source.invert()) return operator*(inverted()); @@ -116,7 +116,7 @@ struct Matrix { auto& operator-=(const Matrix& source) { return *this = operator-(source); } auto& operator*=(T source) { return *this = operator*(source); } auto& operator/=(T source) { return *this = operator/(source); } - template + template auto& operator*=(const Matrix& source) { return *this = operator*(source); } //matrix division is not always possible (when matrix cannot be inverted), so operator/= is not provided @@ -126,30 +126,30 @@ struct Matrix { Matrix source = *this; Matrix result = identity(); - const auto add = [&](uint targetRow, uint sourceRow, T factor = 1) { - for(uint col : range(Cols)) { + const auto add = [&](u32 targetRow, u32 sourceRow, T factor = 1) { + for(u32 col : range(Cols)) { result(targetRow, col) += result(sourceRow, col) * factor; source(targetRow, col) += source(sourceRow, col) * factor; } }; - const auto sub = [&](uint targetRow, uint sourceRow, T factor = 1) { - for(uint col : range(Cols)) { + const auto sub = [&](u32 targetRow, u32 sourceRow, T factor = 1) { + for(u32 col : range(Cols)) { result(targetRow, col) -= result(sourceRow, col) * factor; source(targetRow, col) -= source(sourceRow, col) * factor; } }; - const auto mul = [&](uint row, T factor) { - for(uint col : range(Cols)) { + const auto mul = [&](u32 row, T factor) { + for(u32 col : range(Cols)) { result(row, col) *= factor; source(row, col) *= factor; } }; - for(uint i : range(Cols)) { + for(u32 i : range(Cols)) { if(source(i, i) == 0) { - for(uint row : range(Rows)) { + for(u32 row : range(Rows)) { if(source(row, i) != 0) { add(i, row); break; @@ -160,7 +160,7 @@ struct Matrix { } mul(i, T{1} / source(i, i)); - for(uint row : range(Rows)) { + for(u32 row : range(Rows)) { if(row == i) continue; sub(row, i, source(row, i)); } @@ -171,8 +171,8 @@ struct Matrix { auto transpose() const -> Matrix { Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(col, row) = target(row, col); } } @@ -182,8 +182,8 @@ struct Matrix { static auto identity() -> Matrix { static_assert(Rows == Cols); Matrix result; - for(uint row : range(Rows)) { - for(uint col : range(Cols)) { + for(u32 row : range(Rows)) { + for(u32 col : range(Cols)) { result(row, col) = row == col; } } @@ -191,11 +191,11 @@ struct Matrix { } //debugging function: do not use in production code - template + template auto _print() const -> void { - for(uint row : range(Rows)) { + for(u32 row : range(Rows)) { nall::print("[ "); - for(uint col : range(Cols)) { + for(u32 col : range(Cols)) { nall::print(pad(target(row, col), Pad, ' '), " "); } nall::print("]\n"); @@ -204,8 +204,8 @@ struct Matrix { protected: //same as operator(), but with easier to read syntax inside Matrix class - auto target(uint row, uint col) -> T& { return values[row][col]; } - auto target(uint row, uint col) const -> T { return values[row][col]; } + auto target(u32 row, u32 col) -> T& { return values[row][col]; } + auto target(u32 row, u32 col) const -> T { return values[row][col]; } T values[Rows][Cols]{}; }; diff --git a/nall/memory.hpp b/nall/memory.hpp index 7537785abb..3e6a933f98 100644 --- a/nall/memory.hpp +++ b/nall/memory.hpp @@ -4,35 +4,33 @@ #include namespace nall::memory { - template auto allocate(uint size) -> T*; - template auto allocate(uint size, const T& value) -> T*; + template auto allocate(u32 size) -> T*; + template auto allocate(u32 size, const T& value) -> T*; + template auto resize(void* target, u32 size) -> T*; + template auto free(void* target) -> void; - template auto resize(void* target, uint size) -> T*; + template auto compare(const void* target, u32 capacity, const void* source, u32 size) -> s32; + template auto compare(const void* target, const void* source, u32 size) -> s32; - auto free(void* target) -> void; + template auto icompare(const void* target, u32 capacity, const void* source, u32 size) -> s32; + template auto icompare(const void* target, const void* source, u32 size) -> s32; - template auto compare(const void* target, uint capacity, const void* source, uint size) -> int; - template auto compare(const void* target, const void* source, uint size) -> int; + template auto copy(void* target, u32 capacity, const void* source, u32 size) -> T*; + template auto copy(void* target, const void* source, u32 size) -> T*; - template auto icompare(const void* target, uint capacity, const void* source, uint size) -> int; - template auto icompare(const void* target, const void* source, uint size) -> int; + template auto move(void* target, u32 capacity, const void* source, u32 size) -> T*; + template auto move(void* target, const void* source, u32 size) -> T*; - template auto copy(void* target, uint capacity, const void* source, uint size) -> T*; - template auto copy(void* target, const void* source, uint size) -> T*; - - template auto move(void* target, uint capacity, const void* source, uint size) -> T*; - template auto move(void* target, const void* source, uint size) -> T*; - - template auto fill(void* target, uint capacity, const T& value = {}) -> T*; + template auto fill(void* target, u32 capacity, const T& value = {}) -> T*; template auto assign(T* target) -> void {} template auto assign(T* target, const U& value, P&&... p) -> void; - template auto readl(const void* source) -> T; - template auto readm(const void* source) -> T; + template auto readl(const void* source) -> T; + template auto readm(const void* source) -> T; - template auto writel(void* target, T data) -> void; - template auto writem(void* target, T data) -> void; + template auto writel(void* target, T data) -> void; + template auto writem(void* target, T data) -> void; } namespace nall::memory { @@ -42,27 +40,59 @@ namespace nall::memory { //as this library is used extensively by nall/string, and most strings tend to be small, //this library hand-codes these functions instead. surprisingly, it's a substantial speedup -template auto allocate(uint size) -> T* { +template auto allocate(u32 size) -> T* { + if constexpr(Align == 0) { + return (T*)malloc(size * sizeof(T)); + } + #if defined(API_WINDOWS) + return (T*)_aligned_malloc(size * sizeof(T), Align); + #elif defined(API_POSIX) + T* result = nullptr; + posix_memalign((void**)&result, Align, size * sizeof(T)); + return result; + #else return (T*)malloc(size * sizeof(T)); + #endif } -template auto allocate(uint size, const T& value) -> T* { - auto result = allocate(size); +template auto allocate(u32 size, const T& value) -> T* { + auto result = allocate(size); if(result) fill(result, size, value); return result; } -template auto resize(void* target, uint size) -> T* { +template auto resize(void* target, u32 size) -> T* { + if constexpr(Align == 0) { + return (T*)realloc(target, size * sizeof(T)); + } + #if defined(API_WINDOWS) + return (T*)_aligned_realloc(target, size * sizeof(T), Align); + #elif defined(API_POSIX) + //realloc() cannot be used safely with posix_memalign(); a copy is always required + T* result = allocate(size); + copy(result, target, size); + free(target); + return result; + #else return (T*)realloc(target, size * sizeof(T)); + #endif } -inline auto free(void* target) -> void { +template auto free(void* target) -> void { + if constexpr(Align == 0) { + ::free(target); + return; + } + #if defined(API_WINDOWS) + _aligned_free(target); + #else ::free(target); + #endif } -template auto compare(const void* target, uint capacity, const void* source, uint size) -> int { - auto t = (uint8_t*)target; - auto s = (uint8_t*)source; +template auto compare(const void* target, u32 capacity, const void* source, u32 size) -> s32 { + auto t = (u8*)target; + auto s = (u8*)source; auto l = min(capacity, size) * sizeof(T); while(l--) { auto x = *t++; @@ -73,13 +103,13 @@ template auto compare(const void* target, uint capacity, const void* return -(capacity < size); } -template auto compare(const void* target, const void* source, uint size) -> int { +template auto compare(const void* target, const void* source, u32 size) -> s32 { return compare(target, size, source, size); } -template auto icompare(const void* target, uint capacity, const void* source, uint size) -> int { - auto t = (uint8_t*)target; - auto s = (uint8_t*)source; +template auto icompare(const void* target, u32 capacity, const void* source, u32 size) -> s32 { + auto t = (u8*)target; + auto s = (u8*)source; auto l = min(capacity, size) * sizeof(T); while(l--) { auto x = *t++; @@ -91,25 +121,25 @@ template auto icompare(const void* target, uint capacity, const void return -(capacity < size); } -template auto icompare(const void* target, const void* source, uint size) -> int { +template auto icompare(const void* target, const void* source, u32 size) -> s32 { return icompare(target, size, source, size); } -template auto copy(void* target, uint capacity, const void* source, uint size) -> T* { - auto t = (uint8_t*)target; - auto s = (uint8_t*)source; +template auto copy(void* target, u32 capacity, const void* source, u32 size) -> T* { + auto t = (u8*)target; + auto s = (u8*)source; auto l = min(capacity, size) * sizeof(T); while(l--) *t++ = *s++; return (T*)target; } -template auto copy(void* target, const void* source, uint size) -> T* { +template auto copy(void* target, const void* source, u32 size) -> T* { return copy(target, size, source, size); } -template auto move(void* target, uint capacity, const void* source, uint size) -> T* { - auto t = (uint8_t*)target; - auto s = (uint8_t*)source; +template auto move(void* target, u32 capacity, const void* source, u32 size) -> T* { + auto t = (u8*)target; + auto s = (u8*)source; auto l = min(capacity, size) * sizeof(T); if(t < s) { while(l--) *t++ = *s++; @@ -121,11 +151,11 @@ template auto move(void* target, uint capacity, const void* source, return (T*)target; } -template auto move(void* target, const void* source, uint size) -> T* { +template auto move(void* target, const void* source, u32 size) -> T* { return move(target, size, source, size); } -template auto fill(void* target, uint capacity, const T& value) -> T* { +template auto fill(void* target, u32 capacity, const T& value) -> T* { auto t = (T*)target; while(capacity--) *t++ = value; return (T*)target; @@ -136,28 +166,28 @@ template auto assign(T* target, const U& assign(target, forward

(p)...); } -template auto readl(const void* source) -> T { - auto p = (const uint8_t*)source; +template auto readl(const void* source) -> T { + auto p = (const u8*)source; T data = 0; - for(uint n = 0; n < size; n++) data |= T(*p++) << n * 8; + for(u32 n = 0; n < size; n++) data |= T(*p++) << n * 8; return data; } -template auto readm(const void* source) -> T { - auto p = (const uint8_t*)source; +template auto readm(const void* source) -> T { + auto p = (const u8*)source; T data = 0; - for(int n = size - 1; n >= 0; n--) data |= T(*p++) << n * 8; + for(s32 n = size - 1; n >= 0; n--) data |= T(*p++) << n * 8; return data; } -template auto writel(void* target, T data) -> void { - auto p = (uint8_t*)target; - for(uint n = 0; n < size; n++) *p++ = data >> n * 8; +template auto writel(void* target, T data) -> void { + auto p = (u8*)target; + for(u32 n = 0; n < size; n++) *p++ = data >> n * 8; } -template auto writem(void* target, T data) -> void { - auto p = (uint8_t*)target; - for(int n = size - 1; n >= 0; n--) *p++ = data >> n * 8; +template auto writem(void* target, T data) -> void { + auto p = (u8*)target; + for(s32 n = size - 1; n >= 0; n--) *p++ = data >> n * 8; } } diff --git a/nall/merge-sort.hpp b/nall/merge-sort.hpp index 5c1175b8d7..059fec6925 100644 --- a/nall/merge-sort.hpp +++ b/nall/merge-sort.hpp @@ -21,14 +21,14 @@ namespace nall { -template auto sort(T list[], uint size, const Comparator& lessthan) -> void { +template auto sort(T list[], u32 size, const Comparator& lessthan) -> void { if(size <= 1) return; //nothing to sort //sort smaller blocks using an O(n^2) algorithm (which for small sizes, increases performance) if(size < 64) { //insertion sort requires a copy (via move construction) #if defined(NALL_MERGE_SORT_INSERTION) - for(int i = 1, j; i < size; i++) { + for(s32 i = 1, j; i < size; i++) { T copy(move(list[i])); for(j = i - 1; j >= 0; j--) { if(!lessthan(copy, list[j])) break; @@ -38,9 +38,9 @@ template auto sort(T list[], uint size, const C } //selection sort requires a swap #elif defined(NALL_MERGE_SORT_SELECTION) - for(uint i = 0; i < size; i++) { - uint min = i; - for(uint j = i + 1; j < size; j++) { + for(u32 i = 0; i < size; i++) { + u32 min = i; + for(u32 j = i + 1; j < size; j++) { if(lessthan(list[j], list[min])) min = j; } if(min != i) swap(list[i], list[min]); @@ -50,14 +50,14 @@ template auto sort(T list[], uint size, const C } //split list in half and recursively sort both - uint middle = size / 2; + u32 middle = size / 2; sort(list, middle, lessthan); sort(list + middle, size - middle, lessthan); //left and right are sorted here; perform merge sort //use placement new to avoid needing T to be default-constructable auto buffer = memory::allocate(size); - uint offset = 0, left = 0, right = middle; + u32 offset = 0, left = 0, right = middle; while(left < middle && right < size) { if(!lessthan(list[right], list[left])) { new(buffer + offset++) T(move(list[left++])); @@ -68,14 +68,14 @@ template auto sort(T list[], uint size, const C while(left < middle) new(buffer + offset++) T(move(list[left++])); while(right < size ) new(buffer + offset++) T(move(list[right++])); - for(uint i = 0; i < size; i++) { + for(u32 i = 0; i < size; i++) { list[i] = move(buffer[i]); buffer[i].~T(); } memory::free(buffer); } -template auto sort(T list[], uint size) -> void { +template auto sort(T list[], u32 size) -> void { return sort(list, size, [](const T& l, const T& r) { return l < r; }); } diff --git a/nall/platform.hpp b/nall/platform.hpp index 14d61cb0c6..1dd99c1ab6 100644 --- a/nall/platform.hpp +++ b/nall/platform.hpp @@ -116,30 +116,30 @@ namespace Math { #define bswap32(value) __builtin_bswap32(value) #define bswap64(value) __builtin_bswap64(value) #if defined(__SIZEOF_INT128__) - inline auto bswap128(uint128_t value) -> uint128_t { + inline auto bswap128(u128 value) -> u128 { #if defined(__SSSE3__) static const __m128i shuffle = _mm_setr_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - return reinterpret_cast(_mm_shuffle_epi8(reinterpret_cast<__m128i>(value), shuffle)); + return reinterpret_cast(_mm_shuffle_epi8(reinterpret_cast<__m128i>(value), shuffle)); #else - return (uint128_t)__builtin_bswap64(value) << 64 | __builtin_bswap64(value >> 64); + return (u128)__builtin_bswap64(value) << 64 | __builtin_bswap64(value >> 64); #endif } #endif #define likely(expression) __builtin_expect(bool(expression), true) #define unlikely(expression) __builtin_expect(bool(expression), false) #else - inline auto bswap16(uint16_t value) -> uint16_t { + inline auto bswap16(u16 value) -> u16 { return value << 8 | value >> 8; } - inline auto bswap32(uint32_t value) -> uint32_t { - return (uint32_t)bswap16(value) << 16 | bswap16(value >> 16); + inline auto bswap32(u32 value) -> u32 { + return (u32)bswap16(value) << 16 | bswap16(value >> 16); } - inline auto bswap64(uint64_t value) -> uint64_t { - return (uint64_t)bswap32(value) << 32 | bswap32(value >> 32); + inline auto bswap64(u64 value) -> u64 { + return (u64)bswap32(value) << 32 | bswap32(value >> 32); } #if defined(__SIZEOF_INT128__) - inline auto bswap128(uint128_t value) -> uint128_t { - return (uint128_t)bswap64(value) << 64 | bswap64(value >> 64); + inline auto bswap128(u128 value) -> u128 { + return (u128)bswap64(value) << 64 | bswap64(value >> 64); } #endif #define likely(expression) expression diff --git a/nall/posix/shared-memory.hpp b/nall/posix/shared-memory.hpp index 5a4a375fde..cbad592508 100644 --- a/nall/posix/shared-memory.hpp +++ b/nall/posix/shared-memory.hpp @@ -18,7 +18,7 @@ struct shared_memory { return _mode != mode::inactive; } - auto size() const -> uint { + auto size() const -> u32 { return _size; } @@ -26,7 +26,7 @@ struct shared_memory { return _acquired; } - auto acquire() -> uint8_t* { + auto acquire() -> u8* { if(!acquired()) { sem_wait(_semaphore); _acquired = true; @@ -47,7 +47,7 @@ struct shared_memory { if(_mode == mode::client) return close(); } - auto create(const string& name, uint size) -> bool { + auto create(const string& name, u32 size) -> bool { reset(); _name = {"/nall-", string{name}.transform("/:", "--")}; @@ -62,7 +62,7 @@ struct shared_memory { if(ftruncate(_descriptor, _size) != 0) return remove(), false; - _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); + _data = (u8*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); if(_data == MAP_FAILED) return remove(), false; memory::fill(_data, _size); @@ -94,7 +94,7 @@ struct shared_memory { _size = 0; } - auto open(const string& name, uint size) -> bool { + auto open(const string& name, u32 size) -> bool { reset(); _name = {"/nall-", string{name}.transform("/:", "--")}; @@ -106,7 +106,7 @@ struct shared_memory { _descriptor = shm_open(_name, O_RDWR, 0644); if(_descriptor < 0) return close(), false; - _data = (uint8_t*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); + _data = (u8*)mmap(nullptr, _size, PROT_READ | PROT_WRITE, MAP_SHARED, _descriptor, 0); if(_data == MAP_FAILED) return close(), false; _mode = mode::client; @@ -135,12 +135,12 @@ struct shared_memory { } private: - enum class mode : uint { server, client, inactive } _mode = mode::inactive; + enum class mode : u32 { server, client, inactive } _mode = mode::inactive; string _name; sem_t* _semaphore = nullptr; - int _descriptor = -1; - uint8_t* _data = nullptr; - uint _size = 0; + s32 _descriptor = -1; + u8* _data = nullptr; + u32 _size = 0; bool _acquired = false; }; diff --git a/nall/primitives.hpp b/nall/primitives.hpp index fd81129eba..0c7065911d 100644 --- a/nall/primitives.hpp +++ b/nall/primitives.hpp @@ -6,9 +6,9 @@ namespace nall { struct Boolean; - template struct Natural; - template struct Integer; - template struct Real; + template struct Natural; + template struct Integer; + template struct Real; } #include diff --git a/nall/primitives/bit-field.hpp b/nall/primitives/bit-field.hpp index 624876c7a8..d2bd0d667d 100644 --- a/nall/primitives/bit-field.hpp +++ b/nall/primitives/bit-field.hpp @@ -2,19 +2,19 @@ namespace nall { -template struct BitField; +template struct BitField; /* static BitField */ -template struct BitField { +template struct BitField { static_assert(Precision >= 1 && Precision <= 64); using type = - conditional_t>>>; - enum : uint { shift = Index < 0 ? Precision + Index : Index }; + enum : u32 { shift = Index < 0 ? Precision + Index : Index }; enum : type { mask = 1ull << shift }; BitField(const BitField&) = delete; @@ -62,13 +62,13 @@ template struct BitField { /* dynamic BitField */ -template struct BitField { +template struct BitField { static_assert(Precision >= 1 && Precision <= 64); using type = - conditional_t>>>; BitField(const BitField&) = delete; @@ -78,7 +78,7 @@ template struct BitField { return *this; } - template BitField(T* source, int index) : target((type&)*source) { + template BitField(T* source, s32 index) : target((type&)*source) { static_assert(sizeof(T) == sizeof(type)); if(index < 0) index = Precision + index; mask = 1ull << index; @@ -116,7 +116,7 @@ template struct BitField { private: type& target; type mask; - uint shift; + u32 shift; }; } diff --git a/nall/primitives/bit-range.hpp b/nall/primitives/bit-range.hpp index 0c95becd97..bb83b59a30 100644 --- a/nall/primitives/bit-range.hpp +++ b/nall/primitives/bit-range.hpp @@ -4,20 +4,20 @@ namespace nall { /* static BitRange */ -template struct BitRange { +template struct BitRange { static_assert(Precision >= 1 && Precision <= 64); static_assert(Lo < Precision && Hi < Precision); static_assert(Lo <= Hi); using type = - conditional_t>>>; - enum : uint { lo = Lo < 0 ? Precision + Lo : Lo }; - enum : uint { hi = Hi < 0 ? Precision + Hi : Hi }; + enum : u32 { lo = Lo < 0 ? Precision + Lo : Lo }; + enum : u32 { hi = Hi < 0 ? Precision + Hi : Hi }; enum : type { mask = ~0ull >> 64 - (hi - lo + 1) << lo }; - enum : uint { shift = lo }; + enum : u32 { shift = lo }; BitRange(const BitRange& source) = delete; @@ -34,13 +34,13 @@ template struct BitRange { return (target & mask) >> shift; } - auto operator++(int) { + auto operator++(s32) { auto value = (target & mask) >> shift; target = target & ~mask | target + (1 << shift) & mask; return value; } - auto operator--(int) { + auto operator--(s32) { auto value = (target & mask) >> shift; target = target & ~mask | target - (1 << shift) & mask; return value; @@ -124,13 +124,13 @@ template struct BitRange { /* dynamic BitRange */ -template struct DynamicBitRange { +template struct DynamicBitRange { static_assert(Precision >= 1 && Precision <= 64); using type = - conditional_t>>>; DynamicBitRange(const DynamicBitRange& source) = delete; @@ -140,13 +140,13 @@ template struct DynamicBitRange { return *this; } - DynamicBitRange(Type& source, int index) : target(source) { + DynamicBitRange(Type& source, s32 index) : target(source) { if(index < 0) index = Precision + index; mask = 1ull << index; shift = index; } - DynamicBitRange(Type& source, int lo, int hi) : target(source) { + DynamicBitRange(Type& source, s32 lo, s32 hi) : target(source) { if(lo < 0) lo = Precision + lo; if(hi < 0) hi = Precision + hi; if(lo > hi) swap(lo, hi); @@ -158,13 +158,13 @@ template struct DynamicBitRange { return (target & mask) >> shift; } - auto operator++(int) { + auto operator++(s32) { auto value = (target & mask) >> shift; target = target & ~mask | target + (1 << shift) & mask; return value; } - auto operator--(int) { + auto operator--(s32) { auto value = (target & mask) >> shift; target = target & ~mask | target - (1 << shift) & mask; return value; @@ -245,7 +245,7 @@ template struct DynamicBitRange { private: Type& target; type mask; - uint shift; + u32 shift; }; } diff --git a/nall/primitives/boolean.hpp b/nall/primitives/boolean.hpp index 3d92e51a5b..b651177ae2 100644 --- a/nall/primitives/boolean.hpp +++ b/nall/primitives/boolean.hpp @@ -3,7 +3,7 @@ namespace nall { struct Boolean { - static constexpr auto bits() -> uint { return 1; } + static constexpr auto bits() -> u32 { return 1; } using btype = bool; Boolean() : data(false) {} diff --git a/nall/primitives/integer.hpp b/nall/primitives/integer.hpp index dfc85803d9..4ced0c4cb3 100644 --- a/nall/primitives/integer.hpp +++ b/nall/primitives/integer.hpp @@ -2,28 +2,28 @@ namespace nall { -template struct Integer { +template struct Integer { static_assert(Precision >= 1 && Precision <= 64); - static constexpr auto bits() -> uint { return Precision; } + static constexpr auto bits() -> u32 { return Precision; } using stype = - conditional_t>>>; using utype = typename Natural::utype; static constexpr auto mask() -> utype { return ~0ull >> 64 - Precision; } static constexpr auto sign() -> utype { return 1ull << Precision - 1; } Integer() : data(0) {} - template Integer(Integer value) { data = cast(value); } + template Integer(Integer value) { data = cast(value); } template Integer(const T& value) { data = cast(value); } explicit Integer(const char* value) { data = cast(toInteger(value)); } operator stype() const { return data; } - auto operator++(int) { auto value = *this; data = cast(data + 1); return value; } - auto operator--(int) { auto value = *this; data = cast(data - 1); return value; } + auto operator++(s32) { auto value = *this; data = cast(data + 1); return value; } + auto operator--(s32) { auto value = *this; data = cast(data - 1); return value; } auto& operator++() { data = cast(data + 1); return *this; } auto& operator--() { data = cast(data - 1); return *this; } @@ -40,35 +40,35 @@ template struct Integer { template auto& operator ^=(const T& value) { data = cast(data ^ value); return *this; } template auto& operator |=(const T& value) { data = cast(data | value); return *this; } - auto bit(int index) -> DynamicBitRange { return {*this, index}; } - auto bit(int index) const -> const DynamicBitRange { return {(Integer&)*this, index}; } + auto bit(s32 index) -> DynamicBitRange { return {*this, index}; } + auto bit(s32 index) const -> const DynamicBitRange { return {(Integer&)*this, index}; } - auto bit(int lo, int hi) -> DynamicBitRange { return {*this, lo, hi}; } - auto bit(int lo, int hi) const -> const DynamicBitRange { return {(Integer&)*this, lo, hi}; } + auto bit(s32 lo, s32 hi) -> DynamicBitRange { return {*this, lo, hi}; } + auto bit(s32 lo, s32 hi) const -> const DynamicBitRange { return {(Integer&)*this, lo, hi}; } - auto byte(int index) -> DynamicBitRange { return {*this, index * 8 + 0, index * 8 + 7}; } - auto byte(int index) const -> const DynamicBitRange { return {(Integer&)*this, index * 8 + 0, index * 8 + 7}; } + auto byte(s32 index) -> DynamicBitRange { return {*this, index * 8 + 0, index * 8 + 7}; } + auto byte(s32 index) const -> const DynamicBitRange { return {(Integer&)*this, index * 8 + 0, index * 8 + 7}; } - auto mask(int index) const -> utype { + auto mask(s32 index) const -> utype { return data & 1 << index; } - auto mask(int lo, int hi) const -> utype { + auto mask(s32 lo, s32 hi) const -> utype { return data & (~0ull >> 64 - (hi - lo + 1) << lo); } - auto slice(int index) const { return Natural<>{bit(index)}; } - auto slice(int lo, int hi) const { return Natural<>{bit(lo, hi)}; } + auto slice(s32 index) const { return Natural<>{bit(index)}; } + auto slice(s32 lo, s32 hi) const { return Natural<>{bit(lo, hi)}; } - auto clamp(uint bits) -> stype { - const int64_t b = 1ull << bits - 1; - const int64_t m = b - 1; - return data > m ? m : data < -b ? -b : data; + static auto clamp(s64 value) -> stype { + constexpr s64 b = 1ull << bits() - 1; + constexpr s64 m = b - 1; + return value > m ? m : value < -b ? -b : value; } - auto clip(uint bits) -> stype { - const uint64_t b = 1ull << bits - 1; - const uint64_t m = b * 2 - 1; + auto clip(u32 bits) -> stype { + const u64 b = 1ull << bits - 1; + const u64 m = b * 2 - 1; return (data & m ^ b) - b; } diff --git a/nall/primitives/natural.hpp b/nall/primitives/natural.hpp index 3af3f5aa2c..53302e487c 100644 --- a/nall/primitives/natural.hpp +++ b/nall/primitives/natural.hpp @@ -2,26 +2,26 @@ namespace nall { -template struct Natural { +template struct Natural { static_assert(Precision >= 1 && Precision <= 64); - static constexpr auto bits() -> uint { return Precision; } + static constexpr auto bits() -> u32 { return Precision; } using utype = - conditional_t>>>; static constexpr auto mask() -> utype { return ~0ull >> 64 - Precision; } Natural() : data(0) {} - template Natural(Natural value) { data = cast(value); } + template Natural(Natural value) { data = cast(value); } template Natural(const T& value) { data = cast(value); } explicit Natural(const char* value) { data = cast(toNatural(value)); } operator utype() const { return data; } - auto operator++(int) { auto value = *this; data = cast(data + 1); return value; } - auto operator--(int) { auto value = *this; data = cast(data - 1); return value; } + auto operator++(s32) { auto value = *this; data = cast(data + 1); return value; } + auto operator--(s32) { auto value = *this; data = cast(data - 1); return value; } auto& operator++() { data = cast(data + 1); return *this; } auto& operator--() { data = cast(data - 1); return *this; } @@ -38,35 +38,35 @@ template struct Natural { template auto& operator ^=(const T& value) { data = cast(data ^ value); return *this; } template auto& operator |=(const T& value) { data = cast(data | value); return *this; } - auto bit(int index) -> DynamicBitRange { return {*this, index}; } - auto bit(int index) const -> const DynamicBitRange { return {(Natural&)*this, index}; } + auto bit(s32 index) -> DynamicBitRange { return {*this, index}; } + auto bit(s32 index) const -> const DynamicBitRange { return {(Natural&)*this, index}; } - auto bit(int lo, int hi) -> DynamicBitRange { return {*this, lo, hi}; } - auto bit(int lo, int hi) const -> const DynamicBitRange { return {(Natural&)*this, lo, hi}; } + auto bit(s32 lo, s32 hi) -> DynamicBitRange { return {*this, lo, hi}; } + auto bit(s32 lo, s32 hi) const -> const DynamicBitRange { return {(Natural&)*this, lo, hi}; } - auto byte(int index) -> DynamicBitRange { return {*this, index * 8 + 0, index * 8 + 7}; } - auto byte(int index) const -> const DynamicBitRange { return {(Natural&)*this, index * 8 + 0, index * 8 + 7}; } + auto byte(s32 index) -> DynamicBitRange { return {*this, index * 8 + 0, index * 8 + 7}; } + auto byte(s32 index) const -> const DynamicBitRange { return {(Natural&)*this, index * 8 + 0, index * 8 + 7}; } - auto mask(int index) const -> utype { + auto mask(s32 index) const -> utype { return data & 1 << index; } - auto mask(int lo, int hi) const -> utype { + auto mask(s32 lo, s32 hi) const -> utype { return data & (~0ull >> 64 - (hi - lo + 1) << lo); } - auto slice(int index) const { return Natural<>{bit(index)}; } - auto slice(int lo, int hi) const { return Natural<>{bit(lo, hi)}; } + auto slice(s32 index) const { return Natural<>{bit(index)}; } + auto slice(s32 lo, s32 hi) const { return Natural<>{bit(lo, hi)}; } - auto clamp(uint bits) -> utype { - const uint64_t b = 1ull << bits - 1; - const uint64_t m = b * 2 - 1; - return data < m ? data : m; + static auto clamp(u64 value) -> utype { + constexpr u64 b = 1ull << bits() - 1; + constexpr u64 m = b * 2 - 1; + return value < m ? value : m; } - auto clip(uint bits) -> utype { - const uint64_t b = 1ull << bits - 1; - const uint64_t m = b * 2 - 1; + auto clip(u32 bits) -> utype { + const u64 b = 1ull << bits - 1; + const u64 m = b * 2 - 1; return data & m; } diff --git a/nall/primitives/real.hpp b/nall/primitives/real.hpp index d5058f1b75..d41f86238e 100644 --- a/nall/primitives/real.hpp +++ b/nall/primitives/real.hpp @@ -2,23 +2,23 @@ namespace nall { -template struct Real { +template struct Real { static_assert(Precision == 32 || Precision == 64); - static constexpr auto bits() -> uint { return Precision; } + static constexpr auto bits() -> u32 { return Precision; } using ftype = - conditional_t>; Real() : data(0.0) {} - template Real(Real value) : data((ftype)value) {} + template Real(Real value) : data((ftype)value) {} template Real(const T& value) : data((ftype)value) {} explicit Real(const char* value) : data((ftype)toReal(value)) {} operator ftype() const { return data; } - auto operator++(int) { auto value = *this; ++data; return value; } - auto operator--(int) { auto value = *this; --data; return value; } + auto operator++(s32) { auto value = *this; ++data; return value; } + auto operator--(s32) { auto value = *this; --data; return value; } auto& operator++() { data++; return *this; } auto& operator--() { data--; return *this; } diff --git a/nall/queue/spsc.hpp b/nall/queue/spsc.hpp index 6201729d92..e7a237b47b 100644 --- a/nall/queue/spsc.hpp +++ b/nall/queue/spsc.hpp @@ -7,14 +7,14 @@ namespace nall { template struct queue_spsc; -template +template struct queue_spsc { auto flush() -> void { _read = 0; _write = 2 * Size; } - auto size() const -> uint { + auto size() const -> u32 { return (_write - _read) % (2 * Size); } @@ -59,8 +59,8 @@ struct queue_spsc { private: T _data[Size]; - std::atomic _read = 0; - std::atomic _write = 2 * Size; + std::atomic _read = 0; + std::atomic _write = 2 * Size; }; } diff --git a/nall/queue/st.hpp b/nall/queue/st.hpp index 46f3ea7e6c..114a2db515 100644 --- a/nall/queue/st.hpp +++ b/nall/queue/st.hpp @@ -1,23 +1,23 @@ #pragma once -//simple circular ring buffer +//simple circular ring buffer (single-threaded) namespace nall { template struct queue; -template +template struct queue { auto flush() -> void { _read = 0; _write = 2 * Size; } - auto size() const -> uint { + auto size() const -> u32 { return (_write - _read) % (2 * Size); } - auto capacity() const -> uint { + auto capacity() const -> u32 { return Size; } @@ -29,7 +29,7 @@ struct queue { return size() == Size; } - auto peek(uint index) const -> T { + auto peek(u32 index) const -> T { return _data[(_read + index) % Size]; } @@ -62,8 +62,8 @@ struct queue { private: T _data[Size]; - uint _read = 0; - uint _write = 2 * Size; + u32 _read = 0; + u32 _write = 2 * Size; }; template @@ -81,7 +81,7 @@ struct queue { _size = source._size; _read = source._read; _write = source._write; - for(uint n : range(_capacity)) _data[n] = source._data[n]; + for(u32 n : range(_capacity)) _data[n] = source._data[n]; return *this; } @@ -97,13 +97,13 @@ struct queue { return *this; } - template auto capacity() const -> uint { return _capacity * sizeof(T) / sizeof(U); } - template auto size() const -> uint { return _size * sizeof(T) / sizeof(U); } + template auto capacity() const -> u32 { return _capacity * sizeof(T) / sizeof(U); } + template auto size() const -> u32 { return _size * sizeof(T) / sizeof(U); } auto empty() const -> bool { return _size == 0; } auto pending() const -> bool { return _size > 0; } - auto full() const -> bool { return _size >= (int)_capacity; } + auto full() const -> bool { return _size >= (s32)_capacity; } auto underflow() const -> bool { return _size < 0; } - auto overflow() const -> bool { return _size > (int)_capacity; } + auto overflow() const -> bool { return _size > (s32)_capacity; } auto data() -> T* { return _data; } auto data() const -> const T* { return _data; } @@ -117,14 +117,14 @@ struct queue { _write = 0; } - auto resize(uint capacity, const T& value = {}) -> void { + auto resize(u32 capacity, const T& value = {}) -> void { delete[] _data; _data = new T[capacity]; _capacity = capacity; _size = 0; _read = 0; _write = 0; - for(uint n : range(_capacity)) _data[n] = value; + for(u32 n : range(_capacity)) _data[n] = value; } auto flush() -> void { @@ -137,10 +137,10 @@ struct queue { _size = 0; _read = 0; _write = 0; - for(uint n : range(_capacity)) _data[n] = value; + for(u32 n : range(_capacity)) _data[n] = value; } - auto peek(uint index) const -> T { + auto peek(u32 index) const -> T { return _data[(_read + index) % _capacity]; } @@ -165,10 +165,10 @@ struct queue { private: T* _data = nullptr; - uint _capacity = 0; - int _size = 0; - uint _read = 0; - uint _write = 0; + u32 _capacity = 0; + s32 _size = 0; + u32 _read = 0; + u32 _write = 0; }; } diff --git a/nall/random.hpp b/nall/random.hpp index 53e1e0156d..ebb96ade01 100644 --- a/nall/random.hpp +++ b/nall/random.hpp @@ -22,15 +22,15 @@ namespace nall { template struct RNG { - template auto random() -> T { + template auto random() -> T { T value = 0; - for(uint n : range((sizeof(T) + 3) / 4)) { - value = value << 32 | (uint32_t)static_cast(this)->read(); + for(u32 n : range((sizeof(T) + 3) / 4)) { + value = value << 32 | (u32)static_cast(this)->read(); } return value; } - template auto bound(T range) -> T { + template auto bound(T range) -> T { T threshold = -range % range; while(true) { T value = random(); @@ -39,10 +39,10 @@ template struct RNG { } protected: - auto randomSeed() -> uint256_t { - uint256_t seed = 0; + auto randomSeed() -> u256 { + u256 seed = 0; #if defined(PLATFORM_BSD) || defined(PLATFORM_MACOS) - for(uint n : range(8)) seed = seed << 32 | (uint32_t)arc4random(); + for(u32 n : range(8)) seed = seed << 32 | (u32)arc4random(); #elif defined(PLATFORM_LINUX) && __has_include() getrandom(&seed, 32, GRND_NONBLOCK); #elif defined(PLATFORM_ANDROID) && __has_include() @@ -55,7 +55,7 @@ template struct RNG { } #else srand(time(nullptr)); - for(uint n : range(32)) seed = seed << 8 | (uint8_t)rand(); + for(u32 n : range(32)) seed = seed << 8 | (u8)rand(); if(auto fp = fopen("/dev/urandom", "rb")) { fread(&seed, 32, 1, fp); fclose(fp); @@ -71,9 +71,9 @@ namespace PRNG { struct LFSR : RNG { LFSR() { seed(); } - auto seed(maybe seed = {}) -> void { - lfsr = seed ? seed() : (uint64_t)randomSeed(); - for(uint n : range(8)) read(); //hide the CRC64 polynomial from initial output + auto seed(maybe seed = {}) -> void { + lfsr = seed ? seed() : (u64)randomSeed(); + for(u32 n : range(8)) read(); //hide the CRC64 polynomial from initial output } auto serialize(serializer& s) -> void { @@ -81,12 +81,12 @@ struct LFSR : RNG { } private: - auto read() -> uint64_t { + auto read() -> u64 { return lfsr = (lfsr >> 1) ^ (-(lfsr & 1) & crc64); } - static const uint64_t crc64 = 0xc96c'5795'd787'0f42; - uint64_t lfsr = crc64; + static const u64 crc64 = 0xc96c'5795'd787'0f42; + u64 lfsr = crc64; friend class RNG; }; @@ -94,8 +94,8 @@ struct LFSR : RNG { struct PCG : RNG { PCG() { seed(); } - auto seed(maybe seed = {}, maybe sequence = {}) -> void { - if(!seed) seed = (uint32_t)randomSeed(); + auto seed(maybe seed = {}, maybe sequence = {}) -> void { + if(!seed) seed = (u32)randomSeed(); if(!sequence) sequence = 0; state = 0; @@ -111,16 +111,16 @@ struct PCG : RNG { } private: - auto read() -> uint32_t { - uint64_t state = this->state; + auto read() -> u32 { + u64 state = this->state; this->state = state * 6'364'136'223'846'793'005ull + increment; - uint32_t xorshift = (state >> 18 ^ state) >> 27; - uint32_t rotate = state >> 59; + u32 xorshift = (state >> 18 ^ state) >> 27; + u32 rotate = state >> 59; return xorshift >> rotate | xorshift << (-rotate & 31); } - uint64_t state = 0; - uint64_t increment = 0; + u64 state = 0; + u64 increment = 0; friend class RNG; }; @@ -134,23 +134,23 @@ namespace CSPRNG { struct XChaCha20 : RNG { XChaCha20() { seed(); } - auto seed(maybe key = {}, maybe nonce = {}) -> void { + auto seed(maybe key = {}, maybe nonce = {}) -> void { //the randomness comes from the key; the nonce just adds a bit of added entropy if(!key) key = randomSeed(); - if(!nonce) nonce = (uint192_t)clock() << 64 | chrono::nanosecond(); + if(!nonce) nonce = (u192)clock() << 64 | chrono::nanosecond(); context = {key(), nonce()}; } private: - auto read() -> uint32_t { + auto read() -> u32 { if(!counter) { context.cipher(); context.increment(); } - uint32_t value = context.block[counter++]; + u32 value = context.block[counter++]; if(counter == 16) counter = 0; //64-bytes per block; 4 bytes per read return value; } Cipher::XChaCha20 context{0, 0}; - uint counter = 0; + u32 counter = 0; friend class RNG; }; @@ -160,7 +160,7 @@ struct XChaCha20 : RNG { // -template inline auto random() -> T { +template inline auto random() -> T { static PRNG::PCG pcg; //note: unseeded return pcg.random(); } diff --git a/nall/range.hpp b/nall/range.hpp index 891f5ecad1..2e233b69be 100644 --- a/nall/range.hpp +++ b/nall/range.hpp @@ -4,25 +4,25 @@ namespace nall { struct range_t { struct iterator { - iterator(int64_t position, int64_t step = 0) : position(position), step(step) {} - auto operator*() const -> int64_t { return position; } + iterator(s64 position, s64 step = 0) : position(position), step(step) {} + auto operator*() const -> s64 { return position; } auto operator!=(const iterator& source) const -> bool { return step > 0 ? position < source.position : position > source.position; } auto operator++() -> iterator& { position += step; return *this; } private: - int64_t position; - const int64_t step; + s64 position; + const s64 step; }; struct reverse_iterator { - reverse_iterator(int64_t position, int64_t step = 0) : position(position), step(step) {} - auto operator*() const -> int64_t { return position; } + reverse_iterator(s64 position, s64 step = 0) : position(position), step(step) {} + auto operator*() const -> s64 { return position; } auto operator!=(const reverse_iterator& source) const -> bool { return step > 0 ? position > source.position : position < source.position; } auto operator++() -> reverse_iterator& { position -= step; return *this; } private: - int64_t position; - const int64_t step; + s64 position; + const s64 step; }; auto begin() const -> iterator { return {origin, stride}; } @@ -31,20 +31,20 @@ struct range_t { auto rbegin() const -> reverse_iterator { return {target - stride, stride}; } auto rend() const -> reverse_iterator { return {origin - stride}; } - int64_t origin; - int64_t target; - int64_t stride; + s64 origin; + s64 target; + s64 stride; }; -inline auto range(int64_t size) { +inline auto range(s64 size) { return range_t{0, size, 1}; } -inline auto range(int64_t offset, int64_t size) { +inline auto range(s64 offset, s64 size) { return range_t{offset, size, 1}; } -inline auto range(int64_t offset, int64_t size, int64_t step) { +inline auto range(s64 offset, s64 size, s64 step) { return range_t{offset, size, step}; } diff --git a/nall/recompiler/amd64/constants.hpp b/nall/recompiler/amd64/constants.hpp index 0d1ff6d3e3..0954b86b51 100644 --- a/nall/recompiler/amd64/constants.hpp +++ b/nall/recompiler/amd64/constants.hpp @@ -49,7 +49,7 @@ u64 data; }; - enum class reg8 : uint { + enum class reg8 : u32 { al, cl, dl, bl, ah, ch, dh, bh, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b, }; static constexpr reg8 al = reg8::al; @@ -69,7 +69,7 @@ static constexpr reg8 r14b = reg8::r14b; static constexpr reg8 r15b = reg8::r15b; - enum class reg16 : uint { + enum class reg16 : u32 { ax, cx, dx, bx, sp, bp, si, di, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w, }; static constexpr reg16 ax = reg16::ax; @@ -89,7 +89,7 @@ static constexpr reg16 r14w = reg16::r14w; static constexpr reg16 r15w = reg16::r15w; - enum class reg32 : uint { + enum class reg32 : u32 { eax, ecx, edx, ebx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d, }; static constexpr reg32 eax = reg32::eax; @@ -109,7 +109,7 @@ static constexpr reg32 r14d = reg32::r14d; static constexpr reg32 r15d = reg32::r15d; - enum class reg64 : uint { + enum class reg64 : u32 { rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15, }; static constexpr reg64 rax = reg64::rax; diff --git a/nall/recompiler/amd64/emitter.hpp b/nall/recompiler/amd64/emitter.hpp index 82d4309a96..e8535c9db1 100644 --- a/nall/recompiler/amd64/emitter.hpp +++ b/nall/recompiler/amd64/emitter.hpp @@ -48,7 +48,7 @@ struct emitter { array_span span, origin; } emit; -auto bind(array_span span) { +auto bind(array_span span) { emit.span = span; emit.origin = span; } diff --git a/nall/recompiler/amd64/encoder-instructions.hpp b/nall/recompiler/amd64/encoder-instructions.hpp index 8cc0db7bab..110b0f2f4e 100644 --- a/nall/recompiler/amd64/encoder-instructions.hpp +++ b/nall/recompiler/amd64/encoder-instructions.hpp @@ -3,7 +3,7 @@ //{ //call reg auto call(reg64 rt) { - auto _rt = (uint)rt; + auto _rt = (u32)rt; emit.rex(0, 0, 0, _rt & 8); emit.byte(0xff); emit.modrm(3, 2, _rt & 7); @@ -11,7 +11,7 @@ //mov reg,imm auto mov(reg64 rt, imm32 is) { - auto _rt = (uint)rt; + auto _rt = (u32)rt; emit.rex(1, 0, 0, _rt & 8); emit.byte(0xc7); emit.modrm(3, 0, _rt & 7); @@ -20,7 +20,7 @@ //mov reg,imm auto mov(reg64 rt, imm64 is) { - auto _rt = (uint)rt; + auto _rt = (u32)rt; emit.rex(1, 0, 0, _rt & 8); emit.byte(0xb8 | _rt & 7); emit.qword(is.data); @@ -61,7 +61,7 @@ //inc reg auto inc(reg64 rt) { - auto _rt = (uint)rt; + auto _rt = (u32)rt; emit.rex(1, 0, 0, _rt & 8); emit.byte(0xff); emit.modrm(3, 0, _rt & 7); @@ -69,14 +69,14 @@ //dec reg auto dec(reg64 rt) { - auto _rt = (uint)rt; + auto _rt = (u32)rt; emit.rex(1, 0, 0, _rt & 8); emit.byte(0xff); emit.modrm(3, 1, _rt & 7); } #define op(code) \ - auto _rt = (uint)rt, _rs = (uint)rs; \ + auto _rt = (u32)rt, _rs = (u32)rs; \ emit.rex(0, _rs & 8, 0, _rt & 8); \ emit.byte(code); \ emit.modrm(3, _rs & 7, _rt & 7); @@ -93,7 +93,7 @@ #undef op #define op(code) \ - auto _rt = (uint)rt, _rs = (uint)rs; \ + auto _rt = (u32)rt, _rs = (u32)rs; \ emit.byte(0x66); \ emit.rex(0, _rs & 8, 0, _rt & 8); \ emit.byte(code); \ @@ -111,7 +111,7 @@ #undef op #define op(code) \ - auto _rt = (uint)rt, _rs = (uint)rs; \ + auto _rt = (u32)rt, _rs = (u32)rs; \ emit.rex(0, _rs & 8, 0, _rt & 8); \ emit.byte(code); \ emit.modrm(3, _rs & 7, _rt & 7); @@ -128,7 +128,7 @@ #undef op #define op(code) \ - auto _rt = (uint)rt, _rs = (uint)rs; \ + auto _rt = (u32)rt, _rs = (u32)rs; \ emit.rex(1, _rs & 8, 0, _rt & 8); \ emit.byte(code); \ emit.modrm(3, _rs & 7, _rt & 7); @@ -145,7 +145,7 @@ #undef op #define op(code, reg) \ - auto _rt = (uint)rt; \ + auto _rt = (u32)rt; \ emit.rex(1, 0, 0, _rt & 8); \ emit.byte(code); \ emit.modrm(3, reg, _rt & 7); \ diff --git a/nall/reed-solomon.hpp b/nall/reed-solomon.hpp index d04bb66123..390245b351 100644 --- a/nall/reed-solomon.hpp +++ b/nall/reed-solomon.hpp @@ -3,34 +3,34 @@ namespace nall { //RS(n,k) = ReedSolomon -template +template struct ReedSolomon { - enum : uint { Parity = Length - Inputs }; + enum : u32 { Parity = Length - Inputs }; static_assert(Length <= 255 && Length > 0); static_assert(Parity <= 32 && Parity > 0); - using Field = GaloisField; - template using Polynomial = Matrix; + using Field = GaloisField; + template using Polynomial = Matrix; - template + template static auto shift(Polynomial polynomial) -> Polynomial { - for(int n = Size - 1; n > 0; n--) polynomial[n] = polynomial[n - 1]; + for(s32 n = Size - 1; n > 0; n--) polynomial[n] = polynomial[n - 1]; polynomial[0] = 0; return polynomial; } - template - static auto degree(const Polynomial& polynomial) -> uint { - for(int n = Size; n > 0; n--) { + template + static auto degree(const Polynomial& polynomial) -> u32 { + for(s32 n = Size; n > 0; n--) { if(polynomial[n - 1] != 0) return n - 1; } return 0; } - template + template static auto evaluate(const Polynomial& polynomial, Field field) -> Field { Field sum = 0; - for(uint n : range(Size)) sum += polynomial[n] * field.pow(n); + for(u32 n : range(Size)) sum += polynomial[n] * field.pow(n); return sum; } @@ -41,29 +41,29 @@ struct ReedSolomon { ReedSolomon() = default; ReedSolomon(const ReedSolomon&) = default; - ReedSolomon(const initializer_list& source) { - uint index = 0; + ReedSolomon(const initializer_list& source) { + u32 index = 0; for(auto& value : source) { if(index >= Length) break; message[index++] = value; } } - auto operator[](uint index) -> Field& { return message[index]; } - auto operator[](uint index) const -> Field { return message[index]; } + auto operator[](u32 index) -> Field& { return message[index]; } + auto operator[](u32 index) const -> Field { return message[index]; } auto calculateSyndromes() -> void { static const Polynomial bases = [] { Polynomial bases; - for(uint n : range(Parity)) { + for(u32 n : range(Parity)) { bases[n] = Field::exp(n); } return bases; }(); syndromes = {}; - for(uint m : range(Length)) { - for(uint p : range(Parity)) { + for(u32 m : range(Length)) { + for(u32 p : range(Parity)) { syndromes[p] *= bases[p]; syndromes[p] += message[m]; } @@ -73,8 +73,8 @@ struct ReedSolomon { auto generateParity() -> void { static const Polynomial matrix = [] { Polynomial matrix{}; - for(uint row : range(Parity)) { - for(uint col : range(Parity)) { + for(u32 row : range(Parity)) { + for(u32 col : range(Parity)) { matrix(row, col) = Field::exp(row * col); } } @@ -82,14 +82,14 @@ struct ReedSolomon { throw; //should never occur }(); - for(uint p : range(Parity)) message[Inputs + p] = 0; + for(u32 p : range(Parity)) message[Inputs + p] = 0; calculateSyndromes(); auto parity = matrix * syndromes; - for(uint p : range(Parity)) message[Inputs + p] = parity[Parity - (p + 1)]; + for(u32 p : range(Parity)) message[Inputs + p] = parity[Parity - (p + 1)]; } auto syndromesAreZero() -> bool { - for(uint p : range(Parity)) { + for(u32 p : range(Parity)) { if(syndromes[p]) return false; } return true; @@ -99,11 +99,11 @@ struct ReedSolomon { auto calculateLocators() -> void { Polynomial history{1}; locators = history; - uint errors = 0; + u32 errors = 0; - for(uint n : range(Parity)) { + for(u32 n : range(Parity)) { Field discrepancy = 0; - for(uint l : range(errors + 1)) { + for(u32 l : range(errors + 1)) { discrepancy += locators[l] * syndromes[n - l]; } @@ -121,39 +121,39 @@ struct ReedSolomon { //algorithm: brute force //todo: implement Chien search here - auto calculateErrors() -> vector { + auto calculateErrors() -> vector { calculateSyndromes(); if(syndromesAreZero()) return {}; //no errors detected calculateLocators(); - vector errors; - for(uint n : range(Length)) { + vector errors; + for(u32 n : range(Length)) { if(evaluate(locators, Field{2}.pow(255 - n))) continue; errors.append(Length - (n + 1)); } return errors; } - template - static auto calculateErasures(array_view errors) -> maybe> { + template + static auto calculateErasures(array_view errors) -> maybe> { Polynomial matrix{}; - for(uint row : range(Size)) { - for(uint col : range(Size)) { - uint index = Length - (errors[col] + 1); + for(u32 row : range(Size)) { + for(u32 col : range(Size)) { + u32 index = Length - (errors[col] + 1); matrix(row, col) = Field::exp(row * index); } } return matrix.invert(); } - template - auto correctErasures(array_view errors) -> int { + template + auto correctErasures(array_view errors) -> s32 { calculateSyndromes(); if(syndromesAreZero()) return 0; //no errors detected if(auto matrix = calculateErasures(errors)) { Polynomial factors; - for(uint n : range(Size)) factors[n] = syndromes[n]; + for(u32 n : range(Size)) factors[n] = syndromes[n]; auto errata = matrix() * factors; - for(uint m : range(Size)) { + for(u32 m : range(Size)) { message[errors[m]] += errata[m]; } calculateSyndromes(); @@ -167,7 +167,7 @@ struct ReedSolomon { //because this is a template parameter, and the actual number of errors may very, this function is needed. //the alternative would be to convert Matrix to a dynamically sized Matrix(Rows, Cols) type, //but this would require heap memory allocations and would be a massive performance penalty. - auto correctErrata(array_view errors) -> int { + auto correctErrata(array_view errors) -> s32 { if(errors.size() >= Parity) return -errors.size(); //too many errors to be correctable switch(errors.size()) { @@ -209,7 +209,7 @@ struct ReedSolomon { } //convenience function for when erasures aren't needed - auto correctErrors() -> int { + auto correctErrors() -> s32 { auto errors = calculateErrors(); return correctErrata(errors); } diff --git a/nall/serial.hpp b/nall/serial.hpp index 671e8ffe6a..33c5c09b0f 100644 --- a/nall/serial.hpp +++ b/nall/serial.hpp @@ -34,7 +34,7 @@ struct serial { } //-1 on error, otherwise return bytes read - auto read(uint8_t* data, uint length) -> int { + auto read(u8* data, u32 length) -> s32 { if(!opened) return -1; return ::read(port, (void*)data, length); } @@ -53,14 +53,14 @@ struct serial { } //-1 on error, otherwise return bytes written - auto write(const uint8_t* data, uint length) -> int { + auto write(const u8* data, u32 length) -> s32 { if(!opened) return -1; return ::write(port, (void*)data, length); } //rate==0: use flow control (synchronous mode) //rate!=0: baud-rate (asynchronous mode) - auto open(string device, uint rate = 0) -> bool { + auto open(string device, u32 rate = 0) -> bool { close(); if(!device) device = "/dev/ttyU0"; //note: default device name is for FreeBSD 10+ diff --git a/nall/serializer.hpp b/nall/serializer.hpp index 0fda6e233d..e62ba682ba 100644 --- a/nall/serializer.hpp +++ b/nall/serializer.hpp @@ -53,21 +53,21 @@ struct serializer { _size = 0; } - auto data() const -> const uint8_t* { + auto data() const -> const u8* { return _data; } - auto size() const -> uint { + auto size() const -> u32 { return _size; } - auto capacity() const -> uint { + auto capacity() const -> u32 { return _capacity; } - auto reserve(uint size) -> void { + auto reserve(u32 size) -> void { if(size > _capacity) { - auto data = new uint8_t[bit::round(size)](); + auto data = new u8[bit::round(size)](); memory::copy(data, _data, _capacity); delete[] _data; _data = data; @@ -87,7 +87,7 @@ struct serializer { return *this; } - template auto operator()(T (&array)[N]) -> serializer& { + template auto operator()(T (&array)[N]) -> serializer& { for(auto& value : array) operator()(value); return *this; } @@ -101,7 +101,7 @@ struct serializer { if(_data) delete[] _data; _mode = s._mode; - _data = new uint8_t[s._capacity]; + _data = new u8[s._capacity]; _size = s._size; _capacity = s._capacity; @@ -126,14 +126,14 @@ struct serializer { serializer() { setWriting(); - _data = new uint8_t[1024 * 1024](); + _data = new u8[1024 * 1024](); _size = 0; _capacity = 1024 * 1024; } - serializer(const uint8_t* data, uint capacity) { + serializer(const u8* data, u32 capacity) { setReading(); - _data = new uint8_t[capacity](); + _data = new u8[capacity](); _size = 0; _capacity = capacity; memory::copy(_data, data, capacity); @@ -145,36 +145,36 @@ struct serializer { private: template auto integer(T& value) -> serializer& { - enum : uint { size = std::is_same::value ? 1 : sizeof(T) }; + enum : u32 { size = std::is_same::value ? 1 : sizeof(T) }; reserve(_size + size); if(writing()) { T copy = value; - for(uint n : range(size)) _data[_size++] = copy, copy >>= 8; + for(u32 n : range(size)) _data[_size++] = copy, copy >>= 8; } else if(reading()) { value = 0; - for(uint n : range(size)) value |= (T)_data[_size++] << (n << 3); + for(u32 n : range(size)) value |= (T)_data[_size++] << (n << 3); } return *this; } template auto real(T& value) -> serializer& { - enum : uint { size = sizeof(T) }; + enum : u32 { size = sizeof(T) }; reserve(_size + size); //this is rather dangerous, and not cross-platform safe; //but there is no standardized way to export floating point values - auto p = (uint8_t*)&value; + auto p = (u8*)&value; if(writing()) { - for(uint n : range(size)) _data[_size++] = p[n]; + for(u32 n : range(size)) _data[_size++] = p[n]; } else if(reading()) { - for(uint n : range(size)) p[n] = _data[_size++]; + for(u32 n : range(size)) p[n] = _data[_size++]; } return *this; } bool _mode = 0; - uint8_t* _data = nullptr; - uint _size = 0; - uint _capacity = 0; + u8* _data = nullptr; + u32 _size = 0; + u32 _capacity = 0; }; } diff --git a/nall/set.hpp b/nall/set.hpp index 733bf84348..297a8c3fdb 100644 --- a/nall/set.hpp +++ b/nall/set.hpp @@ -26,7 +26,7 @@ template struct set { }; node_t* root = nullptr; - uint nodes = 0; + u32 nodes = 0; set() = default; set(const set& source) { operator=(source); } @@ -52,7 +52,7 @@ template struct set { } explicit operator bool() const { return nodes; } - auto size() const -> uint { return nodes; } + auto size() const -> u32 { return nodes; } auto reset() -> void { reset(root); @@ -70,7 +70,7 @@ template struct set { } auto insert(const T& value) -> maybe { - uint count = size(); + u32 count = size(); node_t* v = insert(root, value); root->red = 0; if(size() == count) return nothing; @@ -84,7 +84,7 @@ template struct set { } auto remove(const T& value) -> bool { - uint count = size(); + u32 count = size(); bool done = 0; remove(root, &value, done); if(root) root->red = 0; @@ -114,7 +114,7 @@ template struct set { return *this; } - base_iterator(const set& source, uint position) : source(source), position(position) { + base_iterator(const set& source, u32 position) : source(source), position(position) { node_t* node = source.root; while(node) { stack.append(node); @@ -124,12 +124,12 @@ template struct set { protected: const set& source; - uint position; + u32 position; vector stack; }; struct iterator : base_iterator { - iterator(const set& source, uint position) : base_iterator(source, position) {} + iterator(const set& source, u32 position) : base_iterator(source, position) {} auto operator*() const -> T& { return base_iterator::stack.right()->value; } }; @@ -137,7 +137,7 @@ template struct set { auto end() -> iterator { return iterator(*this, size()); } struct const_iterator : base_iterator { - const_iterator(const set& source, uint position) : base_iterator(source, position) {} + const_iterator(const set& source, u32 position) : base_iterator(source, position) {} auto operator*() const -> const T& { return base_iterator::stack.right()->value; } }; diff --git a/nall/shared-pointer.hpp b/nall/shared-pointer.hpp index e5755c13ab..9ac271f3ae 100644 --- a/nall/shared-pointer.hpp +++ b/nall/shared-pointer.hpp @@ -12,8 +12,8 @@ template struct shared_pointer; struct shared_pointer_manager { void* pointer = nullptr; function deleter; - uint strong = 0; - uint weak = 0; + u32 strong = 0; + u32 weak = 0; shared_pointer_manager(void* pointer) : pointer(pointer) { } @@ -188,7 +188,7 @@ struct shared_pointer { return manager && manager->strong == 1; } - auto references() const -> uint { + auto references() const -> u32 { return manager ? manager->strong : 0; } diff --git a/nall/smtp.hpp b/nall/smtp.hpp index d09823d189..82f2d7d2c4 100644 --- a/nall/smtp.hpp +++ b/nall/smtp.hpp @@ -17,14 +17,14 @@ namespace nall { struct SMTP { - enum class Format : uint { Plain, HTML }; + enum class Format : u32 { Plain, HTML }; - auto server(string server, uint16_t port = 25) -> void; + auto server(string server, u16 port = 25) -> void; auto from(string mail, string name = "") -> void; auto to(string mail, string name = "") -> void; auto cc(string mail, string name = "") -> void; auto bcc(string mail, string name = "") -> void; - auto attachment(const uint8_t* data, uint size, string name) -> void; + auto attachment(const u8* data, u32 size, string name) -> void; auto attachment(string filename, string name = "") -> bool; auto subject(string subject) -> void; auto body(string body, Format format = Format::Plain) -> void; @@ -34,14 +34,14 @@ struct SMTP { auto response() -> string; #if defined(API_WINDOWS) - auto close(int) -> int; + auto close(s32) -> s32; SMTP(); #endif private: struct Information { string server; - uint16_t port; + u16 port; struct Contact { string mail; string name; @@ -51,7 +51,7 @@ struct SMTP { vector cc; vector bcc; struct Attachment { - vector buffer; + vector buffer; string name; }; string subject; @@ -63,8 +63,8 @@ struct SMTP { string response; } info; - auto send(int sock, const string& text) -> bool; - auto recv(int sock) -> string; + auto send(s32 sock, const string& text) -> bool; + auto recv(s32 sock) -> string; auto boundary() -> string; auto filename(const string& filename) -> string; auto contact(const Information::Contact& contact) -> string; @@ -72,7 +72,7 @@ struct SMTP { auto split(const string& text) -> string; }; -inline auto SMTP::server(string server, uint16_t port) -> void { +inline auto SMTP::server(string server, u16 port) -> void { info.server = server; info.port = port; } @@ -93,8 +93,8 @@ inline auto SMTP::bcc(string mail, string name) -> void { info.bcc.append({mail, name}); } -inline auto SMTP::attachment(const uint8_t* data, uint size, string name) -> void { - vector buffer; +inline auto SMTP::attachment(const u8* data, u32 size, string name) -> void { + vector buffer; buffer.resize(size); memcpy(buffer.data(), data, size); info.attachments.append({std::move(buffer), name}); @@ -157,13 +157,13 @@ inline auto SMTP::send() -> bool { hints.ai_flags = AI_PASSIVE; addrinfo* serverinfo; - int status = getaddrinfo(info.server, string(info.port), &hints, &serverinfo); + s32 status = getaddrinfo(info.server, string(info.port), &hints, &serverinfo); if(status != 0) return false; - int sock = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); + s32 sock = socket(serverinfo->ai_family, serverinfo->ai_socktype, serverinfo->ai_protocol); if(sock == -1) return false; - int result = connect(sock, serverinfo->ai_addr, serverinfo->ai_addrlen); + s32 result = connect(sock, serverinfo->ai_addr, serverinfo->ai_addrlen); if(result == -1) return false; string response; @@ -220,11 +220,11 @@ inline auto SMTP::response() -> string { return info.response; } -inline auto SMTP::send(int sock, const string& text) -> bool { +inline auto SMTP::send(s32 sock, const string& text) -> bool { const char* data = text.data(); - uint size = text.size(); + u32 size = text.size(); while(size) { - int length = ::send(sock, (const char*)data, size, 0); + s32 length = ::send(sock, (const char*)data, size, 0); if(length == -1) return false; data += length; size -= length; @@ -232,8 +232,8 @@ inline auto SMTP::send(int sock, const string& text) -> bool { return true; } -inline auto SMTP::recv(int sock) -> string { - vector buffer; +inline auto SMTP::recv(s32 sock) -> string { + vector buffer; while(true) { char c; if(::recv(sock, &c, sizeof(char), 0) < 1) break; @@ -248,7 +248,7 @@ inline auto SMTP::boundary() -> string { random_lfsr random; random.seed(time(0)); string boundary; - for(uint n = 0; n < 16; n++) boundary.append(hex<2>(random())); + for(u32 n = 0; n < 16; n++) boundary.append(hex<2>(random())); return boundary; } @@ -278,9 +278,9 @@ inline auto SMTP::contacts(const vector& contacts) -> stri inline auto SMTP::split(const string& text) -> string { string result; - uint offset = 0; + u32 offset = 0; while(offset < text.size()) { - uint length = min(76, text.size() - offset); + u32 length = min(76, text.size() - offset); if(length < 76) { result.append(text.slice(offset)); } else { @@ -293,12 +293,12 @@ inline auto SMTP::split(const string& text) -> string { } #if defined(API_WINDOWS) -inline auto SMTP::close(int sock) -> int { +inline auto SMTP::close(s32 sock) -> s32 { return closesocket(sock); } inline SMTP::SMTP() { - int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + s32 sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(sock == INVALID_SOCKET && WSAGetLastError() == WSANOTINITIALISED) { WSADATA wsaData; if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { diff --git a/nall/string.hpp b/nall/string.hpp index 9c27f5ce2f..6def7fd8b8 100644 --- a/nall/string.hpp +++ b/nall/string.hpp @@ -37,7 +37,7 @@ struct string_view { string_view(const string_view& source); string_view(string_view&& source); string_view(const char* data); - string_view(const char* data, uint size); + string_view(const char* data, u32 size); string_view(const string& source); template string_view(P&&... p); ~string_view(); @@ -45,10 +45,13 @@ struct string_view { auto operator=(const string_view& source) -> type&; auto operator=(string_view&& source) -> type&; + auto operator==(const char* source) const -> bool { return strcmp(data(), source) == 0; } + auto operator!=(const char* source) const -> bool { return strcmp(data(), source) != 0; } + explicit operator bool() const; operator const char*() const; auto data() const -> const char*; - auto size() const -> uint; + auto size() const -> u32; auto begin() const { return &_data[0]; } auto end() const { return &_data[size()]; } @@ -56,7 +59,7 @@ struct string_view { protected: string* _string; const char* _data; - mutable int _size; + mutable s32 _size; }; //adaptive (SSO + COW) is by far the best choice, the others exist solely to: @@ -74,33 +77,34 @@ template struct stringify; template auto print(P&&...) -> void; template auto print(FILE*, P&&...) -> void; template auto pad(const T& value, long precision = 0, char padchar = ' ') -> string; -auto hex(uintmax value, long precision = 0, char padchar = '0') -> string; -auto octal(uintmax value, long precision = 0, char padchar = '0') -> string; -auto binary(uintmax value, long precision = 0, char padchar = '0') -> string; +auto hex(u64 value, long precision = 0, char padchar = '0') -> string; +auto octal(u64 value, long precision = 0, char padchar = '0') -> string; +auto binary(u64 value, long precision = 0, char padchar = '0') -> string; //match.hpp auto tokenize(const char* s, const char* p) -> bool; auto tokenize(vector& list, const char* s, const char* p) -> bool; //utf8.hpp -auto characters(string_view self, int offset = 0, int length = -1) -> uint; +auto characters(string_view self, s32 offset = 0, s32 length = -1) -> u32; //utility.hpp -auto slice(string_view self, int offset = 0, int length = -1) -> string; +auto slice(string_view self, s32 offset = 0, s32 length = -1) -> string; template auto fromInteger(char* result, T value) -> char*; template auto fromNatural(char* result, T value) -> char*; -template auto fromReal(char* str, T value) -> uint; +template auto fromHex(char* result, T value) -> char*; +template auto fromReal(char* str, T value) -> u32; struct string { using type = string; protected: #if defined(NALL_STRING_ALLOCATOR_ADAPTIVE) - enum : uint { SSO = 24 }; + enum : u32 { SSO = 24 }; union { struct { //copy-on-write char* _data; - uint* _refs; + u32* _refs; }; struct { //small-string-optimization char _text[SSO]; @@ -113,13 +117,13 @@ struct string { #if defined(NALL_STRING_ALLOCATOR_COPY_ON_WRITE) char* _data; - mutable uint* _refs; + mutable u32* _refs; auto _allocate() -> char*; auto _copy() -> char*; #endif #if defined(NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION) - enum : uint { SSO = 24 }; + enum : u32 { SSO = 24 }; union { char* _data; char _text[SSO]; @@ -130,8 +134,8 @@ struct string { char* _data; #endif - uint _capacity; - uint _size; + u32 _capacity; + u32 _size; public: string(); @@ -140,11 +144,11 @@ struct string { string(string&& source) : string() { operator=(move(source)); } template auto get() -> T*; template auto data() const -> const T*; - template auto size() const -> uint { return _size / sizeof(T); } - template auto capacity() const -> uint { return _capacity / sizeof(T); } + template auto size() const -> u32 { return _size / sizeof(T); } + template auto capacity() const -> u32 { return _capacity / sizeof(T); } auto reset() -> type&; - auto reserve(uint) -> type&; - auto resize(uint) -> type&; + auto reserve(u32) -> type&; + auto resize(u32) -> type&; auto operator=(const string&) -> type&; auto operator=(string&&) -> type&; @@ -157,8 +161,8 @@ struct string { operator const char*() const { return (const char*)data(); } operator array_span() { return {(char*)get(), size()}; } operator array_view() const { return {(const char*)data(), size()}; } - operator array_span() { return {(uint8_t*)get(), size()}; } - operator array_view() const { return {(const uint8_t*)data(), size()}; } + operator array_span() { return {(u8*)get(), size()}; } + operator array_view() const { return {(const u8*)data(), size()}; } auto operator==(const string& source) const -> bool { return size() == source.size() && memory::compare(data(), source.data(), size()) == 0; @@ -184,14 +188,14 @@ struct string { //atoi.hpp auto boolean() const -> bool; - auto integer() const -> intmax; - auto natural() const -> uintmax; - auto hex() const -> uintmax; - auto real() const -> double; + auto integer() const -> s64; + auto natural() const -> u64; + auto hex() const -> u64; + auto real() const -> f64; //core.hpp - auto operator[](uint) const -> const char&; - auto operator()(uint, char = 0) const -> char; + auto operator[](u32) const -> const char&; + auto operator()(u32, char = 0) const -> char; template auto assign(P&&...) -> type&; template auto prepend(const T&, P&&...) -> type&; template auto prepend(const nall::string_format&, P&&...) -> type&; @@ -199,38 +203,38 @@ struct string { template auto append(const T&, P&&...) -> type&; template auto append(const nall::string_format&, P&&...) -> type&; template auto _append(const stringify&) -> type&; - auto length() const -> uint; + auto length() const -> u32; //find.hpp - auto contains(string_view characters) const -> maybe; + auto contains(string_view characters) const -> maybe; - template auto _find(int, string_view) const -> maybe; + template auto _find(s32, string_view) const -> maybe; - auto find(string_view source) const -> maybe; - auto ifind(string_view source) const -> maybe; - auto qfind(string_view source) const -> maybe; - auto iqfind(string_view source) const -> maybe; + auto find(string_view source) const -> maybe; + auto ifind(string_view source) const -> maybe; + auto qfind(string_view source) const -> maybe; + auto iqfind(string_view source) const -> maybe; - auto findFrom(int offset, string_view source) const -> maybe; - auto ifindFrom(int offset, string_view source) const -> maybe; + auto findFrom(s32 offset, string_view source) const -> maybe; + auto ifindFrom(s32 offset, string_view source) const -> maybe; - auto findNext(int offset, string_view source) const -> maybe; - auto ifindNext(int offset, string_view source) const -> maybe; + auto findNext(s32 offset, string_view source) const -> maybe; + auto ifindNext(s32 offset, string_view source) const -> maybe; - auto findPrevious(int offset, string_view source) const -> maybe; - auto ifindPrevious(int offset, string_view source) const -> maybe; + auto findPrevious(s32 offset, string_view source) const -> maybe; + auto ifindPrevious(s32 offset, string_view source) const -> maybe; //format.hpp auto format(const nall::string_format& params) -> type&; //compare.hpp - template static auto _compare(const char*, uint, const char*, uint) -> int; + template static auto _compare(const char*, u32, const char*, u32) -> s32; - static auto compare(string_view, string_view) -> int; - static auto icompare(string_view, string_view) -> int; + static auto compare(string_view, string_view) -> s32; + static auto icompare(string_view, string_view) -> s32; - auto compare(string_view source) const -> int; - auto icompare(string_view source) const -> int; + auto compare(string_view source) const -> s32; + auto icompare(string_view source) const -> s32; auto equals(string_view source) const -> bool; auto iequals(string_view source) const -> bool; @@ -281,17 +285,17 @@ struct string { auto stripRight() -> type&; //utf8.hpp - auto characters(int offset = 0, int length = -1) const -> uint; + auto characters(s32 offset = 0, s32 length = -1) const -> u32; //utility.hpp static auto read(string_view filename) -> string; - static auto repeat(string_view pattern, uint times) -> string; + static auto repeat(string_view pattern, u32 times) -> string; auto fill(char fill = ' ') -> type&; - auto hash() const -> uint; - auto remove(uint offset, uint length) -> type&; + auto hash() const -> u32; + auto remove(u32 offset, u32 length) -> type&; auto reverse() -> type&; - auto size(int length, char fill = ' ') -> type&; - auto slice(int offset = 0, int length = -1) const -> string; + auto size(s32 length, char fill = ' ') -> type&; + auto slice(s32 offset = 0, s32 length = -1) const -> string; }; template<> struct vector : vector_base { @@ -312,8 +316,8 @@ template<> struct vector : vector_base { auto append() -> type&; auto isort() -> type&; - auto find(string_view source) const -> maybe; - auto ifind(string_view source) const -> maybe; + auto find(string_view source) const -> maybe; + auto ifind(string_view source) const -> maybe; auto match(string_view pattern) const -> vector; auto merge(string_view separator = "") const -> string; auto strip() -> type&; diff --git a/nall/string/allocator/adaptive.hpp b/nall/string/allocator/adaptive.hpp index 57505d32ec..5c4b8d7117 100644 --- a/nall/string/allocator/adaptive.hpp +++ b/nall/string/allocator/adaptive.hpp @@ -43,7 +43,7 @@ inline auto string::reset() -> type& { return *this; } -inline auto string::reserve(uint capacity) -> type& { +inline auto string::reserve(u32 capacity) -> type& { if(capacity <= _capacity) return *this; capacity = bit::round(capacity + 1) - 1; if(_capacity < SSO) { @@ -59,7 +59,7 @@ inline auto string::reserve(uint capacity) -> type& { return *this; } -inline auto string::resize(uint size) -> type& { +inline auto string::resize(u32 size) -> type& { reserve(size); get()[_size = size] = 0; return *this; @@ -96,27 +96,27 @@ inline auto string::operator=(string&& source) -> type& { inline auto string::_allocate() -> void { char _temp[SSO]; memory::copy(_temp, _text, SSO); - _data = memory::allocate(_capacity + 1 + sizeof(uint)); + _data = memory::allocate(_capacity + 1 + sizeof(u32)); memory::copy(_data, _temp, SSO); - _refs = (uint*)(_data + _capacity + 1); //always aligned by 32 via reserve() + _refs = (u32*)(_data + _capacity + 1); //always aligned by 32 via reserve() *_refs = 1; } //COW -> Unique inline auto string::_copy() -> void { - auto _temp = memory::allocate(_capacity + 1 + sizeof(uint)); + auto _temp = memory::allocate(_capacity + 1 + sizeof(u32)); memory::copy(_temp, _data, _size = min(_capacity, _size)); _temp[_size] = 0; --*_refs; _data = _temp; - _refs = (uint*)(_data + _capacity + 1); + _refs = (u32*)(_data + _capacity + 1); *_refs = 1; } //COW -> Resize inline auto string::_resize() -> void { - _data = memory::resize(_data, _capacity + 1 + sizeof(uint)); - _refs = (uint*)(_data + _capacity + 1); + _data = memory::resize(_data, _capacity + 1 + sizeof(u32)); + _refs = (u32*)(_data + _capacity + 1); *_refs = 1; } diff --git a/nall/string/allocator/copy-on-write.hpp b/nall/string/allocator/copy-on-write.hpp index 9c0452ec99..c7e0b4217d 100644 --- a/nall/string/allocator/copy-on-write.hpp +++ b/nall/string/allocator/copy-on-write.hpp @@ -30,7 +30,7 @@ inline auto string::reset() -> type& { return *this; } -inline auto string::reserve(uint capacity) -> type& { +inline auto string::reserve(u32 capacity) -> type& { if(capacity > _capacity) { _capacity = bit::round(max(31u, capacity) + 1) - 1; _data = _data ? _copy() : _allocate(); @@ -38,7 +38,7 @@ inline auto string::reserve(uint capacity) -> type& { return *this; } -inline auto string::resize(uint size) -> type& { +inline auto string::resize(u32 size) -> type& { reserve(size); get()[_size = size] = 0; return *this; @@ -72,19 +72,19 @@ inline auto string::operator=(string&& source) -> string& { } inline auto string::_allocate() -> char* { - auto _temp = memory::allocate(_capacity + 1 + sizeof(uint)); + auto _temp = memory::allocate(_capacity + 1 + sizeof(u32)); *_temp = 0; - _refs = (uint*)(_temp + _capacity + 1); //this will always be aligned by 32 via reserve() + _refs = (u32*)(_temp + _capacity + 1); //this will always be aligned by 32 via reserve() *_refs = 1; return _temp; } inline auto string::_copy() -> char* { - auto _temp = memory::allocate(_capacity + 1 + sizeof(uint)); + auto _temp = memory::allocate(_capacity + 1 + sizeof(u32)); memory::copy(_temp, _data, _size = min(_capacity, _size)); _temp[_size] = 0; --*_refs; - _refs = (uint*)(_temp + _capacity + 1); + _refs = (u32*)(_temp + _capacity + 1); *_refs = 1; return _temp; } diff --git a/nall/string/allocator/small-string-optimization.hpp b/nall/string/allocator/small-string-optimization.hpp index 403981d544..baedeccc10 100644 --- a/nall/string/allocator/small-string-optimization.hpp +++ b/nall/string/allocator/small-string-optimization.hpp @@ -46,7 +46,7 @@ inline auto string::reset() -> type& { return *this; } -inline auto string::reserve(uint capacity) -> type& { +inline auto string::reserve(u32 capacity) -> type& { if(capacity <= _capacity) return *this; capacity = bit::round(capacity + 1) - 1; if(_capacity < SSO) { @@ -60,7 +60,7 @@ inline auto string::reserve(uint capacity) -> type& { return *this; } -inline auto string::resize(uint size) -> type& { +inline auto string::resize(u32 size) -> type& { reserve(size); get()[_size = size] = 0; return *this; diff --git a/nall/string/allocator/vector.hpp b/nall/string/allocator/vector.hpp index 15b5de2635..ef3233948d 100644 --- a/nall/string/allocator/vector.hpp +++ b/nall/string/allocator/vector.hpp @@ -38,7 +38,7 @@ inline auto string::reset() -> type& { return *this; } -inline auto string::reserve(uint capacity) -> type& { +inline auto string::reserve(u32 capacity) -> type& { if(capacity > _capacity) { _capacity = bit::round(capacity + 1) - 1; _data = memory::resize(_data, _capacity + 1); @@ -47,7 +47,7 @@ inline auto string::reserve(uint capacity) -> type& { return *this; } -inline auto string::resize(uint size) -> type& { +inline auto string::resize(u32 size) -> type& { reserve(size); get()[_size = size] = 0; return *this; diff --git a/nall/string/atoi.hpp b/nall/string/atoi.hpp index 54c93d4243..1b197959b4 100644 --- a/nall/string/atoi.hpp +++ b/nall/string/atoi.hpp @@ -6,19 +6,19 @@ inline auto string::boolean() const -> bool { return equals("true"); } -inline auto string::integer() const -> intmax { +inline auto string::integer() const -> s64 { return toInteger(data()); } -inline auto string::natural() const -> uintmax { +inline auto string::natural() const -> u64 { return toNatural(data()); } -inline auto string::hex() const -> uintmax { +inline auto string::hex() const -> u64 { return toHex(data()); } -inline auto string::real() const -> double { +inline auto string::real() const -> f64 { return toReal(data()); } diff --git a/nall/string/cast.hpp b/nall/string/cast.hpp index f80754a5a6..dadbb6cfd5 100644 --- a/nall/string/cast.hpp +++ b/nall/string/cast.hpp @@ -10,14 +10,14 @@ namespace nall { template<> struct stringify { stringify(bool value) : _value(value) {} auto data() const -> const char* { return _value ? "true" : "false"; } - auto size() const -> uint { return _value ? 4 : 5; } + auto size() const -> u32 { return _value ? 4 : 5; } bool _value; }; template<> struct stringify { stringify(bool value) : _value(value) {} auto data() const -> const char* { return _value ? "true" : "false"; } - auto size() const -> uint { return _value ? 4 : 5; } + auto size() const -> u32 { return _value ? 4 : 5; } bool _value; }; @@ -26,7 +26,7 @@ template<> struct stringify { template<> struct stringify { stringify(char source) { _data[0] = source; _data[1] = 0; } auto data() const -> const char* { return _data; } - auto size() const -> uint { return 1; } + auto size() const -> u32 { return 1; } char _data[2]; }; @@ -35,52 +35,52 @@ template<> struct stringify { template<> struct stringify { stringify(signed char source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[2 + sizeof(signed char) * 3]; }; template<> struct stringify { stringify(signed short source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[2 + sizeof(signed short) * 3]; }; template<> struct stringify { stringify(signed int source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[2 + sizeof(signed int) * 3]; }; template<> struct stringify { stringify(signed long source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[2 + sizeof(signed long) * 3]; }; template<> struct stringify { stringify(signed long long source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[2 + sizeof(signed long long) * 3]; }; #if defined(__SIZEOF_INT128__) -template<> struct stringify { +template<> struct stringify { stringify(int128_t source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } - char _data[2 + sizeof(int128_t) * 3]; + auto size() const -> u32 { return strlen(_data); } + char _data[2 + sizeof(s128) * 3]; }; #endif -template struct stringify> { +template struct stringify> { stringify(Integer source) { fromInteger(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } - char _data[2 + sizeof(int64_t) * 3]; + auto size() const -> u32 { return strlen(_data); } + char _data[2 + sizeof(s64) * 3]; }; //unsigned integers @@ -88,52 +88,52 @@ template struct stringify> { template<> struct stringify { stringify(unsigned char source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[1 + sizeof(unsigned char) * 3]; }; template<> struct stringify { stringify(unsigned short source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[1 + sizeof(unsigned short) * 3]; }; template<> struct stringify { stringify(unsigned int source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[1 + sizeof(unsigned int) * 3]; }; template<> struct stringify { stringify(unsigned long source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[1 + sizeof(unsigned long) * 3]; }; template<> struct stringify { stringify(unsigned long long source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[1 + sizeof(unsigned long long) * 3]; }; #if defined(__SIZEOF_INT128__) -template<> struct stringify { - stringify(uint128_t source) { fromNatural(_data, source); } +template<> struct stringify { + stringify(u128 source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } - char _data[1 + sizeof(uint128_t) * 3]; + auto size() const -> u32 { return strlen(_data); } + char _data[1 + sizeof(u128) * 3]; }; #endif -template struct stringify> { +template struct stringify> { stringify(Natural source) { fromNatural(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } - char _data[1 + sizeof(uint64_t) * 3]; + auto size() const -> u32 { return strlen(_data); } + char _data[1 + sizeof(u64) * 3]; }; //floating-point @@ -141,50 +141,50 @@ template struct stringify> { template<> struct stringify { stringify(float source) { fromReal(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[256]; }; template<> struct stringify { stringify(double source) { fromReal(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[256]; }; template<> struct stringify { stringify(long double source) { fromReal(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[256]; }; -template struct stringify> { +template struct stringify> { stringify(Real source) { fromReal(_data, source); } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[256]; }; //arrays -template<> struct stringify> { - stringify(vector source) { +template<> struct stringify> { + stringify(vector source) { _text.resize(source.size()); memory::copy(_text.data(), source.data(), source.size()); } auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } vector _text; }; -template<> struct stringify&> { - stringify(const vector& source) { +template<> struct stringify&> { + stringify(const vector& source) { _text.resize(source.size()); memory::copy(_text.data(), source.data(), source.size()); } auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } vector _text; }; @@ -193,14 +193,14 @@ template<> struct stringify&> { template<> struct stringify { stringify(char* source) : _data(source ? source : "") {} auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } const char* _data; }; template<> struct stringify { stringify(const char* source) : _data(source ? source : "") {} auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } const char* _data; }; @@ -209,56 +209,56 @@ template<> struct stringify { template<> struct stringify { stringify(const string& source) : _text(source) {} auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } const string& _text; }; template<> struct stringify { stringify(const string& source) : _text(source) {} auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } const string& _text; }; template<> struct stringify { stringify(const string_view& source) : _view(source) {} auto data() const -> const char* { return _view.data(); } - auto size() const -> uint { return _view.size(); } + auto size() const -> u32 { return _view.size(); } const string_view& _view; }; template<> struct stringify { stringify(const string_view& source) : _view(source) {} auto data() const -> const char* { return _view.data(); } - auto size() const -> uint { return _view.size(); } + auto size() const -> u32 { return _view.size(); } const string_view& _view; }; -template<> struct stringify> { - stringify(const array_view& source) : _view(source) {} +template<> struct stringify> { + stringify(const array_view& source) : _view(source) {} auto data() const -> const char* { return _view.data(); } - auto size() const -> uint { return _view.size(); } - const array_view& _view; + auto size() const -> u32 { return _view.size(); } + const array_view& _view; }; -template<> struct stringify&> { - stringify(const array_view& source) : _view(source) {} +template<> struct stringify&> { + stringify(const array_view& source) : _view(source) {} auto data() const -> const char* { return _view.data(); } - auto size() const -> uint { return _view.size(); } - const array_view& _view; + auto size() const -> u32 { return _view.size(); } + const array_view& _view; }; template<> struct stringify { stringify(const string_pascal& source) : _text(source) {} auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } const string_pascal& _text; }; template<> struct stringify { stringify(const string_pascal& source) : _text(source) {} auto data() const -> const char* { return _text.data(); } - auto size() const -> uint { return _text.size(); } + auto size() const -> u32 { return _text.size(); } const string_pascal& _text; }; @@ -271,11 +271,11 @@ template struct stringify { memory::copy(_data, "(nullptr)", 10); } else { memory::copy(_data, "0x", 2); - fromNatural(_data + 2, (uintptr)source); + fromHex(_data + 2, (uintptr)source); } } auto data() const -> const char* { return _data; } - auto size() const -> uint { return strlen(_data); } + auto size() const -> u32 { return strlen(_data); } char _data[256]; }; diff --git a/nall/string/compare.hpp b/nall/string/compare.hpp index 6e9c2ccd77..c179d034f9 100644 --- a/nall/string/compare.hpp +++ b/nall/string/compare.hpp @@ -3,25 +3,25 @@ namespace nall { template -inline auto string::_compare(const char* target, uint capacity, const char* source, uint size) -> int { +inline auto string::_compare(const char* target, u32 capacity, const char* source, u32 size) -> s32 { if(Insensitive) return memory::icompare(target, capacity, source, size); return memory::compare(target, capacity, source, size); } //size() + 1 includes null-terminator; required to properly compare strings of differing lengths -inline auto string::compare(string_view x, string_view y) -> int { +inline auto string::compare(string_view x, string_view y) -> s32 { return memory::compare(x.data(), x.size() + 1, y.data(), y.size() + 1); } -inline auto string::icompare(string_view x, string_view y) -> int { +inline auto string::icompare(string_view x, string_view y) -> s32 { return memory::icompare(x.data(), x.size() + 1, y.data(), y.size() + 1); } -inline auto string::compare(string_view source) const -> int { +inline auto string::compare(string_view source) const -> s32 { return memory::compare(data(), size() + 1, source.data(), source.size() + 1); } -inline auto string::icompare(string_view source) const -> int { +inline auto string::icompare(string_view source) const -> s32 { return memory::icompare(data(), size() + 1, source.data(), source.size() + 1); } diff --git a/nall/string/convert.hpp b/nall/string/convert.hpp index 82de77db3e..4056757728 100644 --- a/nall/string/convert.hpp +++ b/nall/string/convert.hpp @@ -4,7 +4,7 @@ namespace nall { inline auto string::downcase() -> string& { char* p = get(); - for(uint n = 0; n < size(); n++) { + for(u32 n = 0; n < size(); n++) { if(p[n] >= 'A' && p[n] <= 'Z') p[n] += 0x20; } return *this; @@ -12,7 +12,7 @@ inline auto string::downcase() -> string& { inline auto string::qdowncase() -> string& { char* p = get(); - for(uint n = 0, quoted = 0; n < size(); n++) { + for(u32 n = 0, quoted = 0; n < size(); n++) { if(p[n] == '\"') quoted ^= 1; if(!quoted && p[n] >= 'A' && p[n] <= 'Z') p[n] += 0x20; } @@ -21,7 +21,7 @@ inline auto string::qdowncase() -> string& { inline auto string::upcase() -> string& { char* p = get(); - for(uint n = 0; n < size(); n++) { + for(u32 n = 0; n < size(); n++) { if(p[n] >= 'a' && p[n] <= 'z') p[n] -= 0x20; } return *this; @@ -29,7 +29,7 @@ inline auto string::upcase() -> string& { inline auto string::qupcase() -> string& { char* p = get(); - for(uint n = 0, quoted = 0; n < size(); n++) { + for(u32 n = 0, quoted = 0; n < size(); n++) { if(p[n] == '\"') quoted ^= 1; if(!quoted && p[n] >= 'a' && p[n] <= 'z') p[n] -= 0x20; } @@ -39,8 +39,8 @@ inline auto string::qupcase() -> string& { inline auto string::transform(string_view from, string_view to) -> string& { if(from.size() != to.size() || from.size() == 0) return *this; //patterns must be the same length char* p = get(); - for(uint n = 0; n < size(); n++) { - for(uint s = 0; s < from.size(); s++) { + for(u32 n = 0; n < size(); n++) { + for(u32 s = 0; s < from.size(); s++) { if(p[n] == from[s]) { p[n] = to[s]; break; diff --git a/nall/string/core.hpp b/nall/string/core.hpp index 315b6001eb..a41fa69190 100644 --- a/nall/string/core.hpp +++ b/nall/string/core.hpp @@ -15,7 +15,7 @@ namespace nall { -inline auto string::operator[](uint position) const -> const char& { +inline auto string::operator[](u32 position) const -> const char& { #ifdef DEBUG struct out_of_bounds {}; if(position >= size() + 1) throw out_of_bounds{}; @@ -23,7 +23,7 @@ inline auto string::operator[](uint position) const -> const char& { return data()[position]; } -inline auto string::operator()(uint position, char fallback) const -> char { +inline auto string::operator()(u32 position, char fallback) const -> char { if(position >= size() + 1) return fallback; return data()[position]; } @@ -68,7 +68,7 @@ template inline auto string::_append(const stringify& source) -> return *this; } -inline auto string::length() const -> uint { +inline auto string::length() const -> u32 { return strlen(data()); } diff --git a/nall/string/eval/evaluator.hpp b/nall/string/eval/evaluator.hpp index cecffd4048..130550870c 100644 --- a/nall/string/eval/evaluator.hpp +++ b/nall/string/eval/evaluator.hpp @@ -36,7 +36,7 @@ inline auto evaluateExpression(Node* node) -> string { throw "invalid operator"; } -inline auto evaluateInteger(Node* node) -> int64_t { +inline auto evaluateInteger(Node* node) -> s64 { if(node->type == Node::Type::Literal) return toInteger(node->literal); #define p(n) evaluateInteger(node->link[n]) @@ -85,7 +85,7 @@ inline auto evaluateInteger(Node* node) -> int64_t { throw "invalid operator"; } -inline auto integer(const string& expression) -> maybe { +inline auto integer(const string& expression) -> maybe { try { auto tree = new Node; const char* p = expression; @@ -98,7 +98,7 @@ inline auto integer(const string& expression) -> maybe { } } -inline auto evaluateReal(Node* node) -> long double { +inline auto evaluateReal(Node* node) -> f64 { if(node->type == Node::Type::Literal) return toReal(node->literal); #define p(n) evaluateReal(node->link[n]) @@ -130,7 +130,7 @@ inline auto evaluateReal(Node* node) -> long double { throw "invalid operator"; } -inline auto real(const string& expression) -> maybe { +inline auto real(const string& expression) -> maybe { try { auto tree = new Node; const char* p = expression; diff --git a/nall/string/eval/literal.hpp b/nall/string/eval/literal.hpp index 7c7177045d..becd35b4b7 100644 --- a/nall/string/eval/literal.hpp +++ b/nall/string/eval/literal.hpp @@ -16,7 +16,7 @@ inline auto literalNumber(const char*& s) -> string { //binary if(p[0] == '%' || (p[0] == '0' && p[1] == 'b')) { - uint prefix = 1 + (p[0] == '0'); + u32 prefix = 1 + (p[0] == '0'); p += prefix; while(p[0] == '\'' || p[0] == '0' || p[0] == '1') p++; if(p - s <= prefix) throw "invalid binary literal"; @@ -27,7 +27,7 @@ inline auto literalNumber(const char*& s) -> string { //octal if(p[0] == '0' && p[1] == 'o') { - uint prefix = 1 + (p[0] == '0'); + u32 prefix = 1 + (p[0] == '0'); p += prefix; while(p[0] == '\'' || (p[0] >= '0' && p[0] <= '7')) p++; if(p - s <= prefix) throw "invalid octal literal"; @@ -38,7 +38,7 @@ inline auto literalNumber(const char*& s) -> string { //hex if(p[0] == '$' || (p[0] == '0' && p[1] == 'x')) { - uint prefix = 1 + (p[0] == '0'); + u32 prefix = 1 + (p[0] == '0'); p += prefix; while(p[0] == '\'' || (p[0] >= '0' && p[0] <= '9') || (p[0] >= 'A' && p[0] <= 'F') || (p[0] >= 'a' && p[0] <= 'f')) p++; if(p - s <= prefix) throw "invalid hex literal"; diff --git a/nall/string/eval/node.hpp b/nall/string/eval/node.hpp index d02a928e9e..d79d4920e3 100644 --- a/nall/string/eval/node.hpp +++ b/nall/string/eval/node.hpp @@ -3,7 +3,7 @@ namespace nall::Eval { struct Node { - enum class Type : uint { + enum class Type : u32 { Null, Literal, Function, Subscript, Member, SuffixIncrement, SuffixDecrement, diff --git a/nall/string/eval/parser.hpp b/nall/string/eval/parser.hpp index c01af0a544..47bbbd539a 100644 --- a/nall/string/eval/parser.hpp +++ b/nall/string/eval/parser.hpp @@ -29,28 +29,28 @@ inline auto whitespace(char n) -> bool { // a<<>>b a<<<=b a>>>=b rotation operators were added // a~b a~=b concatenation operators were added // a??b coalesce operator was added -inline auto parse(Node*& node, const char*& s, uint depth) -> void { - auto unaryPrefix = [&](Node::Type type, uint seek, uint depth) { +inline auto parse(Node*& node, const char*& s, u32 depth) -> void { + auto unaryPrefix = [&](Node::Type type, u32 seek, u32 depth) { auto parent = new Node(type); parse(parent->link(0) = new Node, s += seek, depth); node = parent; }; - auto unarySuffix = [&](Node::Type type, uint seek, uint depth) { + auto unarySuffix = [&](Node::Type type, u32 seek, u32 depth) { auto parent = new Node(type); parent->link(0) = node; parse(parent, s += seek, depth); node = parent; }; - auto binary = [&](Node::Type type, uint seek, uint depth) { + auto binary = [&](Node::Type type, u32 seek, u32 depth) { auto parent = new Node(type); parent->link(0) = node; parse(parent->link(1) = new Node, s += seek, depth); node = parent; }; - auto ternary = [&](Node::Type type, uint seek, uint depth) { + auto ternary = [&](Node::Type type, u32 seek, u32 depth) { auto parent = new Node(type); parent->link(0) = node; parse(parent->link(1) = new Node, s += seek, depth); @@ -59,9 +59,9 @@ inline auto parse(Node*& node, const char*& s, uint depth) -> void { node = parent; }; - auto separator = [&](Node::Type type, uint seek, uint depth) { + auto separator = [&](Node::Type type, u32 seek, u32 depth) { if(node->type != Node::Type::Separator) return binary(type, seek, depth); - uint n = node->link.size(); + u32 n = node->link.size(); parse(node->link(n) = new Node, s += seek, depth); }; diff --git a/nall/string/find.hpp b/nall/string/find.hpp index ee6dbb555b..e0beb1d28e 100644 --- a/nall/string/find.hpp +++ b/nall/string/find.hpp @@ -2,8 +2,8 @@ namespace nall { -inline auto string::contains(string_view characters) const -> maybe { - for(uint x : range(size())) { +inline auto string::contains(string_view characters) const -> maybe { + for(u32 x : range(size())) { for(char y : characters) { if(operator[](x) == y) return x; } @@ -11,10 +11,10 @@ inline auto string::contains(string_view characters) const -> maybe { return nothing; } -template inline auto string::_find(int offset, string_view source) const -> maybe { +template inline auto string::_find(s32 offset, string_view source) const -> maybe { if(source.size() == 0) return nothing; auto p = data(); - for(uint n = offset, quoted = 0; n < size();) { + for(u32 n = offset, quoted = 0; n < size();) { if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } } if(_compare(p + n, size() - n, source.data(), source.size())) { n++; continue; } return n - offset; @@ -22,41 +22,41 @@ template inline auto string::_find(int offset, st return nothing; } -inline auto string::find(string_view source) const -> maybe { return _find<0, 0>(0, source); } -inline auto string::ifind(string_view source) const -> maybe { return _find<1, 0>(0, source); } -inline auto string::qfind(string_view source) const -> maybe { return _find<0, 1>(0, source); } -inline auto string::iqfind(string_view source) const -> maybe { return _find<1, 1>(0, source); } +inline auto string::find(string_view source) const -> maybe { return _find<0, 0>(0, source); } +inline auto string::ifind(string_view source) const -> maybe { return _find<1, 0>(0, source); } +inline auto string::qfind(string_view source) const -> maybe { return _find<0, 1>(0, source); } +inline auto string::iqfind(string_view source) const -> maybe { return _find<1, 1>(0, source); } -inline auto string::findFrom(int offset, string_view source) const -> maybe { return _find<0, 0>(offset, source); } -inline auto string::ifindFrom(int offset, string_view source) const -> maybe { return _find<1, 0>(offset, source); } +inline auto string::findFrom(s32 offset, string_view source) const -> maybe { return _find<0, 0>(offset, source); } +inline auto string::ifindFrom(s32 offset, string_view source) const -> maybe { return _find<1, 0>(offset, source); } -inline auto string::findNext(int offset, string_view source) const -> maybe { +inline auto string::findNext(s32 offset, string_view source) const -> maybe { if(source.size() == 0) return nothing; - for(int n = offset + 1; n < size(); n++) { + for(s32 n = offset + 1; n < size(); n++) { if(memory::compare(data() + n, size() - n, source.data(), source.size()) == 0) return n; } return nothing; } -inline auto string::ifindNext(int offset, string_view source) const -> maybe { +inline auto string::ifindNext(s32 offset, string_view source) const -> maybe { if(source.size() == 0) return nothing; - for(int n = offset + 1; n < size(); n++) { + for(s32 n = offset + 1; n < size(); n++) { if(memory::icompare(data() + n, size() - n, source.data(), source.size()) == 0) return n; } return nothing; } -inline auto string::findPrevious(int offset, string_view source) const -> maybe { +inline auto string::findPrevious(s32 offset, string_view source) const -> maybe { if(source.size() == 0) return nothing; - for(int n = offset - 1; n >= 0; n--) { + for(s32 n = offset - 1; n >= 0; n--) { if(memory::compare(data() + n, size() - n, source.data(), source.size()) == 0) return n; } return nothing; } -inline auto string::ifindPrevious(int offset, string_view source) const -> maybe { +inline auto string::ifindPrevious(s32 offset, string_view source) const -> maybe { if(source.size() == 0) return nothing; - for(int n = offset - 1; n >= 0; n--) { + for(s32 n = offset - 1; n >= 0; n--) { if(memory::icompare(data() + n, size() - n, source.data(), source.size()) == 0) return n; } return nothing; diff --git a/nall/string/format.hpp b/nall/string/format.hpp index c5bbc5612e..47f3a6ca79 100644 --- a/nall/string/format.hpp +++ b/nall/string/format.hpp @@ -6,15 +6,15 @@ namespace nall { //each {#} token will be replaced with its appropriate format parameter inline auto string::format(const nall::string_format& params) -> type& { - auto size = (int)this->size(); + auto size = (s32)this->size(); auto data = memory::allocate(size); memory::copy(data, this->data(), size); - int x = 0; + s32 x = 0; while(x < size - 2) { //2 = minimum tag length if(data[x] != '{') { x++; continue; } - int y = x + 1; + s32 y = x + 1; while(y < size - 1) { //-1 avoids going out of bounds on test after this loop if(data[y] != '}') { y++; continue; } break; @@ -32,19 +32,19 @@ inline auto string::format(const nall::string_format& params) -> type& { }; if(!isNumeric(&data[x + 1], &data[y - 1])) { x++; continue; } - uint index = toNatural(&data[x + 1]); + u32 index = toNatural(&data[x + 1]); if(index >= params.size()) { x++; continue; } - uint sourceSize = y - x; - uint targetSize = params[index].size(); - uint remaining = size - x; + u32 sourceSize = y - x; + u32 targetSize = params[index].size(); + u32 remaining = size - x; if(sourceSize > targetSize) { - uint difference = sourceSize - targetSize; + u32 difference = sourceSize - targetSize; memory::move(&data[x], &data[x + difference], remaining - difference); size -= difference; } else if(targetSize > sourceSize) { - uint difference = targetSize - sourceSize; + u32 difference = targetSize - sourceSize; data = (char*)realloc(data, size + difference); size += difference; memory::move(&data[x + difference], &data[x], remaining); @@ -86,14 +86,14 @@ template inline auto pad(const T& value, long precision, char padcha return buffer; } -inline auto hex(uintmax value, long precision, char padchar) -> string { +inline auto hex(u64 value, long precision, char padchar) -> string { string buffer; - buffer.resize(sizeof(uintmax) * 2); + buffer.resize(sizeof(u64) * 2); char* p = buffer.get(); - uint size = 0; + u32 size = 0; do { - uint n = value & 15; + u32 n = value & 15; p[size++] = n < 10 ? '0' + n : 'a' + n - 10; value >>= 4; } while(value); @@ -103,12 +103,12 @@ inline auto hex(uintmax value, long precision, char padchar) -> string { return buffer; } -inline auto octal(uintmax value, long precision, char padchar) -> string { +inline auto octal(u64 value, long precision, char padchar) -> string { string buffer; - buffer.resize(sizeof(uintmax) * 3); + buffer.resize(sizeof(u64) * 3); char* p = buffer.get(); - uint size = 0; + u32 size = 0; do { p[size++] = '0' + (value & 7); value >>= 3; @@ -119,12 +119,12 @@ inline auto octal(uintmax value, long precision, char padchar) -> string { return buffer; } -inline auto binary(uintmax value, long precision, char padchar) -> string { +inline auto binary(u64 value, long precision, char padchar) -> string { string buffer; - buffer.resize(sizeof(uintmax) * 8); + buffer.resize(sizeof(u64) * 8); char* p = buffer.get(); - uint size = 0; + u32 size = 0; do { p[size++] = '0' + (value & 1); value >>= 1; diff --git a/nall/string/markup/bml.hpp b/nall/string/markup/bml.hpp index 3bf05ddf68..52cc19947b 100644 --- a/nall/string/markup/bml.hpp +++ b/nall/string/markup/bml.hpp @@ -18,22 +18,22 @@ struct ManagedNode : Markup::ManagedNode { } //determine indentation level, without incrementing pointer - auto readDepth(const char* p) -> uint { - uint depth = 0; + auto readDepth(const char* p) -> u32 { + u32 depth = 0; while(p[depth] == '\t' || p[depth] == ' ') depth++; return depth; } //determine indentation level - auto parseDepth(const char*& p) -> uint { - uint depth = readDepth(p); + auto parseDepth(const char*& p) -> u32 { + u32 depth = readDepth(p); p += depth; return depth; } //read name auto parseName(const char*& p) -> void { - uint length = 0; + u32 length = 0; while(valid(p[length])) length++; if(length == 0) throw "Invalid node name"; _name = slice(p, 0, length); @@ -42,19 +42,19 @@ struct ManagedNode : Markup::ManagedNode { auto parseData(const char*& p, string_view spacing) -> void { if(*p == '=' && *(p + 1) == '\"') { - uint length = 2; + u32 length = 2; while(p[length] && p[length] != '\n' && p[length] != '\"') length++; if(p[length] != '\"') throw "Unescaped value"; _value = {slice(p, 2, length - 2), "\n"}; p += length + 1; } else if(*p == '=') { - uint length = 1; + u32 length = 1; while(p[length] && p[length] != '\n' && p[length] != '\"' && p[length] != ' ') length++; if(p[length] == '\"') throw "Illegal character in value"; _value = {slice(p, 1, length - 1), "\n"}; p += length; } else if(*p == ':') { - uint length = 1; + u32 length = 1; while(p[length] && p[length] != '\n') length++; _value = {slice(p, 1, length - 1).trimLeft(spacing, 1L), "\n"}; p += length; @@ -69,7 +69,7 @@ struct ManagedNode : Markup::ManagedNode { if(*(p + 0) == '/' && *(p + 1) == '/') break; //skip comments SharedNode node(new ManagedNode); - uint length = 0; + u32 length = 0; while(valid(p[length])) length++; if(length == 0) throw "Invalid attribute name"; node->_name = slice(p, 0, length); @@ -80,7 +80,7 @@ struct ManagedNode : Markup::ManagedNode { } //read a node and all of its child nodes - auto parseNode(const vector& text, uint& y, string_view spacing) -> void { + auto parseNode(const vector& text, u32& y, string_view spacing) -> void { const char* p = text[y++]; _metadata = parseDepth(p); parseName(p); @@ -88,7 +88,7 @@ struct ManagedNode : Markup::ManagedNode { parseAttributes(p, spacing); while(y < text.size()) { - uint depth = readDepth(text[y]); + u32 depth = readDepth(text[y]); if(depth <= _metadata) break; if(text[y][depth] == ':') { @@ -131,7 +131,7 @@ struct ManagedNode : Markup::ManagedNode { if(document.size() == 0) return; //empty document auto text = document.split("\n"); - uint y = 0; + u32 y = 0; while(y < text.size()) { SharedNode node(new ManagedNode); node->parseNode(text, y, spacing); @@ -153,7 +153,7 @@ inline auto unserialize(const string& markup, string_view spacing = {}) -> Marku return (Markup::SharedNode&)node; } -inline auto serialize(const Markup::Node& node, string_view spacing = {}, uint depth = 0) -> string { +inline auto serialize(const Markup::Node& node, string_view spacing = {}, u32 depth = 0) -> string { if(!node.name()) { string result; for(auto leaf : node) { diff --git a/nall/string/markup/find.hpp b/nall/string/markup/find.hpp index 5ba5dab154..b5add8652f 100644 --- a/nall/string/markup/find.hpp +++ b/nall/string/markup/find.hpp @@ -6,7 +6,7 @@ inline auto ManagedNode::_evaluate(string query) const -> bool { if(!query) return true; for(auto& rule : query.split(",")) { - enum class Comparator : uint { ID, EQ, NE, LT, LE, GT, GE }; + enum class Comparator : u32 { ID, EQ, NE, LT, LE, GT, GE }; auto comparator = Comparator::ID; if(rule.match("*!=*")) comparator = Comparator::NE; else if(rule.match("*<=*")) comparator = Comparator::LE; @@ -57,7 +57,7 @@ inline auto ManagedNode::_find(const string& query) const -> vector { auto path = query.split("/"); string name = path.take(0), rule; - uint lo = 0u, hi = ~0u; + u32 lo = 0u, hi = ~0u; if(name.match("*[*]")) { auto p = name.trimRight("]", 1L).split("[", 1L); @@ -77,7 +77,7 @@ inline auto ManagedNode::_find(const string& query) const -> vector { rule = p(1); } - uint position = 0; + u32 position = 0; for(auto& node : _children) { if(!node->_name.match(name)) continue; if(!node->_evaluate(rule)) continue; diff --git a/nall/string/markup/node.hpp b/nall/string/markup/node.hpp index fb25d97706..33ed459baf 100644 --- a/nall/string/markup/node.hpp +++ b/nall/string/markup/node.hpp @@ -59,29 +59,29 @@ struct Node { auto value(nall::string& target) const -> bool { if(shared) target = string(); return (bool)shared; } auto value(bool& target) const -> bool { if(shared) target = boolean(); return (bool)shared; } - auto value(int& target) const -> bool { if(shared) target = integer(); return (bool)shared; } - auto value(uint& target) const -> bool { if(shared) target = natural(); return (bool)shared; } - auto value(double& target) const -> bool { if(shared) target = real(); return (bool)shared; } + auto value(s32& target) const -> bool { if(shared) target = integer(); return (bool)shared; } + auto value(u32& target) const -> bool { if(shared) target = natural(); return (bool)shared; } + auto value(f64& target) const -> bool { if(shared) target = real(); return (bool)shared; } auto text() const -> nall::string { return value().strip(); } auto string() const -> nall::string { return value().strip(); } auto boolean() const -> bool { return text() == "true"; } - auto integer() const -> int64_t { return text().integer(); } - auto natural() const -> uint64_t { return text().natural(); } - auto real() const -> double { return text().real(); } + auto integer() const -> s64 { return text().integer(); } + auto natural() const -> u64 { return text().natural(); } + auto real() const -> f64 { return text().real(); } auto text(const nall::string& fallback) const -> nall::string { return bool(*this) ? text() : fallback; } auto string(const nall::string& fallback) const -> nall::string { return bool(*this) ? string() : fallback; } auto boolean(bool fallback) const -> bool { return bool(*this) ? boolean() : fallback; } - auto integer(int64_t fallback) const -> int64_t { return bool(*this) ? integer() : fallback; } - auto natural(uint64_t fallback) const -> uint64_t { return bool(*this) ? natural() : fallback; } - auto real(double fallback) const -> double { return bool(*this) ? real() : fallback; } + auto integer(s64 fallback) const -> s64 { return bool(*this) ? integer() : fallback; } + auto natural(u64 fallback) const -> u64 { return bool(*this) ? natural() : fallback; } + auto real(f64 fallback) const -> f64 { return bool(*this) ? real() : fallback; } auto setName(const nall::string& name = "") -> Node& { shared->_name = name; return *this; } auto setValue(const nall::string& value = "") -> Node& { shared->_value = value; return *this; } auto reset() -> void { shared->_children.reset(); } - auto size() const -> uint { return shared->_children.size(); } + auto size() const -> u32 { return shared->_children.size(); } auto prepend(const Node& node) -> void { shared->_children.prepend(node.shared); } auto append(const Node& node) -> void { shared->_children.append(node.shared); } @@ -94,17 +94,17 @@ struct Node { return false; } - auto insert(uint position, const Node& node) -> bool { + auto insert(u32 position, const Node& node) -> bool { if(position > size()) return false; //used > instead of >= to allow indexed-equivalent of append() return shared->_children.insert(position, node.shared), true; } - auto remove(uint position) -> bool { + auto remove(u32 position) -> bool { if(position >= size()) return false; return shared->_children.remove(position), true; } - auto swap(uint x, uint y) -> bool { + auto swap(u32 x, u32 y) -> bool { if(x >= size() || y >= size()) return false; return std::swap(shared->_children[x], shared->_children[y]), true; } @@ -117,7 +117,7 @@ struct Node { }); } - auto operator[](int position) -> Node { + auto operator[](s32 position) -> Node { if(position >= size()) return {}; return shared->_children[position]; } @@ -130,11 +130,11 @@ struct Node { auto operator*() -> Node { return {source.shared->_children[position]}; } auto operator!=(const iterator& source) const -> bool { return position != source.position; } auto operator++() -> iterator& { return position++, *this; } - iterator(const Node& source, uint position) : source(source), position(position) {} + iterator(const Node& source, u32 position) : source(source), position(position) {} private: const Node& source; - uint position; + u32 position; }; auto begin() const -> iterator { return iterator(*this, 0); } diff --git a/nall/string/markup/xml.hpp b/nall/string/markup/xml.hpp index b7557b52f6..6de2d32755 100644 --- a/nall/string/markup/xml.hpp +++ b/nall/string/markup/xml.hpp @@ -42,7 +42,7 @@ struct ManagedNode : Markup::ManagedNode { } //copy part of string from source document into target string; decode markup while copying - auto copy(string& target, const char* source, uint length) -> void { + auto copy(string& target, const char* source, u32 length) -> void { target.reserve(length + 1); #if defined(NALL_XML_LITERAL) @@ -105,7 +105,7 @@ struct ManagedNode : Markup::ManagedNode { //DOCTYPE if(!memory::compare(p, "(sizeof(uint) + size + 1); - ((uint*)_data)[0] = size; - memory::copy(_data + sizeof(uint), text, size); - _data[sizeof(uint) + size] = 0; + u32 size = strlen(text); + _data = memory::allocate(sizeof(u32) + size + 1); + ((u32*)_data)[0] = size; + memory::copy(_data + sizeof(u32), text, size); + _data[sizeof(u32) + size] = 0; } } string_pascal(const string& text) { if(text.size()) { - _data = memory::allocate(sizeof(uint) + text.size() + 1); - ((uint*)_data)[0] = text.size(); - memory::copy(_data + sizeof(uint), text.data(), text.size()); - _data[sizeof(uint) + text.size()] = 0; + _data = memory::allocate(sizeof(u32) + text.size() + 1); + ((u32*)_data)[0] = text.size(); + memory::copy(_data + sizeof(u32), text.data(), text.size()); + _data[sizeof(u32) + text.size()] = 0; } } @@ -32,16 +32,16 @@ struct string_pascal { } explicit operator bool() const { return _data; } - operator const char*() const { return _data ? _data + sizeof(uint) : nullptr; } - operator string() const { return _data ? string{_data + sizeof(uint)} : ""; } + operator const char*() const { return _data ? _data + sizeof(u32) : nullptr; } + operator string() const { return _data ? string{_data + sizeof(u32)} : ""; } auto operator=(const string_pascal& source) -> type& { if(this == &source) return *this; if(_data) { memory::free(_data); _data = nullptr; } if(source._data) { - uint size = source.size(); - _data = memory::allocate(sizeof(uint) + size); - memory::copy(_data, source._data, sizeof(uint) + size); + u32 size = source.size(); + _data = memory::allocate(sizeof(u32) + size); + memory::copy(_data, source._data, sizeof(u32) + size); } return *this; } @@ -64,12 +64,12 @@ struct string_pascal { auto data() const -> char* { if(!_data) return nullptr; - return _data + sizeof(uint); + return _data + sizeof(u32); } - auto size() const -> uint { + auto size() const -> u32 { if(!_data) return 0; - return ((uint*)_data)[0]; + return ((u32*)_data)[0]; } protected: diff --git a/nall/string/replace.hpp b/nall/string/replace.hpp index 49b0073f74..4912704fc1 100644 --- a/nall/string/replace.hpp +++ b/nall/string/replace.hpp @@ -6,14 +6,14 @@ template inline auto string::_replace(string_view from, string_view to, long limit) -> string& { if(limit <= 0 || from.size() == 0) return *this; - int size = this->size(); - int matches = 0; - int quoted = 0; + s32 size = this->size(); + s32 matches = 0; + s32 quoted = 0; //count matches first, so that we only need to reallocate memory once //(recording matches would also require memory allocation, so this is not done) { const char* p = data(); - for(int n = 0; n <= size - (int)from.size();) { + for(s32 n = 0; n <= size - (s32)from.size();) { if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } } if(_compare(p + n, size - n, from.data(), from.size())) { n++; continue; } @@ -27,7 +27,7 @@ inline auto string::_replace(string_view from, string_view to, long limit) -> st if(to.size() == from.size()) { char* p = get(); - for(int n = 0, remaining = matches, quoted = 0; n <= size - (int)from.size();) { + for(s32 n = 0, remaining = matches, quoted = 0; n <= size - (s32)from.size();) { if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } } if(_compare(p + n, size - n, from.data(), from.size())) { n++; continue; } @@ -41,10 +41,10 @@ inline auto string::_replace(string_view from, string_view to, long limit) -> st //left-to-right shrink else if(to.size() < from.size()) { char* p = get(); - int offset = 0; - int base = 0; + s32 offset = 0; + s32 base = 0; - for(int n = 0, remaining = matches, quoted = 0; n <= size - (int)from.size();) { + for(s32 n = 0, remaining = matches, quoted = 0; n <= size - (s32)from.size();) { if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } } if(_compare(p + n, size - n, from.data(), from.size())) { n++; continue; } @@ -66,10 +66,10 @@ inline auto string::_replace(string_view from, string_view to, long limit) -> st resize(size + matches * (to.size() - from.size())); char* p = get(); - int offset = this->size(); - int base = size; + s32 offset = this->size(); + s32 base = size; - for(int n = size, remaining = matches; n >= (int)from.size();) { //quoted reused from parent scope since we are iterating backward + for(s32 n = size, remaining = matches; n >= (s32)from.size();) { //quoted reused from parent scope since we are iterating backward if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n--; continue; } if(quoted) { n--; continue; } } if(_compare(p + n - from.size(), size - n + from.size(), from.data(), from.size())) { n--; continue; } diff --git a/nall/string/split.hpp b/nall/string/split.hpp index 8a127b9062..b7dbd9251e 100644 --- a/nall/string/split.hpp +++ b/nall/string/split.hpp @@ -8,11 +8,11 @@ inline auto vector::_split(string_view source, string_view find, long li if(limit <= 0 || find.size() == 0) return *this; const char* p = source.data(); - int size = source.size(); - int base = 0; - int matches = 0; + s32 size = source.size(); + s32 base = 0; + s32 matches = 0; - for(int n = 0, quoted = 0; n <= size - (int)find.size();) { + for(s32 n = 0, quoted = 0; n <= size - (s32)find.size();) { if constexpr(Quoted) { if(quoted && p[n] == '\\') { n += 2; continue; } if(p[n] == '\'' && quoted != 2) { quoted ^= 1; n++; continue; } diff --git a/nall/string/transform/cml.hpp b/nall/string/transform/cml.hpp index 1e3cf803c8..efbf95b773 100644 --- a/nall/string/transform/cml.hpp +++ b/nall/string/transform/cml.hpp @@ -33,7 +33,7 @@ struct CML { bool inMedia = false; bool inMediaNode = false; - auto parseDocument(const string& filedata, const string& pathname, uint depth) -> bool; + auto parseDocument(const string& filedata, const string& pathname, u32 depth) -> bool; }; inline auto CML::parse(const string& filename) -> string { @@ -49,7 +49,7 @@ inline auto CML::parse(const string& filedata, const string& pathname) -> string return state.output; } -inline auto CML::parseDocument(const string& filedata, const string& pathname, uint depth) -> bool { +inline auto CML::parseDocument(const string& filedata, const string& pathname, u32 depth) -> bool { if(depth >= 100) return false; //prevent infinite recursion auto vendorAppend = [&](const string& name, const string& value) { diff --git a/nall/string/transform/dml.hpp b/nall/string/transform/dml.hpp index bec0fbe6ca..f5bc64278e 100644 --- a/nall/string/transform/dml.hpp +++ b/nall/string/transform/dml.hpp @@ -39,9 +39,9 @@ struct DML { }; vector attributes; - auto parseDocument(const string& filedata, const string& pathname, uint depth) -> bool; - auto parseBlock(string& block, const string& pathname, uint depth) -> bool; - auto count(const string& text, char value) -> uint; + auto parseDocument(const string& filedata, const string& pathname, u32 depth) -> bool; + auto parseBlock(string& block, const string& pathname, u32 depth) -> bool; + auto count(const string& text, char value) -> u32; auto address(string text) -> string; auto escape(const string& text) -> string; @@ -71,7 +71,7 @@ inline auto DML::parse(const string& filename) -> string { return state.output; } -inline auto DML::parseDocument(const string& filedata, const string& pathname, uint depth) -> bool { +inline auto DML::parseDocument(const string& filedata, const string& pathname, u32 depth) -> bool { if(depth >= 100) return false; //attempt to prevent infinite recursion with reasonable limit auto blocks = filedata.split("\n\n"); @@ -79,7 +79,7 @@ inline auto DML::parseDocument(const string& filedata, const string& pathname, u return true; } -inline auto DML::parseBlock(string& block, const string& pathname, uint depth) -> bool { +inline auto DML::parseBlock(string& block, const string& pathname, u32 depth) -> bool { if(!block.stripRight()) return true; auto lines = block.split("\n"); @@ -128,7 +128,7 @@ inline auto DML::parseBlock(string& block, const string& pathname, uint depth) - //navigation else if(count(block, '-')) { state.output.append("