dhgr_viewer: add missing files

This commit is contained in:
Vince Weaver 2023-04-27 21:43:13 -04:00
parent bf13f24098
commit deb0af4914
6 changed files with 1116 additions and 0 deletions

View File

@ -0,0 +1,132 @@
; VMW Productions DHIRES/ZX02 image viewer
;
; by deater (Vince Weaver) <vince@deater.net>
; todo help menu, timed slideshow mode
; move to being a bootsector
.include "zp.inc"
.include "hardware.inc"
WHICH = $E0
hires_start:
;===================
; Init RTS disk code
;===================
jsr rts_init
;===================
; set graphics mode
;===================
jsr HOME
bit SET_GR
bit HIRES
bit FULLGR
sta AN3 ; set double hires
sta EIGHTYCOLON ; 80 column
sta SET80COL ; 80 store
bit PAGE1 ; start in page1
lda #0
sta WHICH
;===================
; Load graphics
;===================
load_loop:
;=============================
ldx WHICH
lda bin_filenames_low,X
sta OUTL
lda bin_filenames_high,X
sta OUTH
lda aux_filenames_low,X
sta INL
lda aux_filenames_high,X
sta INH
jsr load_image
wait_until_keypress:
lda KEYPRESS ; 4
bpl wait_until_keypress ; 3
bit KEYRESET ; clear the keyboard buffer
cmp #$88 ; left button
bne inc_which
dec WHICH
bpl which_ok
ldx #(MAX_FILES-1)
bne store_which ; bra
inc_which:
inc WHICH
ldx WHICH
cpx #MAX_FILES
bcc which_ok ; blt
ldx #0
store_which:
stx WHICH
which_ok:
jmp load_loop
;==========================
; Load Image
;===========================
load_image:
bit PAGE1
jsr opendir_filename ; open and read entire file into memory
lda #<$A000
sta zx_src_l+1
lda #>$A000
sta zx_src_h+1
lda #$20
jsr zx02_full_decomp
; auxiliary part
lda INL
sta OUTL
lda INH
sta OUTH
jsr opendir_filename ; open and read entire file into memory
bit PAGE2
lda #<$A000
sta zx_src_l+1
lda #>$A000
sta zx_src_h+1
lda #$20
jsr zx02_full_decomp
rts
.include "zx02_optim.s"
.include "rts.s"
;

View File

@ -0,0 +1,84 @@
;; HARDWARE LOCATIONS
KEYPRESS = $C000
KEYRESET = $C010
;; SOFT SWITCHES
CLR80COL = $C000 ; PAGE1/PAGE2 normal
SET80COL = $C001 ; PAGE1/PAGE2 switches PAGE0 in Aux instead
EIGHTYCOLOFF = $C00C
EIGHTYCOLON = $C00D
SPEAKER = $C030
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
TEXTGR = $C053
PAGE1 = $C054
PAGE2 = $C055
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
AN3 = $C05E ; Annunciator 3
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
;; BASIC ROUTINES
NORMAL = $F273
;; MONITOR ROUTINES
HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y
CLRSCR = $F832 ;; Clear low-res screen
CLRTOP = $F836 ;; clear only top of low-res screen
SETCOL = $F864 ;; COLOR=A
TEXT = $FB36
TABV = $FB5B ;; VTAB to A
BASCALC = $FBC1 ;;
VTAB = $FC22 ;; VTAB to CV
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
SETINV = $FE80 ;; INVERSE
SETNORM = $FE84 ;; NORMAL
COUT = $FDED ;; output A to screen
COUT1 = $FDF0 ;; output A to screen
COLOR_BLACK = 0
COLOR_RED = 1
COLOR_DARKBLUE = 2
COLOR_PURPLE = 3
COLOR_DARKGREEN = 4
COLOR_GREY = 5
COLOR_MEDIUMBLUE = 6
COLOR_LIGHTBLUE = 7
COLOR_BROWN = 8
COLOR_ORANGE = 9
COLOR_GREY2 = 10
COLOR_PINK = 11
COLOR_LIGHTGREEN = 12
COLOR_YELLOW = 13
COLOR_AQUA = 14
COLOR_WHITE = 15
COLOR_BOTH_BLACK = $00
COLOR_BOTH_RED = $11
COLOR_BOTH_DARKBLUE = $22
COLOR_BOTH_DARKGREEN = $44
COLOR_BOTH_GREY = $55
COLOR_BOTH_MEDIUMBLUE = $66
COLOR_BOTH_LIGHTBLUE = $77
COLOR_BOTH_BROWN = $88
COLOR_BOTH_ORANGE = $99
COLOR_BOTH_PINK = $BB
COLOR_BOTH_LIGHTGREEN = $CC
COLOR_BOTH_YELLOW = $DD
COLOR_BOTH_AQUA = $EE
COLOR_BOTH_WHITE = $FF

