;License:MIT ;(c) 2018-2020 by 4am ; ; functions for managing which HGR page is showing, and doing things on the other one ; ; - GetOffscreenAddress ; - LoadTitleOffscreen ; - LoadCoverOffscreen ; - LoadHelpOffscreen ; - LoadGameTitleOffscreen ; - ResyncPage ; - ShowOtherPage ; - ToggleOffscreenPage ; - ClearScreens ; - ClearOffscreen ; - ClearHGR1 ; - ClearMem ; ; Public variables ; - OffscreenPage ; ;------------------------------------------------------------------------------ ; GetOffscreenAddress ; get high byte of HGR page that is currently not showing ; ; in: none ; out: A = high byte of offscreen HGR page (#$20 or #$40) ; preserves X/Y ;------------------------------------------------------------------------------ GetOffscreenAddress Ignore = * + 1 ; discard IRQs, particularly on the IIc lda #$40 OffscreenPage = * + 1 bne + ; SMC ; 0 = currently showing HGR page 2 ; (so offscreen is page 1 @ $2000) ; 1 = currently showing HGR page 1 ; (so offscreen is page 2 @ $4000) + lsr rts ;------------------------------------------------------------------------------ ; LoadTitleOffscreen ; load title screen in the HGR page that is currently not showing ; ; in: none ; out: all flags and registers clobbered ;------------------------------------------------------------------------------ LoadTitleOffscreen lda #kCoverFile ; all of these are on the same page !byte $00 + !byte $FD ; SMC rts LoadGameTitleOffscreen ; in: gGameToLaunch = index into gSearchStore (word) jsr GetGameToLaunch +ST16 @fname bit MachineStatus ; if < 128K, don't bother checking for DHGR title bvc @hgr jsr okvs_get_current jsr okvs_get_current_PTR_is_already_set ; (PTR) -> length-prefixed game info bitfield ; Y = 0 iny ; Y = 1 lda (PTR), y ; A = game info bitfield ;;and #HAS_DHGR_TITLE bmi @dhgr @hgr jsr ForceHGRMode jsr GetOffscreenAddress sta @addrhi jsr LoadFile !word kHGRTitleDirectory @fname !word $FDFD ; SMC !byte $00 @addrhi !byte $FD ; SMC rts @dhgr jsr BlankDHGR +LD16 @fname +ST16 + jsr LoadDHRFile !word kDHGRTitleDirectory + !word $FDFD rts ;------------------------------------------------------------------------------ ; ClearScreens ; clear and display text screen and then clear both hires screens ; (in this order so that the erasing isn't visible) ; ; in: none ; out: $400..$7FF and $2000..$5FFF cleared ;------------------------------------------------------------------------------ ClearScreens jsr Home lda #$20 ; clear both hi-res pages ldx #$40 ; to flash previous bits of the launcher UI) bne ClearMem ; always ;------------------------------------------------------------------------------ ; ClearOffscreen ; clear $2000..$3FFF or $4000..$5FFF, depending on which HGR page is not ; visible right now ; does not change HGR mode ; ; in: none ; out: $2000..$3FFF or $4000..$5FFF cleared ; A = #$80 ; X = #$00 ; Y = #$00 ; Z = 1 ;------------------------------------------------------------------------------ ClearOffscreen jsr GetOffscreenAddress +HIDE_NEXT_2_BYTES ClearHGR1 lda #$20 ; note to self: LDX #$20 can't move here ldx #$20 ClearMem ldy #$2C ; BIT bne + ; always ;------------------------------------------------------------------------------ ; CopyHGR ; ; in: source and destination page pointers set ; out: all registers clobbered ; 8kb memory region duplicated ;------------------------------------------------------------------------------ CopyHGR ldx #$20 ldy #$B9 ; LDY + sty PageFrom sta PageTo+2 lda #$00 ClearGR ldy #0 PageFrom lda $FD00,y ; SMC PageTo sta $FD00,y ; SMC iny bne PageFrom inc PageFrom+2 inc PageTo+2 dex bne PageFrom sta READMAINMEM rts ResyncPage jsr ToggleOffscreenPage ; /!\ execution falls through here to ShowOtherPage ;------------------------------------------------------------------------------ ; ShowOtherPage ; switch to the HGR page that is not currently showing ; ; in: none ; out: A = new value of OffscreenPage ; preserves X/Y ;------------------------------------------------------------------------------ ShowOtherPage jsr ToggleOffscreenPage bne + bit PAGE2 ; show page 2 rts + bit PAGE1 ; show page 1 rts ;------------------------------------------------------------------------------ ; ToggleOffscreenPage ; switch the internal variable that tracks which HGR page is showing ; (does not affect screen) ; ; in: none ; out: A = new value of OffscreenPage ; preserves X/Y ;------------------------------------------------------------------------------ ToggleOffscreenPage lda OffscreenPage eor #$01 sta OffscreenPage rts