;license:MIT ;(c) 2018 by 4am ; ; User interface - views and paint routines for credits screen ; ; Public functions ; - CreditsDialog ; ID_CREDITS = 0 ;------------------------------------------------------------------------------ ; CreditsDialog ; call WeeGUI to create and paint credits screen, and run to completion ; ; in: WeeGUI initialized ; out: exits via MainScreen ; all registers and flags clobbered ;------------------------------------------------------------------------------ CreditsDialog ldx #$FF txs jsr LoadCredits ; fetch contents from file jsr ClearPendingInput @creditsOuterLoop lda #5 sta currentSection @creditsInnerLoop lda #$20 ; fade to white jsr TextFizzle jsr @ExitOnAnyInput lda #' ' ; fade to black jsr TextFizzle jsr @ExitOnAnyInput ldx currentSection ; set up border frame lda kCreditsTop,x sta kViewCreditsTop lda kCreditsHeight,x sta kViewCreditsVisibleHeight sta kViewCreditsHeight jsr HardResetWeeGUI ldx #WGCreateView +LDADDR kViewCredits +STAY PARAM0 jsr WeeGUI ; create border frame ldx #WGSelectView lda #ID_CREDITS jsr WeeGUI ldx #WGPaintView jsr WeeGUI ; paint border frame jsr PaintCredits ; paint text jsr @ExitOnAnyInput ldx currentSection ; wait a variable period of time lda kCreditsHeight,x ; based on the number of lines of text asl asl tay - lda #0 jsr WAIT jsr @ExitOnAnyInput dey bpl - dec currentSection lda currentSection bpl @creditsInnerLoop bra @creditsOuterLoop @ExitOnAnyInput jsr AnyKeyOrClick bcs @exit rts @exit jmp MainScreen ;------------------------------------------------------------------------------ ; internal functions ;------------------------------------------------------------------------------ ; LoadCredits ; load credits from file and convert it for use by WeeGUI ; ; NOTE: this routine assumes there are no more than 6 sections of credits. ; Section 1 starts at the beginning of the file. ; Sections 1-5 end with the '~' character. ; Sections 2-6 start at the first non-0x0D character after the '~' delimiter. ; Section 6 ends with '[' character (not '~') ; Text is stored on disk with high bit off. ; Each line must be no more than 40 characters. ; Parsing would obviously be easier if these constraints were different, ; but I like the way the file looks. ; ; in: WeeGUI initialized ; out: exits to caller ; all registers and flags clobbered ;------------------------------------------------------------------------------ LoadCredits jsr LoadFile ; load credits file at $2000 !word kCreditsFilename !word kCreditsBuffer !word kProDOSFileBuffer +LDADDR kCreditsBuffer +STAY $FE ; ($FE) points to start of data buffer ldy #$00 ; index into ($FE) pointing to current character ldx #$0C ; (= 6 x 2) index into creditsSectionPointers array lda ($FE) bra @saveSectionPointer @convertSectionLoop jsr IncAndGetChar @convertSectionNoInc cmp #$7E ; '~' ends the section beq @skipSectionDelimiter cmp #$5B ; '[' ends the parsing beq @exit cmp #$0D ; CR -> 0x00 (WeeGUI wants null-terminated strings) beq @null ora #$80 ; all other characters -> set high bit +HIDE_NEXT_2_BYTES @null lda #$00 sta ($FE),y bra @convertSectionLoop ; We found the start of a new section, so skip to the first character on the next line @skipSectionDelimiter jsr IncAndGetChar cmp #$0D ; CR beq @skipSectionDelimiter ; We are at the start of a section, so save this address in the creditsSectionPointers array @saveSectionPointer pha tya clc adc $FE sta creditsSectionPointers-2,x lda $FF bcc + inc + sta creditsSectionPointers-1,x pla dex dex bpl @convertSectionNoInc @exit rts ;------------------------------------------------------------------------------ ; PaintCredits ; paint one section of credits on the screen ; ; in: WeeGUI initialized ; out: exits to caller ; all registers and flags clobbered ;------------------------------------------------------------------------------ PaintCredits lda currentSection asl tax lda creditsSectionPointers,x sta $FE lda creditsSectionPointers+1,x sta $FF ; ($FE) points to start of data buffer ldy #0 ; index into ($FE) pointing to current character stz @VTAB ; line number within WeeGUI view @printLine lda #1 sta PARAM0 inc @VTAB @VTAB=*+1 lda #$FD sta PARAM1 ldx #WGSetCursor jsr WeeGUI ; set cursor to start of this line tya clc adc $FE sta PARAM0 lda $FF bcc + inc + sta PARAM1 ; calculate exact start of text for this line lda (PARAM0) ; skip blank lines beq @skipNull ldx #WGPrint ; otherwise print it jsr WeeGUI @skipToNextLine jsr IncAndGetChar bne @notNull @skipNull jsr IncAndGetChar bra @printLine @notNull cmp #$7E ; '~' ends section beq @exit cmp #$5B ; '[' ends section bne @skipToNextLine @exit rts ;------------------------------------------------------------------------------ ; internal data kCreditsFilename !byte 11 !raw "CREDITS.TXT" currentSection ; used by PaintCredits !byte $FD creditsSectionPointers ; [array of word] address of start of each page of credits !word $FDFD !word $FDFD !word $FDFD !word $FDFD !word $FDFD !word $FDFD kCreditsTop ; [array of byte] top row to draw border for each section of credits !byte 7 ; note: stored here in reverse order compared to the credits file !byte 2 !byte 5 !byte 8 !byte 8 !byte 7 kCreditsHeight ; [array of byte] height of bounding box for each section of credits !byte 10 ; note: stored here in reverse order compared to the credits file !byte 20 !byte 14 !byte 8 !byte 9 !byte 10 kViewCredits !byte ID_CREDITS ; view ID !byte 1 ; style !byte 19 ; left kViewCreditsTop !byte $FD ; top (SMC) !byte 42 ; visible width kViewCreditsVisibleHeight !byte $FD ; visible height (SMC) !byte 42 ; width kViewCreditsHeight !byte $FD ; height (SMC)