View File

@ -0,0 +1,2 @@
5 HOME
105 PRINT CHR$ (4)"BRUN DHIRES"

557
graphics/dhgr_viewer/rts.s Normal file
View File

@ -0,0 +1,557 @@
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assembled with ca65 -- vmw
; added code to patch it to run from current disk slot -- vmw
; USAGE:
; file to load in namlo:namhi
; Loads file contents to addr from filesystem
; also stores filesize in ldsizel:ldsizeh
dirbuf = $900
; note, don't put this immediately below
; the value being read as destaddr-4
; is temporarily overwritten during read
; process
;======================
; filename to open is 30-character Apple text:
filename:
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0
;=======================================================
;=======================================================
;=======================================================
;unhook DOS and build nibble table
rts_init:
; patch to use current drive
; locate input paramater list
jsr $3E3
; result is in A:Y
sta $FF
sty $FE
ldy #1
lda ($FE),y
; list+1 should have slot<<8
ora #$80 ; add in $80
; c0e0
sta mlsmc06+1
; c0e8
clc
adc #8
sta mlsmc02+1
; c0e9
clc
adc #1
sta mlsmc01+1
; c0ec
clc
adc #3
sta mlsmc03+1
sta mlsmc04+1
sta mlsmc05+1
jsr $fe93 ; clear COUT
jsr $fe89 ; clear KEYIN
;========================
; Create nibble table
; Note: the table starts 16 bytes in, and is sparse
; so it doesn't entirely look like the DOS33 table at
ldy #0
ldx #3
L1: stx $3c ; store tempx (3?)
txa ; a=x (a=3)
asl ; a*=2 (a=6)
bit $3c ; a&tempx, set N/V (a=6)
beq L3 ; if 0, skip to L3
ora $3c ; a|=tempx (a=7)
eor #$ff ; a=~a (a=f8)
and #$7e ; a&=0x7e 0111 1110 (a=78)
L2: bcs L3 ; this set way back at asl??
lsr ; a>>1 a=3c c=0
; a=1e c=0
; a=0f c=0
; a=07 c=1
bne L2 ; if a!=0 goto l2
tya ; if a==0, a=y
sta nibtbl, x ; write out to table
iny ; increment y
L3: inx ; increment x x=4, a=0f
bpl L1 ; loop while high bit not set
rts
;=======================================================
;=======================================================
;=======================================================
; filename in OUTL:OUTH
opendir_filename:
; clear out the filename with $A0 (space)
lda #<filename
sta namlo
lda #>filename
sta namhi
ldy #29
wipe_filename_loop:
lda #$A0
sta (namlo),Y
dey
bpl wipe_filename_loop
ldy #0
copy_filename_loop:
lda (OUTL),Y
beq copy_filename_done
sta (namlo),Y
iny
bne copy_filename_loop
copy_filename_done:
; fallthrough
;=======================================================
;=======================================================
;=======================================================
;===========================
; opendir
;===========================
; turn on drive and read volume table of contents
opendir:
mlsmc01:lda $c0e9 ; turn slot#6 drive on
ldx #0
stx adrlo ; zero out adrlo
stx secsize ; zero out secsize
lda #$11 ; a=$11 (VTOC)
jsr readdirsec
firstent:
lda dirbuf+1
; lock if entry not found
entry_not_found:
beq entry_not_found
; read directory sector
ldx dirbuf+2
jsr seekread1
ldy #7 ;number of directory entries in a sector
ldx #$2b ;offset of filename in directory entry
nextent:
tya
pha ; was **phy**
txa
pha ; was **phx**
ldy #$1d
; match name backwards (slower but smaller)
L4:
lda (namlo), y
cmp dirbuf, x
beq foundname
pla
; move to next directory in this block, if possible
clc
adc #$23
tax
pla
tay ; was **ply**
dey
bne nextent
beq firstent ; was **bra**
foundname:
dex
dey
bpl L4
pla
tay ; was **ply**
pla
; read track/sector list
lda dirbuf-32, y
ldx dirbuf-31, y
jsr seekread1
; read load offset and length info only, initially
lda #<filbuf
sta adrlo
lda #4
sta secsize
lda dirbuf+12
ldx dirbuf+13
ldy #>filbuf
jsr seekread
; reduce load offset by 4, to account for offset and length
sec
lda filbuf
sbc #4
sta adrlo
lda filbuf+1
sbc #0
sta adrhi
; save on stack bytes that will be overwritten by extra read
ldy #3
L5:
lda (adrlo), y
pha
dey
bpl L5
lda adrhi
pha
lda adrlo
pha
; increase load size by 4, to account for offst and length
lda filbuf+2
sta ldsizel ; store out raw size
adc #3
sta sizelo
sta secsize
lda filbuf+3
sta ldsizeh ; store out raw size
adc #0
sta sizehi
sta ldsizeh
beq readfirst
lda #0 ; was **stz secsize**
sta secsize
readfirst:
ldy #$0c
; read a file sector
readnext:
tya
pha
lda dirbuf, y ; A = track
ldx dirbuf+1, y ; x = sector
jsr seekread1
pla
tay
; if low count is non-zero then we are done
; (can happen only for partial last block)
lda secsize
bne readdone
; continue if more than $100 bytes left
dec sizehi
bne L6
; set read size to min(length, $100)
lda sizelo
beq readdone
sta secsize
L6:
inc adrhi
iny
iny
bne readnext
; save current address for after t/s read
lda adrhi
pha
lda adrlo
pha
lda #0
sta adrlo ; was **stz adrlo**
; read next track/sector sector
lda dirbuf+1
ldx dirbuf+2
jsr readdirsec
clc
; restore current address
readdone:
pla
; sta adrhi
; pla
sta adrlo ; code originally had this backwards
pla
sta adrhi
bcc readfirst
mlsmc02:lda $c0e8
; restore from stack bytes that were overwritten by extra read
ldx #3
ldy #0
L7:
pla
sta (adrlo), y
iny
dex
bpl L7
rts
;======================
; readdirsec
;======================
; a = track?
; x = sector?
readdirsec:
ldy #>dirbuf
seekread:
sty adrhi
seekread1:
sta phase
lda sectbl, x
sta reqsec
jsr readadr
; if track does not match, then seek
cpx phase
beq checksec
jsr seek
;=========================================
; re merge in with qkumba's recent changes
; to fix seek problem?
;=========================================
; [re-]read sector
re_read_addr:
jsr readadr
checksec:
cmp reqsec
bne re_read_addr
;=========================
; read sector data
;=========================
readdata:
jsr readd5aa
eor #$ad ; zero A if match
bne re_read_addr
L12:
mlsmc03:ldx $c0ec ; read until valid data (high bit set)
bpl L12
eor nibtbl-$80, x
sta bit2tbl-$aa, y
iny
bne L12
L13:
mlsmc04:ldx $c0ec ; read until valid data (high bit set)
bpl L13
eor nibtbl-$80, x
sta (adrlo), y ; the real address
iny
cpy secsize
bne L13
ldy #0
L14:
ldx #$a9
L15:
inx
beq L14
lda (adrlo), y
lsr bit2tbl-$aa, x
rol
lsr bit2tbl-$aa, x
rol
sta (adrlo), y
iny
cpy secsize
bne L15
rts
; no tricks here, just the regular stuff
;=======================
; readaddr -- read the address field
;=======================
; Find address field, put track in cutrk, sector in tmpsec
readadr:
jsr readd5aa
cmp #$96
bne readadr
ldy #3 ; three?
; first read volume/volume
; then track/track
; then sector/sector?
adr_read_two_bytes:
tax
jsr readnib
rol
sta tmpsec
jsr readnib
and tmpsec
dey
bne adr_read_two_bytes
rts
;========================
; make sure we see the $D5 $AA pattern
readd5aa:
L16:
jsr readnib
L17:
cmp #$d5
bne L16
jsr readnib
cmp #$aa
bne L17
tay ; we need Y=#$AA later
readnib:
mlsmc05:lda $c0ec ; read until valid (high bit set)
bpl readnib
seekret:
rts
;=====================
; SEEK
;=====================
; current track in X?
; desired track in phase
seek:
ldy #0
sty step
asl phase ; multiply by two
txa ; current track?
asl ; mul by two
copy_cur:
tax
sta tmptrk
sec
sbc phase
beq L22
bcs L18
eor #$ff
inx
bcc L19
L18:
sbc #1
dex
L19:
cmp step
bcc L20
lda step
L20:
cmp #8
bcs L21
tay
sec
L21:
txa
pha
ldx step1, y
L22:
php
bne L24
L23:
clc
lda tmptrk
ldx step2, y
L24:
stx tmpsec
and #3
rol
tax
lsr
mlsmc06:lda $c0e0, x
L25:
ldx #$12
L26:
dex
bpl L26
dec tmpsec
bne L25
bcs L23
plp
beq seekret
pla
inc step
bne copy_cur
step1: .byte $01, $30, $28, $24, $20, $1e, $1d, $1c
step2: .byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c
sectbl: .byte $00,$0d,$0b,$09,$07,$05,$03,$01,$0e,$0c,$0a,$08,$06,$04,$02,$0f
; From $BA96 of DOS33
nibtbl: .res 128 ; = *
; .byte $00,$01,$98,$99,$02,$03,$9C,$04 ; $BA96 ; 00
; .byte $05,$06,$A0,$A1,$A2,$A4,$A4,$A5 ; $BA9E ; 08
; .byte $07,$08,$A8,$A9,$AA,$09,$0A,$0B ; $BAA6 ; 10
; .byte $0C,$0D,$B0,$B1,$0E,$0F,$10,$11 ; $BAAE ; 18
; .byte $12,$13,$B8,$14,$15,$16,$17,$18 ; $BAB6 ; 20
; .byte $19,$1A,$C0,$C1,$C2,$C3,$C4,$C5 ; $BABE ; 28
; .byte $C6,$C7,$C8,$C9,$CA,$1B,$CC,$1C ; $BAC6 ; 30
; .byte $1D,$1E,$D0,$D1,$D2,$1E,$D4,$D5 ; $BACE ; 38
; .byte $20,$21,$D8,$22,$23,$24,$25,$26 ; $BAD6 ; 40
; .byte $27,$28,$E0,$E1,$E2,$E3,$E4,$29 ; $BADE ; 48
; .byte $2A,$2B,$E8,$2C,$2D,$2E,$2F,$30 ; $BAE6 ; 50
; .byte $31,$32,$F0,$F1,$33,$34,$35,$36 ; $BAEE ; 58
; .byte $37,$38,$F8,$39,$3A,$3B,$3C,$3D ; $BAF6 ; 60
; .byte $3E,$3F,$13,$00,$01,$02,$01,$00 ; $BAFE ; 68
; .byte $00,$00,$00,$00,$00,$00,$00,$00
; .byte $00,$00,$00,$00,$00,$00,$00,$00
bit2tbl: .res 86 ; = nibtbl+128
filbuf: .res 4 ; = bit2tbl+86
;dataend = filbuf+4

