Hacker's Edge Game Guide: Programming/Example program: password.asm

Example program: password.asm
Sept. 4, 2014
Last updated at Jan. 1, 2018

Here is an example program which requests a password and checks it against an internal variable, it should be assembled using the ca65 Assembler along with the Hacker's Edge development kit.

.import __IOBASE__
.export _main

.include "kernel.inc"
.include "ioapi.inc"

.rodata

okmsg:
    .byte "That is correct!", $a,$0

failmsg:
    .byte "Wrong Password.", $a
    .byte "HINT: Read the source code.  Press Ctrl-C to abort.", $a,$0

prompt:
    .byte "Password? ", $0

password:
    .byte "1234", $0

.bss

buffer: .res 40, $0

.code

_main: lda TCNTL
       ora #TMASK
       sta TCNTL
       lda #password
       sta PARAM1+1
       lda #buffer
       sta PARAM2+1
ask_password:
       lda #prompt
       jsr _print
       lda #buffer
       jsr _input
       jsr _cmpstr
       lda RESULT
       bne show_error
       lda #okmsg
       jsr _print
       brk
show_error:
       lda #failmsg
       jsr _print
       jmp ask_password

This example is fairly complex, but shows what you can do with user input to create a basic password request.