; peislam.s - GetTick and ReadBParam trampolines for the IIgs.
;
; GAS syntax for the llvm-mos w65816 toolchain. The old PEI-slam present
; logic was rolled into iigsBlitStageToShr in joeyDraw; only the two
; toolbox trampolines remain.
;
; C ABI (llvm-mos w65816): caller has M=I=16. A uint16_t return value
; is left in A, which matches the toolbox dispatcher's word result, so
; these wrappers need no register shuffling beyond the pop.

	.text

; ----------------------------------------------------------------
; uint16_t iigsGetTickWord(void)
;
; Calls Misc Toolset GetTick ($2503) and returns the low 16 bits of
; the 32-bit tick counter. The system increments this counter from the
; actual VBL hardware interrupt, so it stays accurate regardless of
; caller polling rate -- C-side polling of $C019 missed transitions
; for any op over ~1 ms.
;
; GetTick output convention: caller pushes 4 bytes of output space, the
; tool dispatcher writes the LongWord into them. We pull the low 16
; bits into A (the return value) and discard the high 16 into X.
; ----------------------------------------------------------------
	.section .text.iigsGetTickWord,"ax"
	.globl iigsGetTickWord
iigsGetTickWord:
	pha                 ; output space high word
	pha                 ; output space low word
	ldx #0x2503         ; _GetTick
	jsl 0xe10000
	pla                 ; A = low 16 bits (return value)
	plx                 ; discard high 16 bits
	rtl

; ----------------------------------------------------------------
; uint16_t iigsReadHzParam(void)
;
; Reads battery RAM parameter hrtz50or60 ($1D) via _ReadBParam ($0C03)
; and returns the raw value: 0 = NTSC (60 Hz), 1 = PAL (50 Hz).
;
; GetTick fires from the hardware VBL ISR, so its rate matches the
; video field rate -- 60 Hz on NTSC, 50 Hz on PAL. jlpFrameHz must
; report whichever this machine actually runs so wall-clock math
; (frames * 1000 / jlpFrameHz) is correct on both.
; ----------------------------------------------------------------
	.section .text.iigsReadHzParam,"ax"
	.globl iigsReadHzParam
iigsReadHzParam:
	pha                 ; output space (Word)
	pea 0x001d          ; hrtz50or60 parameter ID
	ldx #0x0c03         ; _ReadBParam
	jsl 0xe10000
	pla                 ; A = result (return value)
	rtl
