Menu64

Description Screenshots Documentation Bugs Download

Description

Menu64 is a minimal set of functions to create simple text-oriented menus for the Commodore 64. The source is released under the LGPL v3, and written in 6502/6510 asm using 'ca65' (cross-assembler).

Top

Screenshots

The test-program running in Vice:

Vice running the 64menu test-program showing pulldown-menu and a dialog Vice running the 64menu test-program showing pulldown-menu and a submenu

Top

Documentation

The documentation mainly consists of comments in the source-code and an example test-program (64mnutst.asm).

Notes:

To build the library, use: cl65 -o 64mnutst.prg -t c64 -C c64-asm.cfg 64mnutst.asm .

'c64-asm.cfg' standard uses $0801 as startaddress, this should be equal to the address in your code.

The program stores data (menu-data) at address $cf00, you can change this in the lines 36 and 37 of 64mnulib.asm (mstartlo and mstarthi).

Aside from the cursor-keys, <clr/home> can be used to exit a menu, you can change this in line 39 of 64mnulib.asm (exitkey).

<Enter> or <Return> is used to confirm the contents of an edit-field.

Getting started:

Creating a menu starts with the definition of a menu, which looks like this:

                
                    mymenu:
                    .byt 18,13,10,5,"checkbox",0,0
                    .byt 1,14,10,6,"menu item",0,0
                    .byt 32,16,10,8,"an input item:",0,"some text",0,255
                
            

The format of an item is:

                
                    mode + type , id , xpos , ypos , caption , defaultvalue
                
            
mode (high nyble) and type (low nyble), the number is the bit (0 .. 7).
  1. select flag (1)
  2. checkbox flag (2)
  3. unused (4)
  4. unused (8)
  5. checkbox (16)
  6. edit (32)
  7. unused (64)
  8. horizontal oriented (128)
id
Unique number to identify the item (range 0-255).
xpos
X position of the item.
ypos
Y position of the item.
Caption
Text of the item.
Defaultvalue
The defaultvalue for the edit-control.

The next step is to create a menu with jsr mcreate. It starts with $fb and $fc pointing to the menu-definition just created:

                
                    lda #<mymenu
                    sta $fb
                    lda #>mymenu
                    sta $fc     
                    jsr _mcreate
                    rts
                
            

_mcreate copies the menu-data to mstartlo , mstarthi and creates an index. $fb , $fc will be freed so they can be used as a pointer to the active menu-item.

The next step is to draw the menu and call the eventhandler:

                
                    jsr _mdraw
                    jsr _mevent
                    rts
                
            

The last step is to add the activate function, which is called inside the event-handler, _mevent. It is the function where you can put the code that reacts to user-input.

The label-names in this example have the following format: 'ni' is an abbreviation for 'not item', followed by the item's id.

                
                    activate:   ldy #$01
                                lda ($fb),y
                                cmp #00
                                bne ni00
                                ldy #$00
                                lda ($fb),y
                                and #$02
                                bne c1
                                lda #$00
                                sta $d020
                                jmp ni00
                    c1:         lda $$0f
                                sta $d020
                    ni00:       rts
                
            

This changes the border-color depending on the status of the checkbox. Note that it checks the id first, and if that is correct it will load the mode + type byte and check bit 1 (and #$02).

Here is the entire code:

                
                                .org $c000         ; call with 'sys 49152'.
                    
                                lda #<mymenu
                                sta $fb
                                lda #>mymenu
                                sta $fc     
                                jsr _mcreate

                                jsr _mdraw
                                jsr _mevent
                                rts
                    
                    activate:   ldy #$01
                                lda ($fb),y
                                cmp #00
                                bne ni00
                                ldy #$00
                                lda ($fb),y
                                and #$02
                                bne c1
                                lda #$00
                                sta $d020
                                jmp ni00
                    c1:         lda #$0f
                                sta $d020
                    ni00:       rts
        
                    .include "64mnulib.asm"
                
                    mymenu:
                        .byt 18,13,10,5,"checkbox",0,0,
                        .byt 1,14,10,6,"menu item",0,0,
                        .byt 32,16,10,8,"an input item:",0,"some text",0,255
                
                
            

Top

Bugs

Top

Download

Version 0.4.2.2

menu64_v0422.zip
Changed the address for the item-table.
menu64_v0421.zip
Renamed .asm to .s, and fixed date in CHANGES: 2025-08-08 to 2025-09-08.
menu64_v042.zip
More bugfixes: positioning of edit-control as default-item and problems with cursor at last position.
menu64_v041.zip
Fixed bug: using the 'delete'-key at the last position of the editfield caused a buffer-overflow.
menu64_v04.zip
Removed extra action (keyboard / joystick) required to switch (sub)menu's.
Renamed standard functions to avoid collision with the functions in the C standard library.
Added more documentation.

Version 0.3

menu64_v03.zip
Added joystick-support for the menu.

Version 0.2

menu64_v02.zip
Added cursor-keys as exit-key for the menu.
Ported project from 'xa64' to 'ca65'.

Version 0.1.1

See menu64v01.html for documentation and more info about this version.

menu64_v011.zip
Added cursor-keys as exit-key for the menu.
bugfix: cursor left/right didn't always work in a pulldown-menu-item without a submenu.
menu64_v01.zip
First release.

Snapshots (older)

menu64_v02_20250721.zip
First snapshot-release.

Top