Skip to content

Instantly share code, notes, and snippets.

View gnacu's full-sized avatar

Gregory Naçu gnacu

View GitHub Profile
salloc ;Struct Allocate
.block
lda offset
sta ptr ;Set lo addr byte
bne incoff
pha
lda #1 ;Alloc one page
jsr pgalloc
tay ;Page addr -> .Y
moveptr .macro
ldy #\1 ;Set ptr offset
lda (ptr),y ;Load lo ptr byte
pha
iny
lda (ptr),y ;Load hi ptr byte
sta ptr+1 ;Save hi ptr byte
pla
sta ptr ;Save lo ptr byte
.endm
ptr = $fb
tptr = $fd
lptr = $71
;.x .y pointer to filename string.
;ptr points to current menu entry struct
;tptr points to parsed file current line
load
cr = $0d
parserow ldy #0
lda (tptr),y ;Read first byte of
cmp #cr ;line. Chk for CR.
bne alloc
rts ;End Of Data
alloc jsr salloc ;ptr -> Empty Struct
headrow lda #0
sta (tptr),y ;Terminate string
#incptr tptr ;Points to length
lda children ;Backup current
pha ;child count
lda (tptr),y ;Load child count
sec
sbc #$40 ;Shift a,x to 1,24
;See Modifier Keys bit flags to under-
;stand these numbers. eg, " *^Q"
modlen .byte 0 ;Extra length for mods
modlens .byte 0,3,3,4,3,4,4,5
actrow lda #0
sta (ptr),y ;Terminate String
#incptr tptr ;Points to modkeys
nextnode ;Check if last sibling ptr is 0
lda lptr+1
bne chkchild
;Set this struct as the first
;child of its parent struct
#copyptr ptr,child
chkchild lda children
rootpg .byte 0
defpage .byte 0
defpgcnt .byte 0
;.x .y pointer to filename string.
mnuload ;Frees old memory. Allocs mem.
;Loads menu file and parses it.
.block
lda rootpg
freemenu bne chkchild
lda ptr+1
sta rootpg
beq menuend
ldy #1 ;Free 1 Page
jsr pgfree
chkchild ldy #childptr+1
;Module Code with table of pointer exports
;----------[ Input ]--------
.include "io.s"
.include "colors.s"
.include "kernal.s"
* = $c7c4