Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FindData:
- ld hl, transData
- ret
- FindDataCompressed:
- ld hl, transDataCompressed
- ret
- ReceiveDataSafe:
- call ReceiveData
- call FindData
- ex de,hl
- ld hl, receiveDataSafeData1
- call CopyDEStringtoHL
- call ReceiveData
- call FindData
- ex de,hl
- ld hl, receiveDataSafeData2
- call CopyDEStringtoHL
- call ReceiveData
- call FindData
- ex de,hl
- ld hl, receiveDataSafeData3
- call CopyDEStringtoHL
- call CopyDataAndRepair
- ret
- ReceiveData:
- ld a, 0
- ld (transInc), a
- ReceiveDataLoop:
- call ReceiveBit
- cp 255
- ret z
- ld b, a
- ld a, (transInc)
- ld hl, transData
- add a, l
- ld l, a
- ld a, b
- add a, 48
- ld (hl), a
- ld a, (transInc)
- inc a
- ld (transInc), a
- jp ReceiveDataLoop
- ret
- ReceiveBit:
- in a,(0)
- ld (prev), a ; store the current state
- Receive_Loop:
- in a,(0) ; get a new state
- ld b, a ; new -> b
- ld a, (prev) ; old -> a
- cp b ; if new == old then
- jp z, Receive_Loop ; loop
- ld (tmpa), a
- ld a, b
- ld (tmpb), a
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r1
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r2
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r3
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r4
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r5
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r6
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r7
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r8
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call r9
- ld a, (tmpb)
- ld b, a
- ld a, (tmpa)
- call rfin
- ld a, (fin)
- ret
- r1:
- ; 0 -> 1
- cp 0 ; if old != 0
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 1 ; if new != 1
- ret nz ; then skip this part
- ld a, 0 ; return 0
- ld (fin), a
- ret
- r2:
- ; 0 -> 2
- cp 0 ; if old != 0
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 2 ; if new != 2
- ret nz ; then skip this part
- ld a, 1 ; return 1
- ld (fin), a
- ret
- r3:
- ; 1 -> 0
- cp 1 ; if old != 1
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 0 ; if new != 0
- ret nz ; then skip this part
- ld a, 0 ; return 0
- ld (fin), a
- ret
- r4:
- ; 1 -> 2
- cp 1 ; if old != 1
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 2 ; if new != 2
- ret nz ; then skip this part
- ld a, 1 ; return 0
- ld (fin), a
- ret
- r5:
- ; 2 -> 0
- cp 2 ; if old != 2
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 0 ; if new != 0
- ret nz ; then skip this part
- ld a, 0 ; return 0
- ld (fin), a
- ret
- r6:
- ; 2 -> 1
- cp 2 ; if old != 2
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 1 ; if new != 1
- ret nz ; then skip this part
- ld a, 1 ; return 1
- ld (fin), a
- ret
- r7:
- ; 3 -> 1
- cp 3 ; if old != 3
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 1 ; if new != 1
- ret nz ; then skip this part
- ld a, 0 ; return 0
- ld (fin), a
- ret
- r8:
- ; 3 -> 2
- cp 3 ; if old != 3
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 2 ; if new != 2
- ret nz ; then skip this part
- ld a, 1 ; return 1
- ld (fin), a
- ret
- r9:
- ; 3 -> 0
- cp 3 ; if old != 3
- ret nz ; then skip this part
- ld c, a ; old -> c
- ld a, b ; new -> a
- ld b, c ; old -> b
- cp 0 ; if new != 0
- ret nz ; then skip this part
- ld a, -1 ; return -1
- ld (fin), a
- ret
- rfin:
- ld a, b ; if new != 3
- cp 3 ; then skip this part
- ret nz
- ld a, -1 ; return -1
- ld (fin), a
- ret
- ResetCable:
- ld a, 0
- out (0),a
- ret
- SendDataSafe:
- call SendData
- call pause
- call SendData
- call pause
- call SendData
- call pause
- ret
- SendData:
- ld a, 0
- ld (transSendPrev), a
- ld (transInc),a
- call ResetCable
- SendData_Loop:
- ld hl, transData
- ld a, (transInc)
- add a, l
- ld l, a
- ld a, (hl)
- cp 0
- jp z, SendData_Next
- sub 48
- call SendBit
- ld a, (transInc)
- inc a
- ld (transInc), a
- jp SendData_Loop
- SendData_Next:
- call ResetCable
- ret
- call ResetCable
- ld a, 0
- call SendBit
- ld a, 1
- call SendBit
- ld a, 0
- call SendBit
- ld a, 1
- call SendBit
- ld a, 0
- call SendBit
- ld a, 1
- call SendBit
- ld a, 0
- call SendBit
- ld a, 0
- call SendBit
- call ResetCable
- ret
- SendBit:
- cp 0
- call z, send0
- cp 1
- call z, send1
- call pause
- ret
- send0:
- ld a, (transSendPrev)
- cp 0
- call z,send0_0
- ld a, (transSendPrev)
- cp 1
- call z,send0_1
- ld a, (transSendPrev)
- cp 2
- call z,send0_2
- ld a, (transSendPrev)
- cp 3
- call z,send0_3
- ret
- send0_0:
- ld a, 2
- ld (transSendPrev), a
- out (0),a
- ret
- send0_1:
- ld a, 3
- ld (transSendPrev), a
- out (0),a
- ret
- send0_2:
- ld a, 3
- ld (transSendPrev), a
- out (0),a
- ret
- send0_3:
- ld a, 2
- ld (transSendPrev), a
- out (0),a
- ret
- send1:
- ld a, (transSendPrev)
- cp 0
- call z,send1_0
- ld a, (transSendPrev)
- cp 1
- call z,send1_1
- ld a, (transSendPrev)
- cp 2
- call z,send1_2
- ld a, (transSendPrev)
- cp 3
- call z,send1_3
- ret
- send1_0:
- ld a, 1
- ld (transSendPrev), a
- out (0),a
- ret
- send1_1:
- ld a, 2
- ld (transSendPrev), a
- out (0),a
- ret
- send1_2:
- ld a, 1
- ld (transSendPrev), a
- out (0),a
- ret
- send1_3:
- ld a, 1
- ld (transSendPrev), a
- out (0),a
- ret
- CompressData:
- ld b, 0
- ld a, (transData)
- cp \'1\'
- call z,set7
- ld a, (transData+1)
- cp \'1\'
- call z,set6
- ld a, (transData+2)
- cp \'1\'
- call z,set5
- ld a, (transData+3)
- cp \'1\'
- call z,set4
- ld a, (transData+4)
- cp \'1\'
- call z,set3
- ld a, (transData+5)
- cp \'1\'
- call z,set2
- ld a, (transData+6)
- cp \'1\'
- call z,set1
- ld a, (transData+7)
- cp \'1\'
- call z,set0
- ld a, b
- ld (transDataCompressed), a
- ret
- set7:
- ld a, %10000000
- or b
- ld b, a
- ret
- set6:
- ld a, %01000000
- or b
- ld b, a
- ret
- set5:
- ld a, %00100000
- or b
- ld b, a
- ret
- set4:
- ld a, %00010000
- or b
- ld b, a
- ret
- set3:
- ld a, %00001000
- or b
- ld b, a
- ret
- set2:
- ld a, %00000100
- or b
- ld b, a
- ret
- set1:
- ld a, %00000010
- or b
- ld b, a
- ret
- set0:
- ld a, %00000001
- or b
- ld b, a
- ret
- CopyDataAndRepair:
- ld a, 0
- ld (CopyDataAndRepairIncr), a
- CopyDataAndRepairLoop:
- ld hl, receiveDataSafeData1
- ld a, (CopyDataAndRepairIncr)
- add a, l
- ld l, a
- ld a, (hl)
- cp 0
- ret z
- cp \'1\'
- jp z, CopyDataAndRepairNext
- ld hl, receiveDataSafeData2
- ld a, (CopyDataAndRepairIncr)
- add a, l
- ld l, a
- ld a, (hl)
- cp \'1\'
- jp z, CopyDataAndRepairNext
- ld hl, receiveDataSafeData3
- ld a, (CopyDataAndRepairIncr)
- add a, l
- ld l, a
- ld a, (hl)
- cp \'1\'
- jp z, CopyDataAndRepairNext
- ld hl, transData
- ld a, (CopyDataAndRepairIncr)
- add a, l
- ld l, a
- ld (hl),\'0\'
- ld a, (CopyDataAndRepairIncr)
- inc a
- ld (CopyDataAndRepairIncr), a
- jp CopyDataAndRepairLoop
- CopyDataAndRepairNext:
- ld hl, transData
- ld a, (CopyDataAndRepairIncr)
- add a, l
- ld l, a
- ld (hl),\'1\'
- ld a, (CopyDataAndRepairIncr)
- inc a
- ld (CopyDataAndRepairIncr), a
- jp CopyDataAndRepairLoop
- ret
- CopyDEStringtoHL:
- ld a, (de)
- cp 0
- ret z
- ld (hl),a
- inc hl
- inc de
- jp CopyDEStringtoHL
- ret
- pause:
- ld hl, 6500
- ld bc, 100
- pauseloop:
- dec hl
- ld a, l
- cp 0
- jp nz, pauseloopcontinue
- ld a, h
- cp 0
- jp nz,pauseloopcontinue
- ret
- pauseloopcontinue:
- jp pauseloop
- ret
- ;01010100
- ;
- transSendPrev:
- .db 0
- transInc:
- .db 0
- transData:
- .ds 100
- transDataCompressed:
- .ds 12
- prev:
- .db 0
- tmpa:
- .db 0
- tmpb:
- .db 0
- receiveDataSafeData1:
- .ds 100
- receiveDataSafeData2:
- .ds 100
- receiveDataSafeData3:
- .ds 100
- CopyDataAndRepairIncr:
- .db 0
- fin:
- .db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement