Changeset 55 for trunk/page00/menu.asm

Show
Ignore:
Timestamp:
10/11/09 23:33:32 (3 years ago)
Author:
brandonlw
Message:

We now have a basic menu system and the beginnings of an oncalc hex editor
I also was forced to duplicate PutMap? instead of using the boot code hack, since it doesn't support inverse text
Progress...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/page00/menu.asm

    r48 r55  
    44 include "includes\os2.inc" 
    55 
    6  PUBLIC _PULLDOWNCHK 
     6 PUBLIC _PULLDOWNCHK,clrTR 
     7 EXTERN savepartialWin,rstrpartialWin,RestoreTextShadow,PutS,LdHLInd,PutPS,EraseEOL,PutC 
    78 
    89_PULLDOWNCHK: 
    910;Key code is in A. Check to see if it's a menu key and back out if not, otherwise handle it. 
    1011;Return carry flag set if you want the system monitor to restart, otherwise the current cxMain handler will get called for this key. 
    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 
     15skipKey: 
     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 
     24MenuCatCommon: 
     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 
     33HandleSystemMenuKey: 
     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 
     48skipSystemKey: 
     49       ld (iy+menuFlags),c 
     50       or a 
     51       ret 
     52       xor a 
     53SetupMenuCustom: 
     54       set useCustomDisplay,(iy+menuFlags) 
     55SetupMenu: 
     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 
     71hsmk1: 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 
     90keyHandled: 
     91       scf 
     92       ret 
     93HandleMenuOpenKey: 
     94       cp kLeft 
     95       jr nz,notLeft 
     96       call DisplayMenu 
     97       jr keyHandled 
     98notLeft: 
     99       cp kRight 
     100       jr nz,notRight 
     101       call DisplayMenu 
     102       jr keyHandled 
     103notRight: 
     104       cp kUp 
     105       jr nz,notUp 
     106       call DisplayMenu 
     107       jr keyHandled 
     108notUp: cp kDown 
     109       jr nz,notDown 
     110       call DisplayMenu 
     111       jr keyHandled 
     112notDown: 
     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 
     123enterLoop: 
     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 
     169notEnter: 
     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 
     179IsSystemMenuKey: 
     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 
     192DisplayMenu: 
     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 
     216noItems: 
     217       ld a,1 
     218$$:    ld (curRow),a 
     219       ret 
     220DispMenuChoices: 
     221       ld a,(topMenuRow) 
     222DispMenuChoicesLoop: 
     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 
     244DisplayMenuItem: 
     245       bit useCustomDisplay,(iy+menuFlags) 
     246       jr z,$F 
     247       ld h,e 
     248       ld l,d 
     249       jr dmiDisplay 
     250$$:    B_CALL KeyToString 
     251dmiDisplay: 
     252       call PutPS 
     253       ld a,(curCol) 
     254       cp 15 
     255       call c,EraseEOL 
     256       ret 
     257DisplayCurMenuNumColonArrow: 
     258       xor a 
     259       ld (curCol),a 
     260       ld a,(menuCurrent+2) 
     261       cp c 
     262       jr nz,$F 
     263DisplayMenuNumColonArow: 
     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 
     273dispSpace: 
     274       ld a,' ' 
     275       jr displayMenuIndexChar 
     276dispTheta: 
     277       ld a,5Bh 
     278       jr displayMenuIndexChar 
     279dispHigherThan10: 
     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 
     298notProgEdit: 
     299       ld a,e 
     300       ld b,'7' 
     301       cp 36 
     302       jr z,dispTheta 
     303       jr nc,dispSpace 
     304dispLessThan9: 
     305       add a,b 
     306displayMenuIndexChar: 
     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 
     328dispColon: 
     329       ld a,':' 
     330dispArrowColon: 
     331       call PutC 
     332       res textInverse,(iy+textFlags) 
     333       ret 
     334GetCurrentMenuPointer: 
     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 
     343gcmpLoop: 
     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 
     356DisplayMenuHeader: 
     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 
     369GetMenuPointer: 
     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 
     377GetBuiltInString: 
     378       ld h,0 
     379       ld l,a 
     380       add hl,hl 
     381       ld de,ptrStrings-2 
     382       add hl,de 
     383       jr LdHLInd 
     384menuTables: 
     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 
     396mntPrograms: 
     397mntApps: 
     398       DB 1 
     399       DB 1 
     400       DB 01h 
     401       DB 83h,k2Tools 
     402mntTools: 
     403       DB 1 
     404       DB 1 
     405       DB 02h 
     406       DW HexEditor 
     407ptrStrings: 
     408       DW sApplications 
     409       DW sTools 
     410sApplications: 
     411       DB sTools-$F 
     412$$:    DB "APPLICATIONS" 
     413sTools: 
     414       DB sEnd-$F 
     415$$:    DB "TOOLS" 
     416sEnd: 
    13417 
     418HexEditor: 
     419       DB $F-HexEditor-1 
     420       DB "Hex Editor" 
     421$$:    res curAble,(iy+curFlags) 
     422       res curOn,(iy+curFlags) 
     423       res appTextSave,(iy+appFlags) 
     424       B_CALL ClrLCDFull 
     425       ld hl,0 
     426       ld (curRow),hl 
     427       ld hl,sWelcome 
     428       call PutS 
     429       B_CALL GetKey 
     430       B_JUMP JForceCmdNoChar 
     431sWelcome: 
     432       DB "Welcome to the  " 
     433       DB "hex editor!",0 
     434    
     435clrTR: 
     436       cp kCatalog 
     437       jr z,clrTRCatalogPressed 
     438       call IsInCatalogMenu 
     439       jr z,DoCatalogKeyPress 
     440       jr MenuCatCommon 
     441clrTRCatalogPressed: 
     442DoCatalogKeyPress: 
     443       scf 
     444       ret 
     445IsInCatalogMenu: 
     446       ld b,a 
     447       ld a,(menuCurrent) 
     448       cp mCatalog 
     449       ld a,b 
     450       ret 
     451IsInMenu: 
     452       ld b,a 
     453       ld a,(menuCurrent) 
     454       or a 
     455       ld a,b 
     456       ret 
     457