From 5d00c3286c3244a727a26a92f1e50c46fc694ea5 Mon Sep 17 00:00:00 2001 From: Quinn Dunki Date: Mon, 13 Oct 2014 19:12:14 -0700 Subject: [PATCH] - More code size optimization - Reimplemented Print unit test - Made it easier to exclude AppleSoft API if desired --- ReadMe.md | 2 + WeeGUI_MLI.s | 43 +++-- applesoft.s | 18 +-- gui.s | 5 +- guidemo.dsk | Bin 143360 -> 143360 bytes guidemo.s | 57 +------ memory.s | 3 + painting.s | 8 +- unit_test.s | 85 +++++++--- utility.s | 28 ---- views.s | 434 +++++++++++++++------------------------------------ 11 files changed, 224 insertions(+), 459 deletions(-) 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 35b3b59132c529aca222cf04dee4a9768ffec273..dc61c27ed65e605e96e73c69cd02834a1cad85d2 100644 GIT binary patch delta 3626 zcmaJ^4{Q_H89)Dt|0IMM62LYky)o9>5}H!9p)8}|kdU06%SULlmPJ)-pj3u++9nN1 zQsAz@g(T%doC_p@I14u&%cXPb46Ty4Wy`uoN~|SwCrv8W%3x(xRtN_Pw){ zI8e>9?!E8#z5BiI-+T8Sf78a_w8e5w2Gg}X6K5;hLz$^}%~b7%+(L@_mEB;-647Az`tXt!W(o(lz$LaZN`*NqL=37)a8I>9^mv^wZxzZaB!wAmL_DR~pN zvJ)SJluWf)&RAtL3cb>%Q-92*X*>4iEz%E8f1`dgc8Mil&9o)yRyD|_*rRjzp;DdC77X&XY)zJ6O#9)v z_TSUSyiH+`_^ok#)Q`71{+V$6^@~CwdCxz=r5czK0hXc@Jp%#fL66{3se@j@i=x+% zv?E!l%flWiM?&m0&ylz)E=F-P(X%jp9%5godwhaB+6sC;$9h2w*9}rcDMF_^+5*$( zAXXne2c>sfU5T2na{4Gt)y1A!=J-+K zxI^a~^@vTN?nKU&I_ILC;iaC=qx7HAOzo;Qpdlxuf$*m1kApg%e;mX&K>P#SP68vI z04I;tDISMXEY1%z)mca<*w_#0$=XJ_2)iT4;pN7hla1!==UAgzJPOj9A8q80!C0eJ zY=phhM)305TCXp;I(ifYOY|5BR(htU#DvR;-T>&dGe}ZJ+^)i~Xys|&%O3UJ`?&8b zteqCk+>W_Ulo0K(+%Qz zXvS4Yf6T_}XzDkHr|J@6MtKHdj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qzLu;{2Uz(`ZyQI)T8Hpb;RfQ zp_hIBI)DOwN+}b>TbKY&u=p+3i6?;YKwoEr_!AIyGXZ%PzHjxSk#TVJBjP3wK2*hZ z0otl)YNA2Wqpt$hXGN1n%_=nu)L<9%2UJ^i^*uWL>nz;v%F?+;h4d+IaaGg2KAhsJ zaX9GJff{su&HNgLlgh=jO#xi*rTynx13u+}1@VJiQWu~*f_| z(54J7v4^&C2iukLW%f`9cW^rg8}1w1`N002u#Y)@KaH{ 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