Added start of csave command and bios write block
This commit is contained in:
@@ -557,6 +557,159 @@ wait_silence:
|
||||
ret
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Return the buffer address in hl
|
||||
; -------------------------------------------------------
|
||||
get_buffer:
|
||||
ld hl,BLOCK_BUFFER
|
||||
ret
|
||||
; -------------------------------------------------------
|
||||
; Generate a short pulse halve
|
||||
; needs d (output state)
|
||||
; uses a
|
||||
; before edge 20T
|
||||
; after edge 402T
|
||||
; -------------------------------------------------------
|
||||
gen_short:
|
||||
ld a,d ; 4T
|
||||
xor 1 ; 7T
|
||||
out (TAPE_PORT),a ; 12T
|
||||
ld d,a ; 4T
|
||||
ld a,18 ; 7T
|
||||
1$: ; loop: 21*a
|
||||
dec a ; 4T
|
||||
cp 0 ; 7T
|
||||
jp nz,1$ ; 10T
|
||||
ret ; 10T
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Generate a long pulse
|
||||
; needs d (output state)
|
||||
; uses a
|
||||
; before edge 20T
|
||||
; after edge 801T
|
||||
; -------------------------------------------------------
|
||||
gen_long:
|
||||
ld a,d ; 4T
|
||||
xor 1 ; 7T
|
||||
out (TAPE_PORT),a ; 12T
|
||||
ld d,a ; 4T
|
||||
ld a,37 ; 7T
|
||||
1$: ; loop: 21*a
|
||||
dec a ; 4T
|
||||
cp 0 ; 7T
|
||||
jp nz,1$ ; 10T
|
||||
ret ; 10T
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Generate a bit
|
||||
; needs carry (bit value)
|
||||
; needs d (output state)
|
||||
; uses a
|
||||
; -------------------------------------------------------
|
||||
gen_bit:
|
||||
jr c,1$ ; carry set: generate a one
|
||||
call gen_short ; zero: short, then long
|
||||
jp gen_long ; tail call returns to caller
|
||||
1$:
|
||||
call gen_long ; one: long, then short
|
||||
jp gen_short ; tail call returns to caller
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Generate a byte
|
||||
; needs a (byte to generate)
|
||||
; needs d (output state)
|
||||
; uses a,b,c
|
||||
; -------------------------------------------------------
|
||||
gen_byte:
|
||||
ld c,a ; preserve the byte
|
||||
ld b,8 ; 8 bits
|
||||
1$:
|
||||
sla c ;shift bit 7 into carry
|
||||
call gen_bit
|
||||
djnz 1$ ; repeat till b=0
|
||||
ret
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Generate the leader
|
||||
; needs d (output state)
|
||||
; uses a,b,c
|
||||
; -------------------------------------------------------
|
||||
gen_leader:
|
||||
; short leader
|
||||
ld b,50 ; generate 50 short pulses
|
||||
1$:
|
||||
call gen_short
|
||||
dec b
|
||||
ld a,b
|
||||
cp 0
|
||||
jr nz,1$ ; repeat if not done
|
||||
; long leader
|
||||
ld b,50 ; generate 50 long pulses
|
||||
2$:
|
||||
call gen_long
|
||||
dec b
|
||||
ld a,b
|
||||
cp 0
|
||||
jr nz,2$ ; repeat if not done
|
||||
; marker
|
||||
ld b,8 ; generate 8 short pulses
|
||||
3$:
|
||||
call gen_short
|
||||
dec b
|
||||
ld a,b
|
||||
cp 0
|
||||
jr nz,3$ ; repeat if not done
|
||||
; training byte
|
||||
ld a,055h
|
||||
call gen_byte
|
||||
ret
|
||||
|
||||
; -------------------------------------------------------
|
||||
; Write a block
|
||||
; Writes the block stored in the block buffer
|
||||
; -------------------------------------------------------
|
||||
write_block:
|
||||
push de
|
||||
push bc
|
||||
; calculate the crc16 over the block
|
||||
ld hl, BLOCK_BUFFER
|
||||
ld a, BLOCK_SIZE-2 ; dont use crc value in block
|
||||
call crc16
|
||||
ex de,hl
|
||||
ld hl, BLOCK_BUFFER+BLOCK_SIZE-2
|
||||
ld (hl),de ; save crc to block
|
||||
; Write the block
|
||||
ld a,0 ; Start with a low output
|
||||
ld d,a
|
||||
out (TAPE_PORT),a
|
||||
call gen_leader
|
||||
; Generate synchronization bytes
|
||||
ld a,05ah
|
||||
call gen_byte
|
||||
ld a,0c3h
|
||||
call gen_byte
|
||||
; write the block buffer
|
||||
ld hl, BLOCK_BUFFER
|
||||
ld e, BLOCK_SIZE
|
||||
1$:
|
||||
ld a,(hl) ; get byte from buffer
|
||||
inc hl
|
||||
call gen_byte
|
||||
dec e
|
||||
ld a,e
|
||||
cp 0
|
||||
jr nz,1$ ; repeat till done
|
||||
; Done with buffer, write 0 byte at last
|
||||
ld a,0
|
||||
call gen_byte
|
||||
; Generate space
|
||||
ld a,200
|
||||
call delay_ms
|
||||
|
||||
pop bc
|
||||
pop de
|
||||
ret
|
||||
; -------------------------------------------------------
|
||||
; Strings
|
||||
; -------------------------------------------------------
|
||||
msg_start: .db "PLAY TAPE", 0ah,0dh,00h
|
||||
|
||||
Reference in New Issue
Block a user