182
graphics/dhgr_viewer/zp.inc Normal file
View File

@ -0,0 +1,182 @@
;; Zero Page
;; ZX0 addresses
ZX0_src = $00
ZX0_dst = $02
offset = $04
bitr = $06
pntr = $07
WHICH_LOAD = $09
CURRENT_DISK = $0A
;; Zero page monitor routines addresses
WNDLFT = $20
WNDWDTH = $21
WNDTOP = $22
WNDBTM = $23
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
H2 = $2C
V2 = $2D
MASK = $2E
COLOR = $30
;INVFLG = $32
; dos33 zero page = 26-2f, 35-38, 3e 3f 40-4d
; overlap applesoft 67-6a,6f,70,af,b0,ca-cd,d8
; DOS33: Confirmed kills $68
RWTSL = $60
RWTSH = $61
DOSBUFL = $62
DOSBUFH = $63
FILEML = $64
FILEMH = $65
FRAME = $60
FRAMEH = $61
WAITING = $62
LETTERL = $63
LETTERH = $64
LETTERX = $65
LETTERY = $66
LETTERD = $67
LETTER = $68
BLARGH = $69
;FACTOR_I = $66
;FACTOR_F = $67
;DX_I = $68
;DX_F = $69
;SPACEX_I = $6A
;SPACEX_F = $6B
;CX_I = $6C
;CX_F = $6D
;DY_I = $6E
;DY_F = $6F
ZPOS = $78
REGISTER_DUMP = $70
A_FINE_TONE = $70
A_COARSE_TONE = $71
B_FINE_TONE = $72
B_COARSE_TONE = $73
C_FINE_TONE = $74
C_COARSE_TONE = $75
NOISE = $76
ENABLE = $77
A_VOLUME = $78
B_VOLUME = $79
C_VOLUME = $7A
ENVELOPE_FINE = $7B
ENVELOPE_COARSE = $7C
ENVELOPE_SHAPE = $7D
COPY_OFFSET = $7E
DECODER_STATE = $7F
REGISTER_DUMP2 = $80
A_FINE_TONE2 = $80
A_COARSE_TONE2 = $81
B_FINE_TONE2 = $82
B_COARSE_TONE2 = $83
C_FINE_TONE2 = $84
C_COARSE_TONE2 = $85
NOISE2 = $86
ENABLE2 = $87
A_VOLUME2 = $88
B_VOLUME2 = $89
C_VOLUME2 = $8A
ENVELOPE_FINE2 = $8B
ENVELOPE_COARS2 = $8C
ENVELOPE_SHAPE2 = $8D
LYRICSL = $8E
LYRICSH = $8F
FRAME_COUNT = $90
MB_VALUE = $91
MB_ADDRL = $91
MB_ADDRH = $92
DONE_PLAYING = $93
MB_CHUNK_OFFSET = $94
MB_FRAME = $94
MB_PATTERN = $95
CHUNKSIZE = $95
LZ4_DONE = $96
DECODE_ERROR = $97
COPY_TIME = $98
DECOMPRESS_TIME = $99
TIME_TAKEN = $9A
LYRICS_ACTIVE = $9B
;FORTYCOL = $9C
CURSOR = $9D
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related
;COLOR1 = $E0
;COLOR2 = $E1
;MATCH = $E2
XX = $E3
YY = $E4
HGR_COLOR = $E4
;SHIPY = $E4
;YADD = $E5
;LOOP = $E6
;MEMPTRL = $E7
;MEMPTRH = $E8
;NAMEL = $E9
;NAMEH = $EA
;NAMEX = $EB
;CHAR = $EC
INL = $EE
INH = $EF
OUTL = $FE
OUTH = $FF
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assembled with ca64 -- vmw
; added code to patch it to run from current disk slot -- vmw
adrlo = $26 ; constant from boot prom
adrhi = $27 ; constant from boot prom
tmpsec = $3c ; constant from boot prom
reqsec = $3d ; constant from boot prom
sizelo = $44
sizehi = $45
secsize = $46
ldsizel = $f0
ldsizeh = $f1
namlo = $fb
namhi = $fc
step = $fd ; state for stepper motor
tmptrk = $fe ; temporary copy of current track
phase = $ff ; current phase for /seek

