progress on FAT16 support

This commit is contained in:
Dennis Gunia
2024-01-12 13:29:20 +01:00
parent ee2f22df09
commit 507eb3a017
40 changed files with 19699 additions and 6346 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
; Z8C Bootloader
; 2022 by Dennis Gunia
BTLDR_ENTRY:
;ld SP, 0ffffh ; set stack pointer
;Setup Serial Interface
LD A,01001111b ; External Trigger, Time Constant Follows
OUT (CS_CTC_0),A
IN A,(CS_DIP) ; Read BAUD from DIP-Switches
OUT (CS_CTC_0),A
LD A,00110000b ;write into WR0: error reset, select WR0
OUT (CS_SIO_A_C),A
LD a,018h ;write into WR0: channel reset
OUT (CS_SIO_A_C),A
LD a,004h ;write into WR0: select WR4
OUT (CS_SIO_A_C),A
;LD a,04h ;write into WR4: clkx1,1 stop bit, no parity
LD a,01000100b ;write into WR4: clkx16,1 stop bit, no parity
OUT (CS_SIO_A_C),A
LD a,005h ;write into WR0: select WR5
OUT (CS_SIO_A_C),A
LD a,11101000b ;DTR inactive, TX 8bit, BREAK off, TX on, RTS inactive
OUT (CS_SIO_A_C),A
LD a,01h ;write into WR0: select WR1
OUT (CS_SIO_A_C),A
LD a,00000100b ;no interrupt in CH B, special RX condition affects vect
OUT (CS_SIO_A_C),A
LD a,02h ;write into WR0: select WR2
OUT (CS_SIO_A_C),A
LD a,0h ;write into WR2: cmd line int vect (see int vec table)
;bits D3,D2,D1 are changed according to RX condition
OUT (CS_SIO_A_C),A
LD a,003h ;write into WR0: select WR3
OUT (CS_SIO_A_C),A
LD a,0C1h ;RX 8bit, auto enable off, RX on
OUT (CS_SIO_A_C),A
BTLDR_STARTUP_MSG:
LD HL,[S_BTLDR_STARTUP_MSG]
BTLDR_STARTUP_MSG_LOOP:
LD A,(HL)
OR A
JR Z, BTLDR_INPUT
CALL BTLDR_SUB_WRITEA
INC HL
JR BTLDR_STARTUP_MSG_LOOP
BTLDR_INPUT:
; Byte 1 & 2 = Length
CALL BTLDR_SUB_INPUT_READ
LD B, A
CALL BTLDR_SUB_INPUT_READ
LD C, A
; Byte 3 & 4 = Offset / Start address
CALL BTLDR_SUB_INPUT_READ
LD H, A
CALL BTLDR_SUB_INPUT_READ
LD L, A
; Byte 5+ = Payload
BTLDR_INPUT_1:
CALL BTLDR_SUB_INPUT_READ
LD (HL),A ;Store byte
DEC BC
LD A,H
OR A.L
JR Z, BTLDR_DONE
INC HL
JR BTLDR_INPUT_1
BTLDR_DONE:
RET
; Strings
S_BTLDR_STARTUP_MSG:
db "Z8C BTLDR.S V0.1 by Dennis Gunia [RDY] ",0
; Subroutines
BTLDR_SUB_WRITEA:
OUT (CS_SIO_A_D),A
BTLDR_SUB_WRITEA_WAIT:
XOR A
INC A
OUT (CS_SIO_A_C),A
IN A,(CS_SIO_A_C)
BIT 0,A
JR Z, BTLDR_SUB_WRITEA_WAIT
RET
BTLDR_SUB_RTS_OFF:
ld a,005h ;write into WR0: select WR5
out (CS_SIO_A_C),A
ld a,0E8h ;DTR active, TX 8bit, BREAK off, TX on, RTS inactive
out (CS_SIO_A_C),A
ret
BTLDR_SUB_RTS_ON:
ld a,005h ;write into WR0: select WR5
out (CS_SIO_A_C),A
ld a,0EAh ;DTR active, TX 8bit, BREAK off, TX on, RTS active
out (CS_SIO_A_C),A
ret
BTLDR_SUB_INPUT_READ:
CALL BTLDR_SUB_RTS_ON
XOR A
OUT (CS_SIO_A_C), a
IN A, (CS_SIO_A_C)
AND 1
JR Z, BTLDR_SUB_INPUT_READ ;LOOP IF BUFFER EMPTY
CALL BTLDR_SUB_RTS_OFF
IN A, (CS_SIO_A_D)
RET

