From 6f1daaefd95bf866dd368da27c0268232dcae7fd Mon Sep 17 00:00:00 2001 From: Rob Greene Date: Wed, 10 Feb 2016 19:00:35 -0600 Subject: [PATCH] Working on key handling; added HandleKey for more structured general key handling. Added track movement to count page. --- afscanner.s | 114 +++++++++++++++++++++++++------------------------- macros.s | 11 +++++ page-browse.s | 2 +- page-count.s | 8 ++-- page-field.s | 2 + page.s | 70 +++++++++++++++++++------------ util.s | 43 +++++++++++++++++++ 7 files changed, 162 insertions(+), 88 deletions(-) create mode 100644 macros.s diff --git a/afscanner.s b/afscanner.s index 34796ca..a073598 100755 --- a/afscanner.s +++ b/afscanner.s @@ -12,17 +12,19 @@ * - Split source into multiple files as one file finally got way too big. * - Slowly switching from spaces to tabs as an experiment in code formatting. * - Pages available: -* + About (default page) -* + Headers (updated Address Field Header information) -* + Browse track buffer (hilights Address Field Header bytes) -* + Graphical disk display -* + Buffer counts +* + About (default page) +* + Headers (updated Address Field Header information) +* + Browse track buffer (hilights Address Field Header bytes) +* + Graphical disk display +* + Buffer counts * ****************************************************************************************** TYP SYS - XC ; enable 65C02 + XC ; enable 65C02 + + use macros * Program Locations @@ -32,51 +34,51 @@ ProgramLength = ProgramEnd-ProgramAddress * Constants: -NUMBYTES = 29 ; Number of bytes on screen -OFFSETV = 3 ; Offset to volume -OFFSETT = OFFSETV+2 ; Offset to track -OFFSETS = OFFSETT+2 ; Offset to sector -OFFSETC = OFFSETS+2 ; Offset to checksum -FAILBYTS = 6656 ; Number of bytes before failure +NUMBYTES = 29 ; Number of bytes on screen +OFFSETV = 3 ; Offset to volume +OFFSETT = OFFSETV+2 ; Offset to track +OFFSETS = OFFSETT+2 ; Offset to sector +OFFSETC = OFFSETS+2 ; Offset to checksum +FAILBYTS = 6656 ; Number of bytes before failure * 80 column card / print controls: -_PRBYTE = 1 ; print byte @ addr -_CLS = $8C ; clear screen -_INVERSE = $8F -_NORMAL = $8E -_MT_OFF = $98 ; disable MouseText -_HOME = $99 ; home the cursor, not cls -_MT_ON = $9B ; enable MouseText for uppercase inverse characters -_CLREOL = $9D ; clear to EOL +_PRBYTE = 1 ; print byte @ addr +_CLS = $8C ; clear screen +_INVERSE = $8F +_NORMAL = $8E +_MT_OFF = $98 ; disable MouseText +_HOME = $99 ; home the cursor, not cls +_MT_ON = $9B ; enable MouseText for uppercase inverse characters +_CLREOL = $9D ; clear to EOL -_C_APPLE = "@" ; Closed Apple -_O_APPLE = "A" ; Open Apple -_L_ARROW = "H" ; Left Arrow -_R_ARROW = "U" ; Right Arrow -_U_ARROW = "K" ; Up Arrow -_D_ARROW = "J" ; Down Arrow -_H_LINE = "S" ; Horizontal Line (full width) +_C_APPLE = "@" ; Closed Apple +_O_APPLE = "A" ; Open Apple +_L_ARROW = "H" ; Left Arrow +_R_ARROW = "U" ; Right Arrow +_U_ARROW = "K" ; Up Arrow +_D_ARROW = "J" ; Down Arrow +_H_LINE = "S" ; Horizontal Line (full width) * Variable locations: - DUM $0 ; ZP locs -SAMPLES DFB 0 ; number of sector samples -CURTRK DFB 0 ; current track -DSTTRK DFB 0 ; destination track + DUM $0 ; ZP locs +SAMPLES DFB 0 ; number of sector samples +CURTRK DFB 0 ; current track +DSTTRK DFB 0 ; destination track PTR DA 0 ; primary print pointer PTR2 DA 0 ; secondary print pointer -SLOT16 DFB 0 ; slot# * 16 +SLOT16 DFB 0 ; slot# * 16 COUNTER DA 0 ; fail counter -TEMP DFB 0 ; local variable +TEMP DFB 0 ; local variable TEMPY DFB 0 ; local Y coordinate DATA DA 0 ; data buffer _init da 0 ; current page init _display da 0 ; current page line display handler _keypress da 0 ; current page keypress handler -scrolling dfb 0 ; flag for scrolling (in high bit) +noscroll dfb 0 ; flag for scrolling (in high bit) topline dw 0 ; current line at top of page maxlines dw 0 ; maximum number of lines available printline dw 0 ; line being printed @@ -84,9 +86,9 @@ printline dw 0 ; line being printed inbuf = $200 ; reusable buffer -DATASTART = $4000 -DATAEND = $6000 -DATALEN = DATAEND-DATASTART +DATASTART = $4000 +DATAEND = $6000 +DATALEN = DATAEND-DATASTART PAGELEN = 20 ; number of lines displayed in content window @@ -104,8 +106,8 @@ DownArrow = CTRLJ * ProDOS: -PRODOSMLI = $BF00 -_MLIQUIT = $65 +PRODOSMLI = $BF00 +_MLIQUIT = $65 * ROM routines and associated addresses: @@ -115,7 +117,7 @@ HPOSN = $F411 HBAS = $26 DELAY = $FCA8 -GETCH = $FD0C +GETCH = $FD0C PRCR = $FD8E PRHEX = $FDDA COUT = $FDED @@ -140,7 +142,7 @@ OpenApple = $C061 sta PTR2+1 stz PTR2 ldy #0 - ldx #>ProgramLength+255 ; account for non-zero low byte + ldx #>ProgramLength+255 ; account for non-zero low byte :0 lda (PTR),y sta (PTR2),y iny @@ -163,21 +165,21 @@ MAIN lda #$4C ; JMP lda #>ProgramAddress sta USRADR+2 - JSR $C300 ; Assuming 80 columns - JSR PRINT - DFB _CLS - ASC "AFScanner",$8D - DFB _MT_ON,_INVERSE,80,_H_LINE,_NORMAL,_MT_OFF ; wraps! - DFB 20,$8D - DFB _MT_ON,_INVERSE,80,_H_LINE,_NORMAL,_MT_OFF ; wraps! - ASC _MT_ON,_INVERSE,_L_ARROW,_NORMAL,", ",_INVERSE,_R_ARROW,_NORMAL,_MT_OFF," Track / " - ASC "re",_INVERSE,"S",_NORMAL,"can / " - ASC _INVERSE,"R",_NORMAL,"ecalibrate / " - ASC "goto ",_INVERSE,"T",_NORMAL,"rack / " - ASC _INVERSE,"ESC",_NORMAL," quit" - DFB _HOME - HEX 8D8D - HEX 00 + JSR $C300 ; Assuming 80 columns + JSR PRINT + DFB _CLS + ASC "AFScanner",$8D + DFB _MT_ON,_INVERSE,80,_H_LINE,_NORMAL,_MT_OFF ; wraps! + DFB 20,$8D + DFB _MT_ON,_INVERSE,80,_H_LINE,_NORMAL,_MT_OFF ; wraps! + ASC _MT_ON,_INVERSE,_L_ARROW,_NORMAL,", ",_INVERSE,_R_ARROW,_NORMAL,_MT_OFF," Track / " + ASC "re",_INVERSE,"S",_NORMAL,"can / " + ASC _INVERSE,"R",_NORMAL,"ecalibrate / " + ASC "goto ",_INVERSE,"T",_NORMAL,"rack / " + ASC _INVERSE,"ESC",_NORMAL," quit" + DFB _HOME + HEX 8D8D + HEX 00 * Setup local variables diff --git a/macros.s b/macros.s new file mode 100644 index 0000000..b28397f --- /dev/null +++ b/macros.s @@ -0,0 +1,11 @@ +****************************************************************************************** +* +* Macros +* ======================================================================================== +* +****************************************************************************************** + +MenuKey mac + dfb ]1 + da ]2 + <<< diff --git a/page-browse.s b/page-browse.s index 4d68fd2..87b3c25 100755 --- a/page-browse.s +++ b/page-browse.s @@ -94,5 +94,5 @@ BrowseDisplay ; Called with Acc = line jmp PRCR BrowseKeypress ; Called with Acc = key - jmp FieldKeypress ; identical to Field ... for now at least + jmp TrackNavigationKeys diff --git a/page-count.s b/page-count.s index 199b664..f8a6a67 100755 --- a/page-count.s +++ b/page-count.s @@ -46,10 +46,10 @@ CountInit ; Returns with A:Y = max lines, C = scrolling CountDisplay ; Called with A:Y = line jsr PRINT - dfb $8D - dfb 14 + dfb _CLREOL,$8D + dfb 14 ; repeat the next space 14x asc " Low +0 +1 +2 +3 +4 +5 +6 +7 High",$8D - dfb 19 + dfb 19 ; repeat the next space 19x asc " ==== ==== ==== ==== ==== ==== ==== ====",$8D dfb 0 @@ -148,7 +148,7 @@ CountKeypress ; Called with Acc = key inx cpx #4 bne :test - jmp KeyboardWait + jmp TrackNavigationKeys :keys asc "-036" :set stx CountSettings diff --git a/page-field.s b/page-field.s index 6b2ca6d..1703ccc 100755 --- a/page-field.s +++ b/page-field.s @@ -104,6 +104,8 @@ FieldDisplay ; Called with A:Y = line :groups dfb 3,2,2,2,2,3 FieldKeypress ; Called with Acc = key + +TrackNavigationKeys ldx #-1 cmp #LARROW beq :chgtrk diff --git a/page.s b/page.s index 1ff4c51..179c8e8 100755 --- a/page.s +++ b/page.s @@ -5,7 +5,6 @@ * ****************************************************************************************** - SetupPage jsr TEXT ; ensure we are out of graphics modes as application has some! jsr PRINT ; position cursor on bottom line @@ -15,7 +14,7 @@ SetupPage dfb $00 ldx #_init ; vector offset jsr _VCALL - ror scrolling ; set flag based on C + ror noscroll ; set flag based on C sty maxlines sta maxlines+1 stz topline @@ -26,7 +25,7 @@ DrawPage dfb _HOME,$8d,$8d,0 ; If we aren't scrolling, call _display vector ONCE and then handle keyboard. - bit scrolling + bit noscroll bpl :scroll lda #0 tay @@ -34,6 +33,7 @@ DrawPage jsr _VCALL jmp KeyboardWait +; We are scrolling, for each line, redraw it :scroll lda #0 :loop pha clc @@ -47,7 +47,7 @@ DrawPage lda printline cmp maxlines bge :erase - + :drwlin lda printline+1 ldy printline ldx #_display @@ -62,6 +62,7 @@ DrawPage cmp #PAGELEN blt :loop +; Handle all keyboard interactions KeyboardWait lda KEYBOARD bpl KeyboardWait @@ -73,53 +74,68 @@ KeyboardWait and #$df ; uppercase mask :goodky sta KEYCLEAR bit OpenApple - bpl :normal + bpl :keys ; OpenApple handler jsr SetScreen - bcs :paging + bcs :oakeys jsr CLRSCRN jmp SetupPage + +; Standard open-apple keys that are always available +:oakeys jsr HandleKey + MenuKey "Q";:Quit + MenuKey "*";:Mon + dfb 0 + +; Open-Apple arrow keys only if scrolling is enabled + bit noscroll + bmi :local0 + jsr HandleKey + MenuKey UpArrow;:PgUp + MenuKey DownArrow;:PgDn + dfb 0 +:local0 jmp :local + +; Normal key handler (only when scrolling) +:keys bit noscroll + bmi :local0 + jsr HandleKey + MenuKey UpArrow;:Up + MenuKey DownArrow;:Down + dfb 0 + jmp :local + ; OA-Up -:paging cmp #UpArrow - bne :nPgUp - ldy #15 +:PgUp ldy #15 :uploop jsr :up1 dey bne :uploop beq :back ; always + ; OA-Down -:nPgUp cmp #DownArrow - bne :chkOAQ - ldy #15 +:PgDn ldy #15 :dnloop jsr :down1 dey bne :dnloop beq :back ; always + ; OA-Q -:chkOAQ cmp #"Q" - bne :chkOA7 - jsr PRODOSMLI +:Quit jsr PRODOSMLI dfb _MLIQUIT da QUITPARM :back jmp DrawPage ; fall through and common return ; OA-* -:chkOA7 cmp #"*" - bne :back - jsr PRINT +:Mon jsr PRINT asc _CLS,"Press CTRL-Y to re-enter AFScanner.",$8D,$00 jmp MONITOR -; Common keypress handler ; Up -:normal cmp #UpArrow - bne :notUp - jsr :up1 +:Up jsr :up1 jmp DrawPage + ; Down -:notUp cmp #DownArrow - bne :pgKey - jsr :down1 +:Down jsr :down1 jmp DrawPage ; "Local" subroutines @@ -156,12 +172,12 @@ KeyboardWait sta topline+1 :rts rts -:pgKey ldx #_keypress +:local ldx #_keypress ; Fall through and JMP to _keypress which takes control for local page keys * Simple vector call from ZP based on X register -_VCALL jmp: ($00,x) ; Merlin32 needs to know 16 bit JMP +_VCALL jmp: ($00,x) ; Merlin32 needs to know 16 bit JMP, ":" does that * Handle screen change - both called by app init and normal keyboard handler diff --git a/util.s b/util.s index 922bad7..c4e41b2 100755 --- a/util.s +++ b/util.s @@ -144,3 +144,46 @@ QUITPARM DFB 4 ; 4 parameters DA 0 ; reserved DFB 0 ; reserved DA 0 ; reserved + +; On entry: +; Acc = keypress +; Stack = address of table (format: key address key address 0) +; Will not return if key found, a JMP will be performed. +; If not found, return with carry set. +HandleKey + sta TEMP + pla + sta PTR + pla + sta PTR+1 + ldy #0 +:next + iny + lda (PTR),y + bpl :notFound + cmp TEMP + beq :jmp + iny + iny + bra :next +; Jump to keypress handler +:jmp iny + lda (PTR),y + sta PTR2 + iny + lda (PTR),y + sta PTR2+1 + jmp (PTR2) +; Not found - return to caller (Y + PTR = return address - 1) +:notFound + clc + tya + adc PTR + tax + lda #0 + adc PTR+1 + pha + phx + lda TEMP + sec + rts