Skip to content

Instantly share code, notes, and snippets.

@mediocregopher
Created October 22, 2012 12:28
Show Gist options
  • Select an option

  • Save mediocregopher/3931292 to your computer and use it in GitHub Desktop.

Select an option

Save mediocregopher/3931292 to your computer and use it in GitHub Desktop.
.global _c_int00 ;This assembler directive allows _c_int00 to be a
;global variable. This tells the linker where your
;program (.text code) begins and where to boot from.
;***************************** Program Constants ****************************************
; Creating constants using the .set assembler directive. This should be at the top of your
; program. This is like a define statement in C.
data_sect .set 0xa000 ;constant that is actually the starting addr of .data section
bss_sect .set 0xb000 ;constant that is actually the starting addr of .bss section
gpamux .set 0x6f86
gpadir .set 0x6f8a
gpadat .set 0x6fc0
gpbmux .set 0x6F96
gpcmux .set 0x6FA6
pclkcr3 .set 0x7020
;****************************************************************************************
;******************* DATA ALLOCATION SECTION - Variables/Data ***************************
; Data can go before or after your program code but should not be placed in the middle
; nof a program for clarity reasons.
.data ;data section, see the command linker file, this puts the
;following data defined below in a block of internal SRAM
;starting at 0xA000.
key_pressed .word 0xff
count .word 0
;****************************************************************************************
.text ;Program section, see the command linker file, program code
;should be placed in the text section which starts at 0x9000
_c_int00: ;This label tells the linker where the entry (starting) point for
;the first instruction in your program.
s EALLOW
PUSH DP
SETC OBJMODE ;allow 32 bit mov instructions
MOVZ DP,#0x7029>>6 ;turn off that pesky watchdog timer
MOV @7029h,#0x68
POP DP
MOV AR0,#gpbmux
MOV *AR0,#0x3C0 ;Enable R/W and CS0
MOV AR0,#gpcmux
MOV *AR0,#0xffff
MOV AR0,#gpcmux+1
MOV *AR0,#0xffff ;Enable data7:0
MOV AR0,#pclkcr3 ;Enable CS0
MOV *AR0,#0x1000
MOV AR0,#gpamux
MOV *AR0,#0
INC AR0
MOV *AR0,#0
INC AR0
MOV *AR0,#0
INC AR0
MOV *AR0,#0 ;Setting GPAMUX1/2 to 0
MOV AR0,#gpadir
MOV *AR0,#0x00ff ;Keypad column read/switchs/leds
INC AR0
MOV *AR0,#0x1f ;Keypad row write
MOV AR0,#gpadat
MOV AR1,#gpadat+1
MOV AR3,#key_pressed
MOV AR4,#count
MOV AR5,#0x4000
MOV *AR0,#0xff ;Initial clear
LOOP LC CHECK
B LOOP,UNC
CHECK MOV AR2,#0xff
MOV *AR1,#0x7 ;Put 7
NOP
NOP
NOP
NOP
NOP
NOP
MOV AL,*AR0
LSR AL,#12
MOV AH,#0x7 ;Checking for 7
MOV AR2,#0x1
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xB ;Checking for B
MOV AR2,#0x2
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xD ;Checking for D
MOV AR2,#0x3
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xE ;Checking for E
MOV AR2,#0xA
CMP AH,AL
B GEN_RET,EQ
MOV *AR1,#0xb ;Put B
NOP
NOP
NOP
NOP
NOP
NOP
MOV AL,*AR0
LSR AL,#12
MOV AH,#0x7 ;Checking for 7
MOV AR2,#0x4
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xB ;Checking for B
MOV AR2,#0x5
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xD ;Checking for D
MOV AR2,#0x6
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xE ;Checking for E
MOV AR2,#0xB
CMP AH,AL
B GEN_RET,EQ
MOV *AR1,#0xd ;Put D
NOP
NOP
NOP
NOP
NOP
NOP
MOV AL,*AR0
LSR AL,#12
MOV AH,#0x7 ;Checking for 7
MOV AR2,#0x7
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xB ;Checking for B
MOV AR2,#0x8
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xD ;Checking for D
MOV AR2,#0x9
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xE ;Checking for E
MOV AR2,#0xc
CMP AH,AL
B GEN_RET,EQ
MOV *AR1,#0xe ;Put E
NOP
NOP
NOP
NOP
NOP
NOP
MOV AL,*AR0
LSR AL,#12
MOV AH,#0x7 ;Checking for 7
MOV AR2,#0xe
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xB ;Checking for B
MOV AR2,#0x0
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xD ;Checking for D
MOV AR2,#0xf
CMP AH,AL
B GEN_RET,EQ
MOV AH,#0xE ;Checking for E
MOV AR2,#0xd
CMP AH,AL
B GEN_RET,EQ
MOV AR2,#0xff
;AR0 -> GPADAT
;AR2 -> value pressed (or ff if none pressed)
;AR3 -> *key_pressed
;AR4 -> *count
GEN_RET LC DELAY
MOV AH,*AR3
MOV AL,AR2
CMP AH,AL
B EZRET,EQ ;If current value is same as last, return
MOV *AR3,AL ;Otherwise move current pressed into memory, we still
;have the old one in AH
MOV AR7,AH ;Temporarily put old pressed in AR7
MOV AH,#0xff
CMP AH,AL ;If current value is 0xff, we know we have a key lift
B DOINC,EQ
LRET
DOINC MOV AH,AR7 ;Put old back in AH, it's the real value
MOV AL,#0
CMP AH,AL
B DOCLEAR,EQ
MOV AL,*AR4
ADD AH,AL
MOV *AR4,AH
MOV *AR5,AH
NOT AH
MOV *AR0,AH
LRET
DOCLEAR MOV *AR4,#0
MOV *AR0,#0xff
MOV *AR5,#0
LRET
;Delays a lot, clobbers AL
DELAY MOV AL,#0x3FFF
MOV *AR1,#0x10
DELAYI DEC AL
B DELAYI,NEQ
MOV *AR1,#0
LRET
EZRET LRET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment