million-perfect-letters/src/ui.message.a

74 lines
1.8 KiB
Plaintext

;license:MIT
;(c) 2020 by 4am
;
; utility functions for showing modeless auto-disappearing messages during play
;
; Public functions:
; - SetNextMessage
; - ShowMessage
; - HideMessage
;
showingMessage ; [byte][private]
!byte 0 ; 1 = currently showing message, 0 = not
currentMessage ; [private]
!byte 40
!raw " "
noMessage ; [private]
!byte 40
!raw " "
SetNextMessage
; copies a new message into private buffer
; (does not display the new message on screen)
; if new message is shorter than max length, it will be centered
; in: A/Y points to length-prefixed string
+ST16 $FE
ldy noMessage
- lda noMessage, y
sta currentMessage, y
dey
bpl -
ldy #0
lda ($FE), y ; A = string length
tay
clc
adc #1
lsr
sta $FD
lda currentMessage
lsr
clc
adc $FD
tax
- lda ($FE), y
sta currentMessage, x
dex
dey
bne -
rts
HideMessage
; out: preserves A
; safe to call multiple times, does nothing if no message is showing
pha
lda showingMessage
beq +
+PRINT_AT noMessage, 7, 0
lda #0
sta showingMessage
+ pla
rts
ShowMessage
; should really only call once
; will clear message before showing the new one, so there may be a small flicker
jsr HideMessage
+PRINT_AT currentMessage, 7, 0
SetShowingMessage
lda #1
sta showingMessage
rts