Skip to content

Instantly share code, notes, and snippets.

@aliva
Last active December 16, 2015 06:09
Show Gist options
  • Save aliva/5389724 to your computer and use it in GitHub Desktop.
Save aliva/5389724 to your computer and use it in GitHub Desktop.
z80 code for class lab 4
JP 1800H
ORG 1800H
MAIN:
CALL DISPLAY
CALL TOUCH
JP MAIN
HLT
ORG 1850H
DELAY:
PUSH AF
PUSH BC
LD A,0FFH
DELAYOUTER:
LD C,0FFH
DELAYINNER:
DEC C
JP NZ,DELAYINNER
DEC A
JP NZ,DELAYOUTER
POP BC
POP AF
RET
ORG 1900H
DISPLAY:
PUSH AF
PUSH BC
PUSH HL
LD HL,1A00H
LD B,06H
LD C,20H
LOOPDISPLAY:
LD A,C
SET 7,A
SET 6,A
OUT (02H),A
LD A,(HL)
OUT (01H),A
INC L
SRA C
CALL DELAY
DJNZ LOOPDISPLAY
POP HL
POP BC
POP AF
RET
ORG 1950H
TOUCH:
PUSH AF
LD A,C0H
OUT (02H),A
IN A,(00H)
SET 6,A
SET 7,A
CPL
OR A
JP Z,TOUCHNONE
CALL KEYCHECK
TOUCHNONE:
POP AF
RET
ORG 1b00H
KEYCHECK:
PUSH BC
PUSH HL
LD H,00H
BIT 1,A
JP Z,CHCKR2
LD H,10H
CHCKR2:
BIT 2,A
JP Z,CHKR3
LD H,20H
CHKR3:
BIT 3,A
JP Z,CHKREND
LD H,30H
CHKREND:
LD L,00H
LD A,0FDH
OUT (02H),A
IN A,(00H)
BIT 1,A
JP NZ,CHKC2
LD L,01H
CHKC2:
LD A,0FBH
OUT (02H),A
IN A,(00H)
BIT 2,A
JP NZ,CHKC3
LD L,02H
CHKC3:
LD A,0F7H
OUT (02H),A
IN A,(00H)
BIT 3,A
JP NZ,CHKCEND
LD L,03H
CHKCEND:
LD A,L
ADD A,H
LD L,A
LD H,1EH
LD A,(HL)
CALL MOVE
CALL DELAY
POP HL
POP BC
RET
ORG 1C00H
MOVE:
PUSH BC
PUSH IX
LD C,A
LD B,05H
LPMOVE:
LD IX,1A04H
LD A,(IX+0)
LD (IX+1),A
DEC IX
DJNZ LPMOVE
LD IX,1A00H
LD (IX+0),A
POP IX
POP BC
RET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment