| 11 | | or a |
| 12 | | ret |
| | 12 | ;In other words return carry flag set if you're handling this keypress. |
| | 13 | cp kInputDone |
| | 14 | jr nz,$F |
| | 15 | skipKey: |
| | 16 | or a |
| | 17 | ret |
| | 18 | $$: call IsSystemMenuKey |
| | 19 | jr c,HandleSystemMenuKey |
| | 20 | call IsInCatalogMenu |
| | 21 | jr z,skipKey |
| | 22 | call IsInMenu |
| | 23 | jr nz,HandleMenuOpenKey |
| | 24 | MenuCatCommon: |
| | 25 | cp appStart |
| | 26 | jr c,skipKey |
| | 27 | ; cp echoStart1 |
| | 28 | ; call c,RestoreOldContext |
| | 29 | cp kQuit |
| | 30 | jr z,skipKey |
| | 31 | or a |
| | 32 | ret |
| | 33 | HandleSystemMenuKey: |
| | 34 | ; call IsInMenu |
| | 35 | ; jr nz,keyHandled |
| | 36 | ld c,(iy+menuFlags) |
| | 37 | res useCustomDisplay,(iy+menuFlags) |
| | 38 | cp kExtendEcho |
| | 39 | jr nz,$F |
| | 40 | ld b,a |
| | 41 | ld a,(keyExtend) |
| | 42 | cp k2Tools |
| | 43 | ld a,b |
| | 44 | jr z,SetupMenuCustom |
| | 45 | jr skipKey |
| | 46 | $$: cp kAppsMenu |
| | 47 | jr z,SetupMenu |
| | 48 | skipSystemKey: |
| | 49 | ld (iy+menuFlags),c |
| | 50 | or a |
| | 51 | ret |
| | 52 | xor a |
| | 53 | SetupMenuCustom: |
| | 54 | set useCustomDisplay,(iy+menuFlags) |
| | 55 | SetupMenu: |
| | 56 | push af |
| | 57 | ld a,(flags+curFlags) |
| | 58 | ld (curFlagsBackup),a |
| | 59 | res appTextSave,(iy+appFlags) |
| | 60 | res curAble,(iy+curFlags) |
| | 61 | res curOn,(iy+curFlags) |
| | 62 | ld a,(menuCurrent) |
| | 63 | or a |
| | 64 | call z,savepartialWin |
| | 65 | pop af |
| | 66 | cp kExtendEcho |
| | 67 | jr nz,$F |
| | 68 | ld a,(keyExtend) |
| | 69 | jr hsmk1 |
| | 70 | $$: sub 2Ah ;menuStart-1 |
| | 71 | hsmk1: ld (menuCurrent),a |
| | 72 | ld hl,0 |
| | 73 | ld (menuCurrent+1),hl |
| | 74 | B_CALL ClrLCDFull |
| | 75 | ld hl,0 |
| | 76 | ld (curRow),hl |
| | 77 | call GetMenuPointer |
| | 78 | ld a,(hl) |
| | 79 | ld (numHeaders),a |
| | 80 | ld a,(menuCurrent+1) |
| | 81 | ld b,a |
| | 82 | inc b |
| | 83 | $$: inc hl |
| | 84 | djnz $B |
| | 85 | ld a,(hl) |
| | 86 | ld (numItemsForThisHeader),a |
| | 87 | xor a |
| | 88 | ld (menuCurrent+2),a |
| | 89 | call DisplayMenu |
| | 90 | keyHandled: |
| | 91 | scf |
| | 92 | ret |
| | 93 | HandleMenuOpenKey: |
| | 94 | cp kLeft |
| | 95 | jr nz,notLeft |
| | 96 | call DisplayMenu |
| | 97 | jr keyHandled |
| | 98 | notLeft: |
| | 99 | cp kRight |
| | 100 | jr nz,notRight |
| | 101 | call DisplayMenu |
| | 102 | jr keyHandled |
| | 103 | notRight: |
| | 104 | cp kUp |
| | 105 | jr nz,notUp |
| | 106 | call DisplayMenu |
| | 107 | jr keyHandled |
| | 108 | notUp: cp kDown |
| | 109 | jr nz,notDown |
| | 110 | call DisplayMenu |
| | 111 | jr keyHandled |
| | 112 | notDown: |
| | 113 | cp kEnter |
| | 114 | jr nz,notEnter |
| | 115 | ld a,(menuCurrent+2) |
| | 116 | push af |
| | 117 | call GetCurrentMenuPointer |
| | 118 | pop bc |
| | 119 | ld a,b |
| | 120 | inc hl |
| | 121 | or a |
| | 122 | jr z,$F |
| | 123 | enterLoop: |
| | 124 | inc hl |
| | 125 | inc hl |
| | 126 | djnz enterLoop |
| | 127 | $$: bit useCustomDisplay,(iy+menuFlags) |
| | 128 | jr z,$F |
| | 129 | ld d,(hl) |
| | 130 | dec hl |
| | 131 | ld e,(hl) |
| | 132 | ex de,hl |
| | 133 | ld c,(hl) |
| | 134 | ld b,0 |
| | 135 | add hl,bc |
| | 136 | inc hl |
| | 137 | push hl |
| | 138 | set appTextSave,(iy+appFlags) |
| | 139 | ld hl,menuCurrent |
| | 140 | ld (hl),0 |
| | 141 | pop hl |
| | 142 | jp (hl) |
| | 143 | $$: ld b,(hl) |
| | 144 | dec hl |
| | 145 | ld a,(hl) |
| | 146 | ld (keyExtend),a |
| | 147 | or a |
| | 148 | ld a,b |
| | 149 | jr z,$F |
| | 150 | ld a,(keyExtend) |
| | 151 | ld c,a |
| | 152 | ld a,b |
| | 153 | ld (keyExtend),a |
| | 154 | ld a,c |
| | 155 | cp 83h |
| | 156 | jr nz,$F |
| | 157 | ld a,kExtendEcho |
| | 158 | jr HandleSystemMenuKey |
| | 159 | $$: push af |
| | 160 | call RestoreTextShadow |
| | 161 | ld a,(curFlagsBackup) |
| | 162 | ld (flags+curFlags),a |
| | 163 | set appTextSave,(iy+appFlags) |
| | 164 | ld hl,menuCurrent |
| | 165 | ld (hl),0 |
| | 166 | pop af |
| | 167 | or a |
| | 168 | ret |
| | 169 | notEnter: |
| | 170 | cp kClear |
| | 171 | jr nz,keyHandled |
| | 172 | call RestoreTextShadow |
| | 173 | ld a,(curFlagsBackup) |
| | 174 | ld (flags+curFlags),a |
| | 175 | set appTextSave,(iy+appFlags) |
| | 176 | ld hl,menuCurrent |
| | 177 | ld (hl),0 |
| | 178 | jr keyHandled |
| | 179 | IsSystemMenuKey: |
| | 180 | ;HACK: until we get all the menus between menuStart and menuEnd implemented, we have to hard-code |
| | 181 | ; which menu keys we support, which for now is just APPS. |
| | 182 | cp kAppsMenu |
| | 183 | scf |
| | 184 | ret z |
| | 185 | or a |
| | 186 | ret |
| | 187 | cp menuEnd+1 |
| | 188 | ret nc |
| | 189 | cp menuStart |
| | 190 | ccf |
| | 191 | ret |
| | 192 | DisplayMenu: |
| | 193 | ld a,(menuCurrent+2) |
| | 194 | ld c,a |
| | 195 | push bc |
| | 196 | ld a,1 |
| | 197 | ld (topMenuRow),a |
| | 198 | B_CALL ClrLCDFull |
| | 199 | ld hl,0 |
| | 200 | ld (curRow),hl |
| | 201 | call EraseEOL |
| | 202 | call DisplayMenuHeader |
| | 203 | call GetCurrentMenuPointer |
| | 204 | pop bc |
| | 205 | ld a,(numItemsForThisHeader) |
| | 206 | or a |
| | 207 | jr z,noItems |
| | 208 | ld a,c |
| | 209 | sla a |
| | 210 | ld e,a |
| | 211 | ld d,0 |
| | 212 | add hl,de |
| | 213 | call DispMenuChoices |
| | 214 | ld a,(topMenuRow) |
| | 215 | jr $F |
| | 216 | noItems: |
| | 217 | ld a,1 |
| | 218 | $$: ld (curRow),a |
| | 219 | ret |
| | 220 | DispMenuChoices: |
| | 221 | ld a,(topMenuRow) |
| | 222 | DispMenuChoicesLoop: |
| | 223 | ld (curRow),a |
| | 224 | call DisplayCurMenuNumColonArrow |
| | 225 | ld d,(hl) |
| | 226 | inc hl |
| | 227 | ld e,(hl) |
| | 228 | inc hl |
| | 229 | push hl |
| | 230 | push bc |
| | 231 | call DisplayMenuItem |
| | 232 | pop bc |
| | 233 | pop hl |
| | 234 | inc c |
| | 235 | ld a,(numItemsForThisHeader) |
| | 236 | cp c |
| | 237 | ret z |
| | 238 | ret c |
| | 239 | ld a,(curRow) |
| | 240 | cp 7 |
| | 241 | ret z |
| | 242 | inc a |
| | 243 | jr DispMenuChoicesLoop |
| | 244 | DisplayMenuItem: |
| | 245 | bit useCustomDisplay,(iy+menuFlags) |
| | 246 | jr z,$F |
| | 247 | ld h,e |
| | 248 | ld l,d |
| | 249 | jr dmiDisplay |
| | 250 | $$: B_CALL KeyToString |
| | 251 | dmiDisplay: |
| | 252 | call PutPS |
| | 253 | ld a,(curCol) |
| | 254 | cp 15 |
| | 255 | call c,EraseEOL |
| | 256 | ret |
| | 257 | DisplayCurMenuNumColonArrow: |
| | 258 | xor a |
| | 259 | ld (curCol),a |
| | 260 | ld a,(menuCurrent+2) |
| | 261 | cp c |
| | 262 | jr nz,$F |
| | 263 | DisplayMenuNumColonArow: |
| | 264 | set textInverse,(iy+textFlags) |
| | 265 | $$: ld b,'1' |
| | 266 | ld a,c |
| | 267 | ld e,a |
| | 268 | cp 9 |
| | 269 | jr c,dispLessThan9 |
| | 270 | jr nz,dispHigherThan10 |
| | 271 | ld a,'0' |
| | 272 | jr displayMenuIndexChar |
| | 273 | dispSpace: |
| | 274 | ld a,' ' |
| | 275 | jr displayMenuIndexChar |
| | 276 | dispTheta: |
| | 277 | ld a,5Bh |
| | 278 | jr displayMenuIndexChar |
| | 279 | dispHigherThan10: |
| | 280 | ld a,(menuCurrent) |
| | 281 | cp 3 |
| | 282 | jr z,dispSpace |
| | 283 | cp 28h |
| | 284 | jr z,dispSpace |
| | 285 | cp 2 |
| | 286 | jr z,dispSpace |
| | 287 | cp 16 |
| | 288 | jr nz,$F |
| | 289 | ld a,(menuCurrent+1) |
| | 290 | or a |
| | 291 | jr z,dispSpace |
| | 292 | jr notProgEdit |
| | 293 | $$: cp 2Ah |
| | 294 | jr nz,notProgEdit |
| | 295 | ld a,(menuCurrent+1) |
| | 296 | cp 2 |
| | 297 | jr z,dispSpace |
| | 298 | notProgEdit: |
| | 299 | ld a,e |
| | 300 | ld b,'7' |
| | 301 | cp 36 |
| | 302 | jr z,dispTheta |
| | 303 | jr nc,dispSpace |
| | 304 | dispLessThan9: |
| | 305 | add a,b |
| | 306 | displayMenuIndexChar: |
| | 307 | call PutC |
| | 308 | push bc |
| | 309 | ld a,(topMenuRow) |
| | 310 | ld b,a |
| | 311 | ld a,(curRow) |
| | 312 | cp b |
| | 313 | pop bc |
| | 314 | jr nz,$F |
| | 315 | ld a,e |
| | 316 | or a |
| | 317 | jr z,dispColon |
| | 318 | ld a,1Eh |
| | 319 | jr dispArrowColon |
| | 320 | $$: cp 7 |
| | 321 | jr nz,dispColon |
| | 322 | ld a,(numItemsForThisHeader) |
| | 323 | dec a |
| | 324 | cp e |
| | 325 | ld a,1Fh |
| | 326 | jr z,dispColon |
| | 327 | jr nc,dispArrowColon |
| | 328 | dispColon: |
| | 329 | ld a,':' |
| | 330 | dispArrowColon: |
| | 331 | call PutC |
| | 332 | res textInverse,(iy+textFlags) |
| | 333 | ret |
| | 334 | GetCurrentMenuPointer: |
| | 335 | call GetMenuPointer |
| | 336 | ld a,(menuCurrent+1) |
| | 337 | or a |
| | 338 | ld b,a |
| | 339 | ld a,(hl) |
| | 340 | ld c,a |
| | 341 | jr z,$F |
| | 342 | push hl |
| | 343 | gcmpLoop: |
| | 344 | inc hl |
| | 345 | add a,(hl) |
| | 346 | djnz gcmpLoop |
| | 347 | pop hl |
| | 348 | $$: sla a |
| | 349 | sub c |
| | 350 | add a,(hl) |
| | 351 | inc hl |
| | 352 | ld e,a |
| | 353 | ld d,0 |
| | 354 | add hl,de |
| | 355 | ret |
| | 356 | DisplayMenuHeader: |
| | 357 | call GetMenuPointer |
| | 358 | ld a,(hl) |
| | 359 | ld b,a |
| | 360 | inc hl |
| | 361 | inc hl |
| | 362 | ld a,(hl) |
| | 363 | ;A is the string index for the header |
| | 364 | set textInverse,(iy+textFlags) |
| | 365 | call GetBuiltInString |
| | 366 | call PutPS |
| | 367 | res textInverse,(iy+textFlags) |
| | 368 | ret |
| | 369 | GetMenuPointer: |
| | 370 | ld a,(menuCurrent) |
| | 371 | ld h,0 |
| | 372 | ld l,a |
| | 373 | add hl,hl |
| | 374 | ld de,menuTables-2 |
| | 375 | add hl,de |
| | 376 | jr LdHLInd |
| | 377 | GetBuiltInString: |
| | 378 | ld h,0 |
| | 379 | ld l,a |
| | 380 | add hl,hl |
| | 381 | ld de,ptrStrings-2 |
| | 382 | add hl,de |
| | 383 | jr LdHLInd |
| | 384 | menuTables: |
| | 385 | DW 0000h |
| | 386 | DW mntApps |
| | 387 | DW mntPrograms |
| | 388 | DW mntTools |
| | 389 | ;Each table has the following: |
| | 390 | ; DB bNumberOfHeaders |
| | 391 | ; DB bNumberOfChoices1 |
| | 392 | ; DB bHeaderStringIndex |
| | 393 | ; DB keyExtend1,keyCode1 |
| | 394 | ;Custom menu entries also hvae: |
| | 395 | ; DW wJumpAddress |
| | 396 | mntPrograms: |
| | 397 | mntApps: |
| | 398 | DB 1 |
| | 399 | DB 1 |
| | 400 | DB 01h |
| | 401 | DB 83h,k2Tools |
| | 402 | mntTools: |
| | 403 | DB 1 |
| | 404 | DB 1 |
| | 405 | DB 02h |
| | 406 | DW HexEditor |
| | 407 | ptrStrings: |
| | 408 | DW sApplications |
| | 409 | DW sTools |
| | 410 | sApplications: |
| | 411 | DB sTools-$F |
| | 412 | $$: DB "APPLICATIONS" |
| | 413 | sTools: |
| | 414 | DB sEnd-$F |
| | 415 | $$: DB "TOOLS" |
| | 416 | sEnd: |