View File

@@ -0,0 +1,78 @@
debug_init:
ld A,VAR_CONSOLE_CONF ; Setup CTC
out (IO_CTC0_C0),A ; Controll word, software reset, time constant follows, CLK/TRG starts timer
ld A,VAR_CONSOLE_BAUD ; Setup timer const
out (IO_CTC0_C0),A ; Load timer const into CTC (Setup Baud generator)
;set up TX and RX:W
ld a,00110000b ;write into WR0: error reset, select WR0
out (IO_SIO0A_C),A
ld a,018h ;write into WR0: channel reset
out (IO_SIO0A_C),A
ld a,004h ;write into WR0: select WR4
out (IO_SIO0A_C),A
ld a,04h ;44h write into WR4: clkx1,1 stop bit, no parity
out (IO_SIO0A_C),A
ld a,005h ;write into WR0: select WR5
out (IO_SIO0A_C),A
ld a,068h ;DTR active, TX 8bit, BREAK off, TX on, RTS inactive
out (IO_SIO0A_C),A
ld a,01h ;write into WR0: select WR1
out (IO_SIO0A_C),A
ld a,00000100b ;no interrupt in CH B, special RX condition affects vect
out (IO_SIO0A_C),A
;enable SIO channel A RX
ld a,003h ;write into WR0: select WR3
out (IO_SIO0A_C),A
ld a,0C1h ;RX 8bit, auto enable off, RX on
out (IO_SIO0A_C),A
;Channel A RX active
ld hl,[MSG_START_DBG]
call debug_print_str
ret
debug_print_char:
out (IO_SIO0A_D),a
call debug_wait_out
ret
debug_print_str:
ld a, (hl)
or a
ret z
call debug_print_char
inc hl
jr debug_print_str
debug_print_newLine:
ld a,10
call debug_print_char
ld a,13
call debug_print_char
ret
debug_wait_out:
; check for TX buffer empty
sub a ;clear a, write into WR0: select RR0
inc a ;select RR1
out (IO_SIO0A_C),A
in A,(IO_SIO0A_C) ;read RRx
bit 0,A
jr z,debug_wait_out
ret
MSG_START_DBG:
db "Debug interface active!",13,10,0
debug_a_hex:
push BC
push AF
call STRCONV_BYTES_TO_HEX
ld a, b
call debug_print_char
ld a, c
call debug_print_char
pop AF
pop BC
ret

View File

