Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .CR z80
- .ORG 0x8000
- .TF blinken.hex,ins
- SEED: .DW 0xadde
- SEED2: .DW 0xefbe
- SEED3: .DW 0x3331
- SEED4: .DW 0x5f7a
- PORT .EQU 0
- CYCLES: .DW 0xA000 ; Default delay loop length
- LAST: .DB 0x00
- CURR: .DB 0x00
- MODE: .DB 0x02
- ; MODE: Selected with buttons (when implemented)
- ; 0x01: Fast random flashes
- ; 0x02: Random flashes, random delays
- ; 0x04: Cylon
- ; 0x08: Counter
- ; 0x10:
- ; 0x20:
- ; 0x40:
- ; 0x80: Exit to monitor
- DIRECTION: .DB 0x00
- ; Current direction of chase (0=L, 1=R)
- .ORG 0x8100
- BEGIN:
- CALL modeselect
- JP begin
- EXIT: ; return to SCM
- LD a,port
- LD c,a
- LD a,0x00
- OUT (c),a
- LD a,0x01
- LD c,0x00
- RST 0x0030
- RET
- MODESELECT:
- LD a,port
- LD c,a
- IN a,(c)
- CALL nz,setmode
- LD a,(mode)
- BIT 0,a
- JP nz,fastflash
- BIT 1,a
- JP nz,standardflash
- BIT 2,a
- JP nz,cylon
- BIT 3,a
- JP nz,counter
- BIT 7,a
- JP nz,exit
- ; fall through if the selected mode is invalid
- JP nz,standardflash
- RET
- SETMODE: LD (mode),a
- ; some mode specific setup
- BIT 2,a ; cylon
- JP nz,cylonsetup
- BIT 3,a ; counter
- JP nz,countsetup
- RET
- COUNTER:
- LD a,(last)
- CALL write
- INC a
- LD (last),a
- LD bc,(cycles)
- CALL delay
- RET
- COUNTSETUP: LD a,1
- LD (last),a
- LD hl,0x1000
- LD (cycles),hl
- RET
- CYLONSETUP: LD a,0
- LD (direction),a
- LD a,0x1
- LD (last),a
- LD hl,0x1000
- LD (cycles),hl
- RET
- CYLON: LD a,(direction)
- LD d,0x10 ; counter for PCM loop
- LD b, 1
- AND b
- JP nz,cylonright
- CYLONLEFT: LD a,(last)
- RLA
- LD (curr),a
- JP cylonpcm
- CYLONRIGHT: LD a,(last)
- RRA
- LD (curr),a
- JP cylonpcm
- CYLONPCM: LD a,(curr)
- LD b,a
- LD a,(last)
- OR b
- CALL write
- LD bc,0x0080
- CALL delay
- LD a,(curr)
- CALL write
- LD bc,0x0400
- CALL delay
- DEC d
- JP nz,cylonpcm
- ; finally set the direction for next time
- LD a,(curr)
- OR a ; clear carry flag
- PUSH af
- RLA
- JP c,nextright
- POP af
- RRA
- JP c,nextleft
- JP cylondone
- NEXTRIGHT: LD a,1
- LD (direction),a
- JP cylondone
- NEXTLEFT: LD a,0
- LD (direction),a
- CYLONDONE: LD a,(curr)
- LD (last),a
- RET
- STANDARDFLASH:
- CALL RandLFSR
- CALL write
- LD bc,(cycles)
- CALL delay
- CALL randomisedelay
- RET
- FASTFLASH:
- CALL RandLFSR
- LD (last),a
- CALL write
- LD bc,0x1000
- CALL delay
- RET
- WRITE: PUSH af
- PUSH bc
- LD b,a ;writes value of A to LEDs
- LD a,port
- LD c,a
- OUT (c),b
- POP bc
- POP af
- RET
- RANDOMISEDELAY:
- CALL RandLFSR
- LD (cycles),a
- CALL RandLFSR
- LD b,a
- SRL b ; keep things speedy
- LD a,b
- LD (cycles+1),a
- RET
- DELAY: ;preload BC with desired number of cycles
- BIT 0,a ; the most expensive instruction we could find :)
- BIT 0,a
- AND 0xff
- DEC bc
- LD a,c
- OR b
- JP nz,delay
- RET
- RANDLFSR:
- LD hl,seed+4
- LD e,(hl)
- INC hl
- LD d,(hl)
- INC hl
- LD c,(hl)
- INC hl
- LD a,(hl)
- LD b,a
- RL e
- RL d
- RL c
- RLA
- RL e
- RL d
- RL c
- RLA
- RL e
- RL d
- RL c
- RLA
- LD h,a
- RL e
- RL d
- RL c
- RLA
- XOR b
- RL e
- RL d
- XOR h
- XOR c
- XOR d
- LD hl,seed+6
- LD de,seed+7
- LD bc,7
- LDDR
- LD (de),a
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement