home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / routines / dobarmenu.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  4.6 KB  |  183 lines

  1. ;DoBarMenu version 1.0    table-driven menu routine
  2. ;by Cassady Roop
  3. ;INPUT:  hl- points to datatable
  4. ;OUTPUT:  Displays and runs a TI-BASIC-like menu, ignoring all input but the F keys.
  5. ;Note: save any important reg's before using this.
  6. ;Note2: JP to this routine, don't call.
  7. ;Note3: This routine JPs to addresses, it doesn't call.
  8. ;It's big, but it works.  Example datatable at end of document.
  9. ;-----------------------------------------------------------------------------------------
  10. DoBarMenu:
  11.     push hl                    ;save datatable pointer
  12.     ld hl, $FF80            ;start byte of row 56 in video mem. HLine makes horizontal line at top of menu.
  13.     ld b, $FF                ;%11111111
  14.     ld a, $00                ;initialize counter
  15. DBM_HLineLoop:
  16.     ld (hl), b                ;darken 8 pixels
  17.     inc hl                    ;next byte
  18.     inc a                    ;increment counter
  19.     cp 32                    ;two complete rows done yet?
  20.     jr nz, DBM_HLineLoop        ;recycle
  21.     ld hl, $FFA0            ;vidmem, first byte of row 58. VLine makes vertical posts between menu slots.
  22.     ld b, $00                ;initialize line counter
  23.     ld de, $0003
  24. DBM_VLineLoop:
  25.     ld a, (DBM_byte1)            ;%11000000
  26.     ld (hl), a                ;move to vidmem
  27.     add hl, de                ;HL+3=HL
  28.     ld (hl), a                ;uses same byte as last one
  29.     add hl, de
  30.     ld a, (DBM_byte7)        ;%01100000
  31.     ld (hl), a
  32.     add hl, de
  33.     ld a, (DBM_byte10)        ;%00011000
  34.     ld (hl), a
  35.     add hl, de
  36.     ld a, (DBM_byte13)        ;%00001100
  37.     ld (hl), a
  38.     add hl, de
  39.     ld a, (DBM_byte16)        ;%00000110
  40.     ld (hl), a
  41.     inc hl                    ;next line
  42.     inc b                    ;increment line counter
  43.     ld a, b
  44.     cp 6                    ;6 lines done?
  45.     jr nz, DBM_VLineLoop    ;if not, recycle
  46.     ld hl, $FF8F
  47.     res 0, (hl)                ;remove unsightly piece of overshot
  48.     ld hl, $FF9F
  49.     res 0, (hl)
  50.     pop hl                    ;retrieve
  51.     push hl                    ;save it again
  52.     ld a, (hl)
  53.     ld b, a
  54.     inc b
  55. DBM_FillLoop:                ;fill the menu slots with their texts
  56.     dec b
  57.     ld a, b
  58.     cp $00
  59.     jp z, DBM_Key        ;if skipped a null and got a zero count
  60.     inc hl
  61.     ld e, (hl)
  62.     inc hl
  63.     ld d, (hl)            ;addresses are stored backwards
  64.     ld a, d
  65.     cp $00
  66.     jr z, DBM_FillLoop    ;null entry, so skip it
  67.     inc de
  68.     inc de
  69.     push hl
  70.     ld a, b
  71.     cp 5
  72.     call z, DBM_5    ;five left, so first entry
  73.     cp 4
  74.     call z, DBM_4    ;four left, so second entry
  75.     cp 3
  76.     call z, DBM_3
  77.     cp 2
  78.     call z, DBM_2
  79.     cp 1
  80.     jp z, DBM_1
  81.     ld (_pencol), hl
  82.     ld h, d
  83.     ld l, e                ;ld hl, de. hl now points to string
  84.     call _vputs
  85.     pop hl
  86.     jr DBM_FillLoop
  87. DBM_5                    ;first entry
  88.     ld hl, $3A03
  89.     ret
  90. DBM_4                    ;second entry
  91.     ld hl, $3A1B
  92.     ret
  93. DBM_3:
  94.     ld hl, $3A34
  95.     ret
  96. DBM_2
  97.     ld hl, $3A4E
  98.     ret
  99. DBM_1
  100.     ld hl, $3A67
  101.     ld (_pencol), hl
  102.     ld h, d
  103.     ld l, e                    ;ld hl, de
  104.     call _vputs
  105.     pop hl
  106.     jp DBM_Key
  107. DBM_Key:                    ;interpret keypresses
  108.     call _getkey
  109.     cp $C7
  110.     jp p, DBM_Key            ;if a-$C7=positive, then too big to be an Fkey
  111.     cp $C2
  112.     jp m, DBM_Key            ;if a-$C2=positive, then too small to be an Fkey
  113.     pop hl                    ;hl now points to DataTable
  114.     push hl                    ;store it again for later use
  115.     sub $C1                    ;returns 1-5 for the function keys, in register a
  116.     rlca                    ;a=a*2
  117.     dec a                    ;a=a*2-1  
  118. DBM_keyloop:                ;advance hl to the correct entry pointer for that key
  119.     inc hl
  120.     dec a
  121.     cp $00                    ;if zero, we've found our entry pointer for that key
  122.     jr nz, DBM_keyloop
  123.     ld e, (hl)
  124.     inc hl
  125.     ld d, (hl)                ;entry address now in de
  126.     ld a, d
  127.     cp $00                    ;if null (blank), it'll be zero
  128.     jr z, DBM_key
  129.     pop bc                    ;cleanup the stack
  130.     ld a, (de)
  131.     ld l, a
  132.     inc de
  133.     ld a, (de)
  134.     ld h, a                    ;jump address should now be in hl
  135.     push hl                    ;save it
  136.     ld a, $80                ;number of bytes from top left of menu to bottom right
  137.     ld hl, $FF7F
  138. DBM_delmenu:                ;erase menu before making the jump
  139.     inc hl
  140.     ld (hl), $00            ;8 blank pixels
  141.     dec a
  142.     cp $00
  143.     jr nz, DBM_delmenu        ;reloop    
  144.     pop hl                    ;restore jump address
  145.     jp (hl)                    ;make the jump
  146. DBM_byte1:                    ;bytes used in making the vertical lines
  147.     .db %11000000
  148. DBM_byte7:
  149.     .db %01100000
  150. DBM_byte10:
  151.     .db %00011000
  152. DBM_byte13:
  153.     .db %00001100
  154. DBM_byte16:
  155.     .db %00000110
  156. ;-----------------------------------------------------
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. ;-------------------
  164. ;Example datatable- point to with HL
  165.  
  166. datatable:
  167.     .db $05                ;length (number of entries). currently only supports $05!
  168.     .dw entry1,entry2,entry3,entry4,entry5    ;pointers to entries.  Blanks can be made by replacing 'entry4', for 
  169.                                             ;example, with $0000.  That leaves a blank spot for menu spot 4.
  170. entry1:
  171.     .dw jump_here_1                            ;address to jump to if F1 is selected by the user
  172.     .db "1",0                                ;text to display in menu slot 1
  173. entry2:
  174.     .dw jump_here_2
  175.     .db "2",0
  176. entry3:
  177.     .dw jump_here_3
  178.     .db "3",0
  179.  
  180. ....                                        ;blank menu slots need not have an entry address, as long as
  181.                                             ;$0000 is in their slot in the pointer list above.
  182. ;-------------------------
  183.