@@ -0,0 +1,322 @@
; HL contains start address
; B contains length
disassemble:
call dasm_print16hex_addr ;print address (HL)
call disassemble_table_seek
xor a
or b
or c
jr z, disassemble_err ;if bc==0000h
ld a,(hl) ;load first byte
call dasm_print8hex ;print value
ld a,(hl)
cp 0xC3 ;C3 JPnn
jp z, dasm_C3
;start getting value
disassemble_err:
ld a,(hl)
call dasm_print8hex ;print value
push hl
ld hl, [dasm_UU]
call print_str
pop hl
disassemble_continue:
call print_newLine
inc hl
dec b
jp nz, disassemble
ret
;A contains char
;BC contains returned position
disassemble_table_seek:
push hl
ld c,a
disassemble_table_seek_loop:
ld a,(hl)
cp c ; if match
jr z, disassemble_table_found
or a ; if null
jp z, disassemble_table_notfound
ld b,0
ld c,4
add hl,bc
ld a,(hl)
ld c,a
add hl,bc
inc hl
jr disassemble_table_seek_loop
disassemble_table_found
ld b,H
ld c,l
pop hl
ret
disassemble_table_notfound
ld b,0
ld c,0
pop hl
ret
dasm_C3: ;JP nn (276)
inc hl
ld e, (HL)
inc hl
ld d, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_C3_str]
call print_str
ld h,d
ld l,e
call dasm_print16hex_addr
pop hl
jp disassemble_continue
dasm_C3_str:
db "JP ",0x00
dasm_JPccnn: ;JP nn (276)
rra
rra
rra
and 0x07
call dasm_printFlags
ld a, ","
call print_char
inc hl
ld e, (HL)
inc hl
ld d, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_C3_str]
call print_str
ld h,d
ld l,e
call dasm_print16hex_addr
pop hl
jp disassemble_continue
dasm_18: ;JR e
inc hl
ld e, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_18_str]
call print_str
ld a,e
call dasm_print8relhex
pop hl
jp disassemble_continue
dasm_18_str:
db "JR ",0x00
dasm_38: ;JR C,e
inc hl
ld e, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_38_str]
call print_str
ld a,e
call dasm_print8relhex
pop hl
jp disassemble_continue
dasm_38_str:
db "JR C, ",0x00
dasm_30: ;JR NC,e
inc hl
ld e, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_30_str]
call print_str
ld a,e
call dasm_print8relhex
pop hl
jp disassemble_continue
dasm_30_str:
db "JR NC, ",0x00
dasm_28: ;JR Z,e
inc hl
ld e, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_28_str]
call print_str
ld a,e
call dasm_print8relhex
pop hl
jp disassemble_continue
dasm_28_str:
db "JR Z, ",0x00
dasm_20: ;JR NZ,e
inc hl
ld e, (HL)
inc hl
;de now has jmp value
push hl
ld hl, [dasm_20_str]
call print_str
ld a,e
call dasm_print8relhex
pop hl
jp disassemble_continue
dasm_20_str:
db "JR NZ, ",0x00
dasm_E9: ;JR NZ,e
inc hl
push hl
ld hl, [dasm_20_str]
call print_str
pop hl
jp disassemble_continue
dasm_E9_str:
db "JP (HL), ",0x00
dasm_E9: ;JP (HL)
inc hl
push hl
ld hl, [dasm_E9_str]
call print_str
pop hl
jp disassemble_continue
dasm_E9_str:
db "JP (HL)",0x00
dasm_E9: ;JP (IX)
inc hl
push hl
ld hl, [dasm_E9_str]
call print_str
pop hl
jp disassemble_continue
dasm_E9_str:
db "JP (IX)",0x00
dasm_E9: ;JP (IY)
inc hl
push hl
ld hl, [dasm_E9_str]
call print_str
pop hl
jp disassemble_continue
dasm_E9_str:
db "JP (IY)",0x00
dasm_00: ;JP nn (276)
inc hl
push hl
ld hl, [dasm_00_str]
call print_str
pop hl
jp disassemble_continue
dasm_00_str:
db "NOP",0x00
dasm_FF: ;JP nn (276)
inc hl
push hl
ld hl, [dasm_FF_str]
call print_str
pop hl
jp disassemble_continue
dasm_FF_str:
db "---",0x00
dasm_print16hex_addr:
ld a,"$"
call print_char
ld a,h
call print_a_hex
ld a,l
call print_a_hex
ld a,"h"
call print_char
ld a," "
call print_char
ret
dasm_print8hex:
call print_a_hex
ld a,"h"
call print_char
ld a," "
call print_char
ret
dasm_print8relhex:
push af
and 0x80
jp nz, dasm_print8relhex_neg
ld a,"$"
call print_char
ld a,"+"
call print_char
pop af
call print_a_hex
ld a,"h"
call print_char
ret
dasm_print8relhex_neg:
ld a,"$"
call print_char
ld a,"-"
call print_char
pop af
neg
call print_a_hex
ld a,"h"
call print_char
ret
dasm_printFlags:
push hl
ld hl, [dasm_printFlags_table]
rlca
ld b,0
ld c,a
add hl,bc
call print_str
ld a, " "
call print_char
pop hl
ret
dasm_printFlags_table:
db "NZ",0
db "Z",0,0
db "NC"
db "C",0,0
db "PO",0
db "PE",0
db "P",0,0
db "M",0,0

View File

@@ -0,0 +1,16 @@
; a contains data
; bc destroied
; carry is set if odd, reset if even
calc_parity:
ld c,0 ;parity data
ld b,8 ;bit counter
calc_parity_loop:
rrca
jr nc,calc_parity_loop_2 ;if not zero then skip increment
inc c
calc_parity_loop_2:
djnz calc_parity_loop
ld a,c
rra ;carry is set to bit 0 of high-counter.
;if bit1 is set -> odd # of 1s else even # of 1s
ret