diff --git a/ReadMe.md b/ReadMe.md index c78b798..d793491 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -6,6 +6,8 @@ Known issues - Positive scroll values unsupported - Hitting Reset in app that uses windows and desktop (no mouse needed) seems to mess up screen holes for Disk II - Mashing a button with mouse in Applesoft will cause Undefined Statement error +- Repainting a view while the mouse cursor is on it will cause artifacts when mouse moves +- Quitting sometimes leaves BASIC in inverted text mode To Do: diff --git a/WeeGUI_MLI.s b/WeeGUI_MLI.s index 8fcbd5b..d3353f6 100644 --- a/WeeGUI_MLI.s +++ b/WeeGUI_MLI.s @@ -41,25 +41,24 @@ WGStrokeRect = 16 WGFancyRect = 18 WGPaintView = 20 WGViewPaintAll = 22 -WGEraseView = 24 -WGEraseViewContents = 26 -WGCreateView = 28 -WGCreateCheckbox = 30 -WGCreateButton = 32 -WGViewSetTitle = 34 -WGViewSetAction = 36 -WGSelectView = 38 -WGViewFromPoint = 40 -WGViewFocus = 42 -WGViewUnfocus = 44 -WGViewFocusNext = 46 -WGViewFocusPrev = 48 -WGViewFocusAction = 50 -WGPendingViewAction = 52 -WGPendingView = 54 -WGScrollX = 56 -WGScrollXBy = 58 -WGScrollY = 60 -WGScrollYBy = 62 -WGEnableMouse = 64 -WGDisableMouse = 66 +WGEraseViewContents = 24 +WGCreateView = 26 +WGCreateCheckbox = 28 +WGCreateButton = 30 +WGViewSetTitle = 32 +WGViewSetAction = 34 +WGSelectView = 36 +WGViewFromPoint = 38 +WGViewFocus = 40 +WGViewUnfocus = 42 +WGViewFocusNext = 44 +WGViewFocusPrev = 46 +WGViewFocusAction = 48 +WGPendingViewAction = 50 +WGPendingView = 52 +WGScrollX = 54 +WGScrollXBy = 56 +WGScrollY = 58 +WGScrollYBy = 60 +WGEnableMouse = 62 +WGDisableMouse = 64 diff --git a/applesoft.s b/applesoft.s index 7c67648..2bd0633 100644 --- a/applesoft.s +++ b/applesoft.s @@ -395,7 +395,7 @@ WGAmpersand_WINDW: CALL16 WGCreateView,WGAmpersandCommandBuffer - jsr WGEraseView + jsr WGEraseViewContents jsr WGPaintView jsr WGBottomCursor rts @@ -809,16 +809,6 @@ WGAmpersand_PNT: rts -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; WGAmpersand_UNPNT -; Erases the selected view -; &UNPNT -WGAmpersand_UNPNT: - jsr WGEraseView - jsr WGBottomCursor - rts - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; WGAmpersand_PNTA ; Repaints all views @@ -1028,9 +1018,6 @@ WG_STACKPTR: ; A place to save the stack pointer for tricky Applesoft manipulati WG_KEYBUFFER: ; A phony string buffer for non-blocking GET .byte 0 -WG_GOSUB: ; Set if a gosub was generated by a view action -.byte 0 - ; Jump table for ampersand commands. ; Each row is 8 bytes (5 for name, NULL terminator, 2 for address) @@ -1107,9 +1094,6 @@ WGAmpersandCommandTable: .byte "PNT",0,0,0 .addr WGAmpersand_PNT -.byte "UNPNT",0 -.addr WGAmpersand_UNPNT - .byte "PNTA",0,0 .addr WGAmpersand_PNTA diff --git a/gui.s b/gui.s index 4ee6793..70520f7 100644 --- a/gui.s +++ b/gui.s @@ -50,7 +50,6 @@ WGEntryPointTable: .addr WGFancyRect .addr WGPaintView .addr WGViewPaintAll -.addr WGEraseView .addr WGEraseViewContents .addr WGCreateView .addr WGCreateCheckbox @@ -81,7 +80,7 @@ WGInit: SAVE_AXY jsr WG80 - jsr WGInitApplesoft +; jsr WGInitApplesoft ldy #15 ; Clear our block allocators WGInit_clearMemLoop: @@ -128,7 +127,7 @@ WG80: .include "rects.s" .include "views.s" .include "mouse.s" -.include "applesoft.s" +;.include "applesoft.s" .include "memory.s" diff --git a/guidemo.dsk b/guidemo.dsk index 35b3b59..dc61c27 100644 Binary files a/guidemo.dsk and b/guidemo.dsk differ diff --git a/guidemo.s b/guidemo.s index c8ac322..dc795e0 100644 --- a/guidemo.s +++ b/guidemo.s @@ -46,6 +46,8 @@ main: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Show off some WeeGUI features + ;jmp tortureTestPrint + ;jmp tortureTestRects ldx #WGClearScreen jsr WeeGUI @@ -194,61 +196,6 @@ testCallback: -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -.if 0 - ;jmp tortureTestPrint - ;jmp tortureTestRects - - jsr WGDesktop - - CALL16 WGCreateView,testView - CALL16 WGViewSetTitle,testTitle0 - CALL16 WGCreateCheckbox,testCheck - CALL16 WGCreateButton,testButton1 - CALL16 WGCreateButton,testButton2 - - jsr WGViewPaintAll - - lda #0 - jsr WGSelectView - -; ldx #5 -; ldy #0 -; jsr WGSetCursor - -; lda #0 -; jsr WGScrollX - -; lda #-17 -; jsr WGScrollY - -; jsr testPaintContents - - jsr WGEnableMouse - - -;; - jsr WGNormal - lda #10 - sta PARAM0 - lda #15 - sta PARAM1 - jsr WGSetCursor - CALL16 WGPrint,testStr - - bra testPaintContents_done -;; - - -testCallback: - jsr $ff3a - rts - - rts - -.endif - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bloadCmdLine: diff --git a/memory.s b/memory.s index 7c5c69c..56ef2a0 100644 --- a/memory.s +++ b/memory.s @@ -57,6 +57,9 @@ WG_FOCUSVIEW: WG_PENDINGACTIONVIEW: .byte 0 +WG_GOSUB: ; Set if an Applesoft gosub was generated by a view action +.byte 0 + WG_VIEWCLIP: ; X0,Y0,X1,Y1. Edges of current window, in view space, right span .byte 0,0,0,0,0 diff --git a/painting.s b/painting.s index 00f749e..551cb07 100644 --- a/painting.s +++ b/painting.s @@ -84,11 +84,11 @@ WGDesktop_charLoop: ; WGPlot ; Plots a character at global cursor position (assumes 80 cols) ; A: Character to plot (Apple format) -; Side effects: Clobbers S0, BASL,BASH +; Side effects: Clobbers BASL,BASH ; WGPlot: - sta SCRATCH0 SAVE_XY + pha ldx WG_CURSORY lda TEXTLINES_L,x ; Compute video memory address of point @@ -110,13 +110,13 @@ WGPlot: bne WGPlot_xOdd SETSWITCH PAGE2ON ; Plot the character - lda SCRATCH0 + pla sta (BASL) jmp WGPlot_done WGPlot_xOdd: SETSWITCH PAGE2OFF ; Plot the character - lda SCRATCH0 + pla sta (BASL) WGPlot_done: diff --git a/unit_test.s b/unit_test.s index 9c9d585..390b5be 100644 --- a/unit_test.s +++ b/unit_test.s @@ -8,7 +8,7 @@ ; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved. ; -.if 0 + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; tortureTestPrint ; Prints strings in a range of positions and scrolling offsets @@ -19,18 +19,25 @@ ; Delta X ; Delta Y tortureTestPrint: - jsr WGClearScreen + ldx #WGClearScreen + jsr WeeGUI lda #0 ; Initialize - jsr WGScrollX - jsr WGScrollY + ldx #WGScrollX + jsr WeeGUI + + ldx #WGScrollY + jsr WeeGUI tortureTestPrint_init: - CALL16 WGCreateView,testPrintView + WGCALL16 WGCreateView,testPrintView lda #0 - jsr WGSelectView - jsr WGPaintView + ldx #WGSelectView + jsr WeeGUI + + ldx #WGPaintView + jsr WeeGUI lda #0 pha @@ -47,7 +54,8 @@ tortureTestPrint_loop: lda #0 ; Initialize sta PARAM0 sta PARAM1 - jsr WGSetCursor + ldx #WGSetCursor + jsr WeeGUI plx inx ; Grab current delta X @@ -73,8 +81,11 @@ tortureTestPrint_flipDeltaX: inx tortureTestPrint_continueX: + phx lda $0100,x - jsr WGScrollX ; Apply current X scroll + ldx #WGScrollX ; Apply current X scroll + jsr WeeGUI + plx dex dex dex @@ -101,21 +112,29 @@ tortureTestPrint_flipDeltaY: inx tortureTestPrint_continueY: + phx lda $0100,x - jsr WGScrollY + ldx #WGScrollY + jsr WeeGUI + plx dex dex tortureTestPrint_print: - VBL_SYNC - jsr WGEraseViewContents +; VBL_SYNC + phx + ldx #WGEraseViewContents + jsr WeeGUI - CALL16 WGPrint,unitTestStr + WGCALL16 WGPrint,unitTestStr - jsr WGPrint ; Do it again + ldx #WGPrint ; Do it again + jsr WeeGUI ; jmp tortureTestPrint_lock - jsr delayShort + jsr delay + + plx jmp tortureTestPrint_loop tortureTestPrint_reset: @@ -126,7 +145,7 @@ tortureTestPrint_reset: tortureTestPrint_lock: jmp tortureTestPrint_lock -.endif + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; tortureTestRects @@ -284,7 +303,7 @@ tortureTestRectsOddDone: -delayShort: +delayShort: ; ~1/30 sec pha phx phy @@ -312,8 +331,38 @@ delayShortInner: + +delay: ; ~1 sec + pha + phx + phy + + ldy #$ce ; Loop a bunch +delayOuter: + ldx #$ff +delayInner: + nop + nop + nop + nop + nop + nop + nop + dex + bne delayInner + dey + bne delayOuter + + ply + plx + pla + rts + + + + testPrintView: - .byte "000F061E0A287E" ; 0, 7,3,62,19,75,126 + .byte 0,0,15,6,30,10,40,126 unitTestStr: .byte "This is a test of the emergency broadcast system. If this had been a real emergency, you would be dead now. Amusingly, it can be noted that if this had been a real emergency, and you were now a steaming pile of ash, there would of course be nobody.",0; to read this message. That begs any number",0; of extistential questions about this very text.",0 diff --git a/utility.s b/utility.s index 18ed863..6e116a4 100644 --- a/utility.s +++ b/utility.s @@ -6,34 +6,6 @@ ; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved. ; -.if 0 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; delay -; Sleeps for ~1 second -; -delay: - SAVE_AXY - - ldy #$ce ; Loop a bunch -delayOuter: - ldx #$ff -delayInner: - nop - nop - nop - nop - nop - nop - nop - dex - bne delayInner - dey - bne delayOuter - - RESTORE_AXY - rts -.endif - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; delayShort diff --git a/views.s b/views.s index c46e97b..03abaa9 100644 --- a/views.s +++ b/views.s @@ -26,8 +26,7 @@ ; WGCreateView: SAVE_AXY - SAVE_ZPS - + ldy #0 lda (PARAM0),y ; Find our new view record pha ; Cache view ID so we can select when we're done @@ -44,60 +43,44 @@ WGCreateView: iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen X - inx + sta WG_VIEWRECORDS+0,x ; Screen X iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen Y - inx + sta WG_VIEWRECORDS+1,x ; Screen Y iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen Width - inx + sta WG_VIEWRECORDS+2,x ; Screen Width iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen Height - inx + sta WG_VIEWRECORDS+3,x ; Screen Height pla - sta WG_VIEWRECORDS,x ; Style - inx + sta WG_VIEWRECORDS+4,x ; Style - lda #0 ; Initialize scrolling - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x - inx + stz WG_VIEWRECORDS+5,x ; Initialize scrolling + stz WG_VIEWRECORDS+6,x iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; View Width - inx + sta WG_VIEWRECORDS+7,x ; View Width iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; View Height + sta WG_VIEWRECORDS+8,x ; View Height - lda #0 - inx ; Initialize state - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x ; Initialize callback - inx - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x ; Initialize title - inx - sta WG_VIEWRECORDS,x + stz WG_VIEWRECORDS+9,x ; Initialize state + stz WG_VIEWRECORDS+10,x ; Initialize callback + stz WG_VIEWRECORDS+11,x + stz WG_VIEWRECORDS+12,x ; Initialize title + stz WG_VIEWRECORDS+13,x pla jsr WGSelectView ; Leave this as the active view WGCreateView_done: - RESTORE_ZPS RESTORE_AXY rts @@ -118,7 +101,6 @@ WGCreateView_done: ; WGCreateCheckbox: SAVE_AXY - SAVE_ZPS ldy #0 lda (PARAM0),y ; Find our new view record @@ -132,58 +114,39 @@ WGCreateCheckbox: iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen X - inx + sta WG_VIEWRECORDS+0,x ; Screen X iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen Y - inx + sta WG_VIEWRECORDS+1,x ; Screen Y lda #1 - sta WG_VIEWRECORDS,x ; Initialize screen width - inx - sta WG_VIEWRECORDS,x ; Initialize screen height - inx + sta WG_VIEWRECORDS+2,x ; Initialize screen width + sta WG_VIEWRECORDS+3,x ; Initialize screen height + sta WG_VIEWRECORDS+7,x ; Initialize view width + sta WG_VIEWRECORDS+8,x ; Initialize view height lda #VIEW_STYLE_CHECK - sta WG_VIEWRECORDS,x ; Style - inx + sta WG_VIEWRECORDS+4,x ; Style - lda #0 ; Initialize scrolling - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x - inx + stz WG_VIEWRECORDS+5,x ; Initialize scrolling + stz WG_VIEWRECORDS+6,x - lda #0 - sta WG_VIEWRECORDS,x ; Initialize view width - inx - sta WG_VIEWRECORDS,x ; Initialize view height - inx - - lda #%00000000 ; Initialize state - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x ; Initialize callback - inx - sta WG_VIEWRECORDS,x - inx + stz WG_VIEWRECORDS+9,x ; Initialize state + stz WG_VIEWRECORDS+10,x ; Initialize callback + stz WG_VIEWRECORDS+11,x iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Title - inx + sta WG_VIEWRECORDS+12,x ; Title iny lda (PARAM0),y - sta WG_VIEWRECORDS,x - inx + sta WG_VIEWRECORDS+13,x pla jsr WGSelectView ; Leave this as the active view WGCreateCheckbox_done: - RESTORE_ZPS RESTORE_AXY rts @@ -206,7 +169,6 @@ WGCreateCheckbox_done: ; SH: Title string pointer (MSB) WGCreateButton: SAVE_AXY - SAVE_ZPS ldy #0 lda (PARAM0),y ; Find our new view record @@ -220,66 +182,46 @@ WGCreateButton: iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen X - inx + sta WG_VIEWRECORDS+0,x ; Screen X iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen Y - inx + sta WG_VIEWRECORDS+1,x ; Screen Y iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Screen width - inx + sta WG_VIEWRECORDS+2,x ; Screen width + sta WG_VIEWRECORDS+7,x ; View width lda #1 - sta WG_VIEWRECORDS,x ; Initialize screen height - inx + sta WG_VIEWRECORDS+3,x ; Initialize screen height + sta WG_VIEWRECORDS+8,x ; Initialize view height lda #VIEW_STYLE_BUTTON - sta WG_VIEWRECORDS,x ; Style - inx + sta WG_VIEWRECORDS+4,x ; Style - lda #0 ; Initialize scrolling - sta WG_VIEWRECORDS,x - inx - sta WG_VIEWRECORDS,x - inx - - lda #0 - sta WG_VIEWRECORDS,x ; Initialize view width - inx - sta WG_VIEWRECORDS,x ; Initialize view height - inx - - lda #%00000000 ; Initialize state - sta WG_VIEWRECORDS,x - inx + stz WG_VIEWRECORDS+5,x ; Initialize scrolling + stz WG_VIEWRECORDS+6,x + stz WG_VIEWRECORDS+9,x ; Initialize state iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Callback - inx + sta WG_VIEWRECORDS+10,x ; Callback iny lda (PARAM0),y - sta WG_VIEWRECORDS,x - inx + sta WG_VIEWRECORDS+11,x iny lda (PARAM0),y - sta WG_VIEWRECORDS,x ; Title - inx + sta WG_VIEWRECORDS+12,x ; Title iny lda (PARAM0),y - sta WG_VIEWRECORDS,x - inx + sta WG_VIEWRECORDS+13,x pla jsr WGSelectView ; Leave this as the active view WGCreateButton_done: - RESTORE_ZPS RESTORE_AXY rts @@ -290,15 +232,14 @@ WGCreateButton_done: ; Paints the current view ; WGPaintView: - SAVE_AY + SAVE_AXY SAVE_ZPP - SAVE_ZPS LDY_ACTIVEVIEW lda WG_VIEWRECORDS+4,y ; Cache style information and #$f ; Mask off flag bits - sta SCRATCH0 + pha lda WG_VIEWRECORDS+0,y ; Fetch the geometry sta PARAM0 @@ -309,13 +250,12 @@ WGPaintView: lda WG_VIEWRECORDS+3,y sta PARAM3 - lda SCRATCH0 ; Draw outline + pla ; Draw outline cmp #VIEW_STYLE_FANCY beq WGPaintView_decorated jsr WGStrokeRect - lda SCRATCH0 cmp #VIEW_STYLE_CHECK beq WGPaintView_check cmp #VIEW_STYLE_BUTTON @@ -335,9 +275,8 @@ WGPaintView_button: jsr paintButton WGPaintView_done: - RESTORE_ZPS RESTORE_ZPP - RESTORE_AY + RESTORE_AXY rts @@ -345,7 +284,7 @@ WGPaintView_done: ; paintCheck ; Paints the contents of a checkbox ; Y: Index into view records of checkbox to paint -; Side effects: Clobbers S0,P0,P1, all registers +; Side effects: Clobbers all registers,P0,P1 paintCheck: lda WG_VIEWRECORDS+0,y ; Position cursor sta WG_CURSORX @@ -409,11 +348,8 @@ paintCheck_done: ; paintButton ; Paints the contents of a button ; Y: Index into view records of button to paint -; +; Side effects: Clobbers all registers,P0,P1,S1 paintButton: - SAVE_AX - SAVE_ZPS - lda WG_VIEWRECORDS+12,y ; Prep the title string sta PARAM0 lda WG_VIEWRECORDS+13,y @@ -475,8 +411,6 @@ paintButton_titleMarginRightLoop: jmp paintButton_titleMarginRightLoop paintButton_done: - RESTORE_ZPS - RESTORE_AX rts @@ -484,11 +418,8 @@ paintButton_done: ; paintWindowTitle ; Paints the title of a fancy window ; Y: Index into view records of view title to paint -; +; Side effects: Clobbers all registers,P0,P1,S1 paintWindowTitle: - SAVE_AX - SAVE_ZPS - lda WG_VIEWRECORDS+12,y ; Prep the title string sta PARAM0 lda WG_VIEWRECORDS+13,y @@ -523,55 +454,15 @@ paintWindowTitleLoop: bra paintWindowTitleLoop paintWindowTitle_done: - RESTORE_ZPS - RESTORE_AX rts -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; WGEraseView -; Erases the current view (including decoration) -; -WGEraseView: - SAVE_AXY - SAVE_ZPP - - LDY_ACTIVEVIEW - - lda WG_VIEWRECORDS+0,y - dec - sta PARAM0 - - lda WG_VIEWRECORDS+1,y - dec - sta PARAM1 - - lda WG_VIEWRECORDS+2,y - inc - inc - sta PARAM2 - - lda WG_VIEWRECORDS+3,y - inc - inc - sta PARAM3 - - ldy #' '+$80 - jsr WGFillRect - -WGEraseView_done: - RESTORE_ZPP - RESTORE_AXY - rts - - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; WGEraseViewContents ; Erases the contents of the current view (interior contents only) ; WGEraseViewContents: - SAVE_AXY + SAVE_AY SAVE_ZPP LDY_ACTIVEVIEW @@ -593,7 +484,7 @@ WGEraseViewContents: WGEraseViewContents_done: RESTORE_ZPP - RESTORE_AXY + RESTORE_AY rts @@ -605,17 +496,14 @@ WGEraseViewContents_done: ; WGSelectView: sta WG_ACTIVEVIEW - pha ; Initialize cursor to local origin - lda #0 - sta WG_LOCALCURSORX - sta WG_LOCALCURSORY + stz WG_LOCALCURSORX + stz WG_LOCALCURSORY jsr cacheClipPlanes ; View changed, so clipping cache is stale WGSelectView_done: - pla rts @@ -630,30 +518,11 @@ WGViewFocus: lda WG_ACTIVEVIEW ; Stash current selection pha - lda WG_FOCUSVIEW - bmi WGViewFocus_noCurrent + jsr unfocusCurrent - LDY_FOCUSVIEW ; Unfocus current view - lda WG_VIEWRECORDS+9,y - and #%01111111 - sta WG_VIEWRECORDS+9,y - - lda WG_FOCUSVIEW - jsr WGSelectView - jsr WGPaintView - -WGViewFocus_noCurrent: pla - sta WG_FOCUSVIEW ; Focus on our original selection - jsr WGSelectView - - LDY_FOCUSVIEW - - lda WG_VIEWRECORDS+9,y ; Change state and repaint to reflect it - ora #%10000000 - sta WG_VIEWRECORDS+9,y - - jsr WGPaintView + sta WG_FOCUSVIEW ; Focus on our current selection + jsr focusCurrent RESTORE_AY rts @@ -667,17 +536,7 @@ WGViewFocus_noCurrent: WGViewUnfocus: pha - lda WG_FOCUSVIEW - bmi WGViewUnfocus_done - - LDY_FOCUSVIEW ; Unfocus current view - lda WG_VIEWRECORDS+9,y - and #%01111111 - sta WG_VIEWRECORDS+9,y - - lda WG_FOCUSVIEW - jsr WGSelectView - jsr WGPaintView + jsr unfocusCurrent lda #$ff sta WG_FOCUSVIEW @@ -695,17 +554,7 @@ WGViewUnfocus_done: WGViewFocusNext: SAVE_AY - lda WG_FOCUSVIEW - bmi WGViewFocusNext_loop - - LDY_FOCUSVIEW ; Unfocus current view - lda WG_VIEWRECORDS+9,y - and #%01111111 - sta WG_VIEWRECORDS+9,y - - lda WG_FOCUSVIEW - jsr WGSelectView - jsr WGPaintView + jsr unfocusCurrent WGViewFocusNext_loop: inc WG_FOCUSVIEW ; Increment and wrap @@ -723,14 +572,7 @@ WGViewFocusNext_wantFocus: ; Does this view accept focus? bcc WGViewFocusNext_loop WGViewFocusNext_focus: - lda WG_FOCUSVIEW ; Change state and repaint to reflect it - jsr WGSelectView - - lda WG_VIEWRECORDS+9,y - ora #%10000000 - sta WG_VIEWRECORDS+9,y - - jsr WGPaintView + jsr focusCurrent RESTORE_AY rts @@ -744,17 +586,7 @@ WGViewFocusNext_focus: WGViewFocusPrev: SAVE_AXY - lda WG_FOCUSVIEW - bmi WGViewFocusPrev_hadNone - - LDY_FOCUSVIEW ; Unfocus current view - lda WG_VIEWRECORDS+9,y - and #%01111111 - sta WG_VIEWRECORDS+9,y - - lda WG_FOCUSVIEW - jsr WGSelectView - jsr WGPaintView + jsr unfocusCurrent WGViewFocusPrev_loop: dec WG_FOCUSVIEW ; Decrement and wrap @@ -778,18 +610,48 @@ WGViewFocusPrev_wantFocus: ; Does this view accept focus? bcc WGViewFocusPrev_loop WGViewFocusPrev_focus: - lda WG_FOCUSVIEW ; Change state and repaint to reflect it - jsr WGSelectView + jsr focusCurrent - LDY_FOCUSVIEW + RESTORE_AXY + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; unfocusCurrent +; Unfocuses current view, if any +; Side effects: Clobbers A, +; Leaves Y pointed at current focus view record +; Changes active view selection +unfocusCurrent: + lda WG_FOCUSVIEW + bmi unfocusCurrentDone ; No current focus + + LDY_FOCUSVIEW ; Unfocus current view + lda WG_VIEWRECORDS+9,y + and #%01111111 + sta WG_VIEWRECORDS+9,y + + lda WG_FOCUSVIEW + jsr WGSelectView + jsr WGPaintView + +unfocusCurrentDone: + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; focusCurrent +; Sets focus to desired view, and repaints +; Side effects: Clobbers A +focusCurrent: + lda WG_FOCUSVIEW + jsr WGSelectView lda WG_VIEWRECORDS+9,y ora #%10000000 sta WG_VIEWRECORDS+9,y jsr WGPaintView - - RESTORE_AXY rts @@ -916,7 +778,7 @@ WGPendingView: ; PARAM0: Null-terminated string pointer (LSB) ; PARAM1: Null-terminated string pointer (MSB) WGViewSetTitle: - SAVE_AXY + SAVE_AY LDY_ACTIVEVIEW lda PARAM0 @@ -925,7 +787,7 @@ WGViewSetTitle: sta WG_VIEWRECORDS+13,y WGViewSetTitle_done: - RESTORE_AXY + RESTORE_AY rts @@ -995,37 +857,24 @@ WGSetGlobalCursor: WGSyncGlobalCursor: SAVE_AY - ; X LDY_ACTIVEVIEW + ; Sync X clc ; Transform to viewspace lda WG_LOCALCURSORX - adc WG_VIEWRECORDS,y + adc WG_VIEWRECORDS+0,y - iny - iny - iny - iny - iny clc - adc WG_VIEWRECORDS,y ; Transform to scrollspace + adc WG_VIEWRECORDS+5,y ; Transform to scrollspace sta WG_CURSORX - ; Y - LDY_ACTIVEVIEW - iny - + ; Sync Y clc ; Transform to viewspace lda WG_LOCALCURSORY - adc WG_VIEWRECORDS,y + adc WG_VIEWRECORDS+1,y - iny - iny - iny - iny - iny clc - adc WG_VIEWRECORDS,y ; Transform to scrollspace + adc WG_VIEWRECORDS+6,y ; Transform to scrollspace sta WG_CURSORY WGSyncGlobalCursor_done: @@ -1043,14 +892,10 @@ WGSyncGlobalCursor_done: WGScrollX: phy pha + LDY_ACTIVEVIEW - iny - iny - iny - iny - iny pla - sta WG_VIEWRECORDS,y + sta WG_VIEWRECORDS+5,y jsr cacheClipPlanes ; Scroll offset changed, so clipping cache is stale WGScrollX_done: @@ -1062,15 +907,12 @@ WGScrollX_done: ; WGScrollXBy ; Scrolls the current view horizontally by a delta ; A: Scroll delta -; Side effects: Clobbers A +; Side effects: Clobbers A,S0 ; WGScrollXBy: - phy - phx + SAVE_XY tax - SAVE_ZPS - LDY_ACTIVEVIEW txa @@ -1097,8 +939,7 @@ WGScrollXBy_clampLeft: WGScrollXBy_contentRight: clc ; Compute new scroll value adc WG_VIEWRECORDS+5,y - cmp #0 ; Clamp if needed - beq @0 + beq @0 ; Clamp if needed bpl WGScrollXBy_clampRight @0: sta WG_VIEWRECORDS+5,y bra WGScrollXBy_done @@ -1108,9 +949,7 @@ WGScrollXBy_clampRight: sta WG_VIEWRECORDS+5,y WGScrollXBy_done: - RESTORE_ZPS - plx - ply + RESTORE_XY rts @@ -1123,16 +962,10 @@ WGScrollXBy_done: WGScrollY: phy pha + LDY_ACTIVEVIEW pla - iny - iny - iny - iny - iny - iny - sta WG_VIEWRECORDS,y - + sta WG_VIEWRECORDS+6,y jsr cacheClipPlanes ; Scroll offset changed, so clipping cache is stale WGScrollY_done: @@ -1145,15 +978,12 @@ WGScrollY_done: ; WGScrollYBy ; Scrolls the current view horizontally by a delta ; A: Scroll delta -; Side effects: Clobbers A +; Side effects: Clobbers A,S0 ; WGScrollYBy: - phy - phx + SAVE_XY tax - SAVE_ZPS - LDY_ACTIVEVIEW txa @@ -1180,9 +1010,8 @@ WGScrollYBy_clampTop: WGScrollYBy_contentDown: clc ; Compute new scroll value adc WG_VIEWRECORDS+6,y - cmp #0 ; Clamp if needed - beq @0 - bpl WGScrollYBy_clampBottom + beq @0 ; Clamp if needed + bpl WGScrollYBy_clampBottom @0: sta WG_VIEWRECORDS+6,y bra WGScrollYBy_done @@ -1191,9 +1020,7 @@ WGScrollYBy_clampBottom: sta WG_VIEWRECORDS+6,y WGScrollYBy_done: - RESTORE_ZPS - plx - ply + RESTORE_XY rts @@ -1290,44 +1117,27 @@ cacheClipPlanes: ; Compute clip planes in view space LDY_ACTIVEVIEW - iny ; Left edge - iny - iny - iny - iny - lda WG_VIEWRECORDS,y + lda WG_VIEWRECORDS+5,y ; Left edge eor #$ff inc sta WG_VIEWCLIP+0 - dey ; Right edge - dey - dey clc - adc WG_VIEWRECORDS,y + adc WG_VIEWRECORDS+2,y ; Right edge sta WG_VIEWCLIP+2 - iny ; Right span (distance from window edge to view edge, in viewspace - iny - iny - iny - iny - lda WG_VIEWRECORDS,y + lda WG_VIEWRECORDS+7,y ; Right span (distance from window edge to view edge, in viewspace sec sbc WG_VIEWCLIP+2 sta WG_VIEWCLIP+4 - dey ; Top edge - lda WG_VIEWRECORDS,y + lda WG_VIEWRECORDS+6,y ; Top edge eor #$ff inc sta WG_VIEWCLIP+1 - dey ; Bottom edge - dey - dey clc - adc WG_VIEWRECORDS,y + adc WG_VIEWRECORDS+3,y ; Bottom edge sta WG_VIEWCLIP+3 RESTORE_AY