View File

@ -0,0 +1,159 @@
; De-compressor for ZX02 files
; ----------------------------
;
; Decompress ZX02 data (6502 optimized format), optimized for speed and size
; 138 bytes code, 58.0 cycles/byte in test file.
;
; Compress with:
; zx02 input.bin output.zx0
;
; (c) 2022 DMSC
; Code under MIT license, see LICENSE file.
;ZP=$80
;offset = ZP+0
;ZX0_src = ZP+2
;ZX0_dst = ZP+4
;bitr = ZP+6
;pntr = ZP+7
; Initial values for offset, source, destination and bitr
;zx0_ini_block:
; .byte $00, $00, <comp_data, >comp_data, <out_addr, >out_addr, $80
;--------------------------------------------------
; Decompress ZX0 data (6502 optimized format)
zx02_full_decomp:
; ; Get initialization block
; ldy #7
;
;copy_init: lda zx0_ini_block-1, y
; sta offset-1, y
; dey
; bne copy_init
sta ZX0_dst+1 ; page to output to in A
zx_src_l:
ldy #$dd
sty ZX0_src
zx_src_h:
ldy #$dd
sty ZX0_src+1
ldy #$80
sty bitr
ldy #0
sty offset
sty offset+1
sty ZX0_dst ; always on even page
; Decode literal: Ccopy next N bytes from compressed file
; Elias(length) byte[1] byte[2] ... byte[N]
decode_literal:
jsr get_elias
cop0: lda (ZX0_src), y
inc ZX0_src
bne plus1
inc ZX0_src+1
plus1: sta (ZX0_dst),y
inc ZX0_dst
bne plus2
inc ZX0_dst+1
plus2: dex
bne cop0
asl bitr
bcs dzx0s_new_offset
; Copy from last offset (repeat N bytes from last offset)
; Elias(length)
jsr get_elias
dzx0s_copy:
lda ZX0_dst
sbc offset ; C=0 from get_elias
sta pntr
lda ZX0_dst+1
sbc offset+1
sta pntr+1
cop1:
lda (pntr), y
inc pntr
bne plus3
inc pntr+1
plus3: sta (ZX0_dst),y
inc ZX0_dst
bne plus4
inc ZX0_dst+1
plus4: dex
bne cop1
asl bitr
bcc decode_literal
; Copy from new offset (repeat N bytes from new offset)
; Elias(MSB(offset)) LSB(offset) Elias(length-1)
dzx0s_new_offset:
; Read elias code for high part of offset
jsr get_elias
beq exit ; Read a 0, signals the end
; Decrease and divide by 2
dex
txa
lsr ; @
sta offset+1
; Get low part of offset, a literal 7 bits
lda (ZX0_src), y
inc ZX0_src
bne plus5
inc ZX0_src+1
plus5:
; Divide by 2
ror ; @
sta offset
; And get the copy length.
; Start elias reading with the bit already in carry:
ldx #1
jsr elias_skip1
inx
bcc dzx0s_copy
; Read an elias-gamma interlaced code.
; ------------------------------------
get_elias:
; Initialize return value to #1
ldx #1
bne elias_start
elias_get: ; Read next data bit to result
asl bitr
rol ; @
tax
elias_start:
; Get one bit
asl bitr
bne elias_skip1
; Read new bit from stream
lda (ZX0_src), y
inc ZX0_src
bne plus6
inc ZX0_src+1
plus6: ;sec ; not needed, C=1 guaranteed from last bit
rol ;@
sta bitr
elias_skip1:
txa
bcs elias_get
; Got ending bit, stop reading
exit:
rts