Skip to content

Instantly share code, notes, and snippets.

@ped7g
Created July 29, 2020 07:36
Show Gist options
  • Save ped7g/ea89274f875e172432ac9bd03de9a1a4 to your computer and use it in GitHub Desktop.
Save ped7g/ea89274f875e172432ac9bd03de9a1a4 to your computer and use it in GitHub Desktop.
fixed + cleaned up a bit source from Alexander
REAL_ORG = #3c51
DICT_BEGIN = #3c49
DATA_REG = 129
CONTROL_REG = 128
RTS_LOW = #16
RTS_HIGH = #56
MACRO CHECKSUM start?
opt push listoff ; disable listing while calculating checksum
.ptr = start?
.chk = 0
dup $ - start?
.chk = .chk ^ ({b .ptr})
.ptr = .ptr + 1
edup
opt pop ; restore listing back to original state
db .chk
ENDM
MACRO MakeAceTap filename, lastLink
dw .headerEnd - .headerblock ; TAP chunk size
.headerblock
db 0 ; type 0 - dict, FF - bytes
.name
db filename
ASSERT ($-.name) <= 10 ; check if filename is 10 bytes at most
IF ($-.name) < 10
ds 10 - ($-.name), ' ' ; fill space up to 10 bytes
ENDIF
dw dataBlockEnd - dataBlock
dw REAL_ORG
dw lastLink ; Last word link
dw #3c4c
dw #3c4c
dw #3c4f
dw dataBlockEnd
; Data chunk!
CHECKSUM .headerblock
.headerEnd
dw tapEnd - dataBlock
ENDM
device zxspectrum48
org REAL_ORG - 30 ; Space for TAP header
tapBegin:
MakeAceTap "test", uwrite.link
dataBlock:
uinit:
.name
db "UINI", 'T' + #80 ; Name
.size
dw (.end - $) ; Size
dw DICT_BEGIN ; Link
.link
db .size - .name
dw $ + 2
ld a, 3, c, CONTROL_REG : out (c), a
ld a, RTS_HIGH : out (c), a
jp (iy)
.end
uread:
.name
db "UREA", 'D' + #80
.size dw (.end - $)
dw uinit.link ; PrevLink
.link
db .size - .name
dw $ + 2
ld de, #FFFF, a, RTS_LOW : ld c, CONTROL_REG : out (c), a
in a, (c) : and 1 : jr z, .exit
in a, (DATA_REG)
ld d, 0, e, a
.exit
ld c, CONTROL_REG
ld a, RTS_HIGH : out (c), a
rst #10
jp (iy)
.end
ureadsync:
.name
db "UREAD", 'S' + #80
.size
dw (.end - $)
dw uread.link
.link
db .size - .name
dw $ + 2
ld a, RTS_LOW : ld c, CONTROL_REG : out (c), a
.waitByte
in a, (c) : and 1 : jr z, .waitByte
ld a, RTS_HIGH : out (c), a
inc c
in a, (c)
ld e, a, d, 0
rst #10
jp (iy)
.end
uwrite:
.name
db "UWRIT", 'E' + #80
.size
dw (.end - $)
dw ureadsync.link
.link
db .size - .name
dw $ + 2
rst #18
.loop
in a, (CONTROL_REG) : and 2 : jr z, .loop
ld c, DATA_REG, a, e : out (c), a
jp (iy)
.end
dataBlockEnd:
CHECKSUM dataBlock
tapEnd = $
savebin "test.tap", tapBegin, tapEnd - tapBegin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment