diff --git a/examples/asm/elmer/README.md b/examples/asm/elmer/README.md index b3408d93..633bb4f1 100644 --- a/examples/asm/elmer/README.md +++ b/examples/asm/elmer/README.md @@ -17,6 +17,9 @@ This directory contains a number of example programs and utilities for developin * rom-bare-buftest - A HuCARD ROM to compare a PC Engine emulator's buffered VDC reading with real PC Engine console hardware. +* rom-bare-clktest + - A HuCARD ROM to compare a PC Engine emulator's ADPCM playback rate with real PC Engine console hardware. + * rom-bare-dmatest - A HuCARD ROM to compare a PC Engine emulator's VDC SATB-DMA and VRAM-DMA timing with real PC Engine console hardware. diff --git a/examples/asm/elmer/include/bare-startup.asm b/examples/asm/elmer/include/bare-startup.asm index 658b1b0b..6c8dbdfb 100644 --- a/examples/asm/elmer/include/bare-startup.asm +++ b/examples/asm/elmer/include/bare-startup.asm @@ -145,6 +145,8 @@ bare_hw_reset: sei ; Disable interrupts. lda #$F8 tam1 + stz IFU_IRQ_MSK ; Disable IFU interrupts. + stz TIMER_CR ; HW reset already does these, stz IRQ_ACK ; but this may be a reset from stz IRQ_MSK ; software (i.e. joypad). diff --git a/examples/asm/elmer/rom-bare-clktest/Makefile b/examples/asm/elmer/rom-bare-clktest/Makefile new file mode 100644 index 00000000..d7af6dce --- /dev/null +++ b/examples/asm/elmer/rom-bare-clktest/Makefile @@ -0,0 +1,11 @@ +all: clktest.pce + +include ../Make_ex.inc + +AFLAGS ?= --newproc --strip -m -l 2 -S -gA + +SRC_INC = pceas.inc pcengine.inc joypad.asm tty.asm vce.asm vdc.asm +SRC_OVL = clktest.asm + +clktest.pce: $(SRC_OVL) $(SRC_INC) + $(AS) $(AFLAGS) --raw clktest.asm diff --git a/examples/asm/elmer/rom-bare-clktest/clktest.asm b/examples/asm/elmer/rom-bare-clktest/clktest.asm new file mode 100644 index 00000000..08c8ea26 --- /dev/null +++ b/examples/asm/elmer/rom-bare-clktest/clktest.asm @@ -0,0 +1,641 @@ +; *************************************************************************** +; *************************************************************************** +; +; clktest.asm +; +; ADPCM playback clock tester using the basic HuCARD startup library code. +; +; Copyright John Brandwood 2026. +; +; Distributed under the Boost Software License, Version 1.0. +; (See accompanying file LICENSE_1_0.txt or copy at +; http://www.boost.org/LICENSE_1_0.txt) +; +; *************************************************************************** +; *************************************************************************** +; +; The purpose of this example is to compare the accuracy of emulation with +; real console hardware. +; +; This checks how many CPU cycles it takes to execute a TIA instruction to +; transfer data to the VDC while the screen is active. +; +; Because of the VDC's round-robin method of VDC memory access, and its need +; to read background data during the line's display, the CPU is subject to a +; lot of delays that aren't taken into account by the documented cycle times +; of (17 + 6n). +; +; The actual clock cycles taken depends upon the screen resolution, the time +; that the transfer is started, and the number of sprites on the line. +; +; OUCH! +; +; *************************************************************************** +; *************************************************************************** +; +; The PC Engine's memory map is set to ... +; +; MPR0 = bank $FF : PCE hardware +; MPR1 = bank $F8 : PCE RAM with Stack & ZP +; MPR2 = bank $00 : HuCARD ROM +; MPR3 = bank $01 : HuCARD ROM +; MPR4 = bank $02 : HuCARD ROM +; MPR5 = bank $03 : HuCARD ROM +; MPR6 = bank $04 : HuCARD ROM +; MPR7 = bank $00 : HuCARD ROM with the startup code and IRQ vectors. +; +; *************************************************************************** +; *************************************************************************** + + + ; + ; Create some equates for a very generic VRAM layout, with a + ; 64*32 BAT, followed by the SAT, then followed by the tiles + ; for the ASCII character set. + ; + ; This uses the first 8KBytes of VRAM ($0000-$0FFF). + ; + +BAT_LINE = 64 +BAT_SIZE = 64 * 32 +SAT_ADDR = BAT_SIZE ; SAT takes 16 tiles of VRAM. +CHR_ZERO = BAT_SIZE / 16 ; 1st tile # after the BAT. +CHR_0x10 = CHR_ZERO + 16 ; 1st tile # after the SAT. +CHR_0x20 = CHR_ZERO + 32 ; ASCII ' ' CHR tile #. + + .list + .mlist + + include "bare-startup.asm" ; No "CORE(not TM)" library! + + include "common.asm" ; Common helpers. + include "vdc.asm" ; Useful VDC routines. + include "font.asm" ; Useful font routines. + include "joypad.asm" ; Joypad routines. + include "tty.asm" ; Useful TTY print routines. + + + +; *************************************************************************** +; *************************************************************************** +; +; Constants and Variables. +; + +ADPCM_SAMPLES = 250000 ; Number of samples. +ADPCM_BYTES = (ADPCM_SAMPLES / 2) ; Number of bytes. +ADPCM_BLOCKS = ADPCM_BYTES >> 13 ; Number of 8192 byte chunks. +ADPCM_EXTRA = ADPCM_BYTES - (ADPCM_BLOCKS << 13) + + .zp + +loop_count ds 2 +addr_value ds 2 +cycle_count ds 4 + + + +; *************************************************************************** +; *************************************************************************** +; +; It's a bank of NOPs for timing, plus a 16-bit loop counter. +; + + .data + + align $2000 + +delay_loop: ds $2000, $EA + +next_delay: + + + db $1A ; INC A + db $D0,$01 ; BNE jump_delay + db $E8 ; INX +jump_delay: db $4C,$00,$40 ; JMP $4000 + + + +; *************************************************************************** +; *************************************************************************** +; +; bare_main - This is executed after startup library initialization. +; + + .code + + ; Reset the IRQ hooks when switching resolution. + +bare_main: jsr bare_clr_hooks + + ; Turn the display off and initialize the screen mode. + + call init_256x224 ; Initialize VDC & VRAM. + + ; Upload the font to VRAM. + + stz <_di + 0 ; Destination VRAM address. + lda #>(CHR_0x10 * 16) + sta <_di + 1 + + lda #$FF ; Put font in colors 4-7, + sta <_al ; so bitplane 2 = $FF and + stz <_ah ; bitplane 3 = $00. + + lda #16 + 96 ; 16 graphics + 96 ASCII. + sta <_bl + + lda #my_font + sta <_bp + 1 + ldy #^my_font + + call dropfnt8x8_vdc ; Upload font to VRAM. + + ; Upload the palette data to the VCE. + + stz <_al ; Start at palette 0 (BG). + lda #4 ; Copy 4 palettes of 16 colors. + sta <_ah + lda #screen_pal + sta <_bp + 1 + ldy #^screen_pal + call load_palettes ; Add to the palette queue. + + lda #16 ; Start at palette 16 (SPR). + sta <_al + lda #4 ; Copy 4 palettes of 16 colors. + sta <_ah + lda #screen_pal + sta <_bp + 1 + ldy #^screen_pal + call load_palettes ; Add to the palette queue. + + call xfer_palettes ; Transfer queue to VCE now. + + ; Turn on the BG & SPR layers, then wait for a soft-reset. + + call set_dspon ; Enable background. + + ; Display the test name. + + PRINTF "\e<\eX1\eY1\eP0**PC ENGINE ADPCM SPEED TEST**\eP1\eX1\eY3\eP1This takes roughly 20 seconds.\eP0" + +; PRINTF "\e<\eX1\eY1\eP0**PC ENGINE ADPCM SPEED TEST**\eP1\eX1\eY3\x1E\x1F\eP0:Del\eP1 \x1C\x1D\eP0:Siz\eP1 SEL\eP0:Mode\eP1 RUN\eP0:Spr\eP0" + + ; Bank in 32KB of NOP instructions followed by a JMP $4000. + + lda #^delay_loop + tam2 + tam3 + tam4 + tam5 + lda #^next_delay + tam6 + + stz = 8192 + + adc